From 9829e4800f4040dc1ae84d4e03e77c91bb15583f Mon Sep 17 00:00:00 2001 From: DedunuKarunarathne <46235093+DedunuKarunarathne@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:15:55 +0530 Subject: [PATCH] Dynamically inject values to the throttle mediator Dynamically inject values to the throttle mediator. Fixes: https://github.com/wso2/product-micro-integrator/issues/3787 --- .../synapse/commons/throttle/core/ThrottleFactory.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/commons/src/main/java/org/apache/synapse/commons/throttle/core/ThrottleFactory.java b/modules/commons/src/main/java/org/apache/synapse/commons/throttle/core/ThrottleFactory.java index 6ac8f9bed8..072e19ce49 100644 --- a/modules/commons/src/main/java/org/apache/synapse/commons/throttle/core/ThrottleFactory.java +++ b/modules/commons/src/main/java/org/apache/synapse/commons/throttle/core/ThrottleFactory.java @@ -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; @@ -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. @@ -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 " + @@ -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", @@ -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 ",