Skip to content

Commit

Permalink
Dynamically inject values to the throttle mediator
Browse files Browse the repository at this point in the history
Dynamically inject values to the throttle mediator. Fixes: wso2/product-micro-integrator#3787
  • Loading branch information
DedunuKarunarathne committed Dec 2, 2024
1 parent c17a92f commit 9829e48
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 9829e48

Please sign in to comment.