diff --git a/modules/core/src/main/java/org/apache/synapse/mediators/transform/pfutils/Constants.java b/modules/core/src/main/java/org/apache/synapse/mediators/transform/pfutils/Constants.java index d9ace07b93..d359c82352 100644 --- a/modules/core/src/main/java/org/apache/synapse/mediators/transform/pfutils/Constants.java +++ b/modules/core/src/main/java/org/apache/synapse/mediators/transform/pfutils/Constants.java @@ -40,6 +40,7 @@ private Constants() { public static final String CTX_PROPERTY_INJECTING_NAME = "ctx"; public static final String AXIS2_PROPERTY_INJECTING_NAME = "axis2"; public static final String TRANSPORT_PROPERTY_INJECTING_NAME = "trp"; + public static final String VARIABLE_INJECTING_NAME = "var"; public static final String JSON_TYPE = "json"; public static final String XML_TYPE = "xml"; public static final String TEXT_TYPE = "text"; diff --git a/modules/core/src/main/java/org/apache/synapse/mediators/transform/pfutils/FreeMarkerTemplateProcessor.java b/modules/core/src/main/java/org/apache/synapse/mediators/transform/pfutils/FreeMarkerTemplateProcessor.java index cdf99473d9..ce98a442dd 100644 --- a/modules/core/src/main/java/org/apache/synapse/mediators/transform/pfutils/FreeMarkerTemplateProcessor.java +++ b/modules/core/src/main/java/org/apache/synapse/mediators/transform/pfutils/FreeMarkerTemplateProcessor.java @@ -70,6 +70,7 @@ import static org.apache.synapse.mediators.transform.pfutils.Constants.PAYLOAD_INJECTING_NAME; import static org.apache.synapse.mediators.transform.pfutils.Constants.TEXT_PAYLOAD_TYPE; import static org.apache.synapse.mediators.transform.pfutils.Constants.TRANSPORT_PROPERTY_INJECTING_NAME; +import static org.apache.synapse.mediators.transform.pfutils.Constants.VARIABLE_INJECTING_NAME; import static org.apache.synapse.mediators.transform.pfutils.Constants.XML_PAYLOAD_TYPE; import static org.apache.synapse.util.PayloadHelper.TEXTELT; import static org.apache.synapse.util.PayloadHelper.getXMLPayload; @@ -88,6 +89,7 @@ public class FreeMarkerTemplateProcessor extends TemplateProcessor { private boolean usingPropertyAxis2; private boolean usingPropertyTransport; private boolean usingArgs; + private boolean usingVariables; private static final Log log = LogFactory.getLog(FreeMarkerTemplateProcessor.class); private boolean templateLoaded = false; @@ -218,6 +220,7 @@ private void findRequiredInjections(String templateString) { usingPropertyCtx = templateString.contains(CTX_PROPERTY_INJECTING_NAME); usingPropertyAxis2 = templateString.contains(AXIS2_PROPERTY_INJECTING_NAME); usingPropertyTransport = templateString.contains(TRANSPORT_PROPERTY_INJECTING_NAME); + usingVariables = templateString.contains(VARIABLE_INJECTING_NAME); } /** @@ -400,6 +403,7 @@ private void injectProperties(MessageContext synCtx, Map data) { injectCtxProperties(synCtx, data); injectAxis2Properties(synCtx, data); injectTransportProperties(synCtx, data); + injectVariables(synCtx, data); } private void injectCtxProperties(MessageContext synCtx, Map data) { @@ -420,6 +424,21 @@ private void injectCtxProperties(MessageContext synCtx, Map data } } + private void injectVariables(MessageContext synCtx, Map data) { + + if (usingVariables) { + Map variables = new HashMap<>(); + for (Object o : synCtx.getVariableKeySet()) { + String varName = (String) o; + Object variable = synCtx.getVariable(varName); + if (variable != null) { + variables.put(varName, variable.toString()); + } + } + data.put(VARIABLE_INJECTING_NAME, variables); + } + } + private void injectAxis2Properties(MessageContext synCtx, Map data) { if (usingPropertyAxis2) {