Skip to content

Commit

Permalink
Merge pull request #2245 from DedunuKarunarathne/master
Browse files Browse the repository at this point in the history
Dynamically inject values to the throttle mediator
  • Loading branch information
DedunuKarunarathne authored Dec 3, 2024
2 parents a460488 + 9829e48 commit ed36e06
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.neethi.builders.xml.XmlPrimtiveAssertion;
import org.apache.synapse.commons.resolvers.ResolverFactory;
import org.apache.synapse.commons.throttle.core.factory.CallerConfigurationFactory;
import org.apache.synapse.commons.throttle.core.factory.ThrottleConfigurationFactory;
import org.apache.synapse.commons.throttle.core.factory.ThrottleContextFactory;
Expand Down Expand Up @@ -458,6 +459,7 @@ private static void fillControlConfiguration(Policy policy,
"Name of the policy cannot be null");
}
if (!value.equals("")) {
String resolvedValue = ResolverFactory.getInstance().getResolver(value.trim()).resolve();

if (name.equals(
ThrottleConstants.
Expand All @@ -466,7 +468,7 @@ private static void fillControlConfiguration(Policy policy,
isFoundMaxCount = true;
try {
callerConfiguration.setMaximumRequestPerUnitTime(
Integer.parseInt(value.trim()));
Integer.parseInt(resolvedValue));
} catch (NumberFormatException ignored) {
log.error("Error occurred - " +
"Invalid number for maximum " +
Expand All @@ -485,7 +487,7 @@ private static void fillControlConfiguration(Policy policy,
long timeInMilliSec = 0;
try {
timeInMilliSec =
Long.parseLong(value.trim());
Long.parseLong(resolvedValue);
} catch (NumberFormatException ignored) {
log.error("Error occurred " +
"- Invalid number for unit time",
Expand All @@ -504,7 +506,7 @@ private static void fillControlConfiguration(Policy policy,
PROHIBIT_TIME_PERIOD_PARAMETER_NAME)) {
try {
callerConfiguration.setProhibitTimePeriod(
Long.parseLong(value.trim()));
Long.parseLong(resolvedValue));
} catch (NumberFormatException ignored) {
log.error("Error occurred - Invalid" +
" number for prohibit time ",
Expand Down

0 comments on commit ed36e06

Please sign in to comment.