You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by su...@apache.org on 2011/03/10 09:04:42 UTC
svn commit: r1080145 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse: ./
config/xml/ mediators/ mediators/eip/ mediators/eip/aggregator/
mediators/eip/splitter/ mediators/template/ util/xpath/
Author: supun
Date: Thu Mar 10 08:04:41 2011
New Revision: 1080145
URL: http://svn.apache.org/viewvc?rev=1080145&view=rev
Log:
commiting the patch SYNAPSE-738, many thanks to Udayanga for the contribution
Added:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorSerializer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorSerializer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateContext.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateMediator.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueSerializer.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/Value.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathConstants.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathVariableContext.java
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java Thu Mar 10 08:04:41 2011
@@ -104,6 +104,7 @@ public final class SynapseConstants {
/** ServerManager MBean category and id */
public static final String SERVER_MANAGER_MBEAN = "ServerManager";
public static final String RECEIVING_SEQUENCE = "RECEIVING_SEQUENCE";
+ public static final String SYNAPSE__FUNCTION__STACK = "_SYNAPSE_FUNCTION_STACK";
/** Parameter names in the axis2.xml that can be used to configure the synapse */
public static final class Axis2Param {
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java?rev=1080145&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorFactory.java Thu Mar 10 08:04:41 2011
@@ -0,0 +1,82 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.Value;
+import org.apache.synapse.mediators.template.InvokeMediator;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.Properties;
+
+/**
+ * Builds Invoke mediator from a configuration as
+ * <invoke target="">
+ * <parameter name="p1" value="{expr}" />
+ * <parameter name="p1" value="{{expr}}" />
+ * <parameter name="p1" value="v2" />
+ * ...
+ * ..
+ * </invoke>
+ */
+public class InvokeMediatorFactory extends AbstractMediatorFactory {
+
+ private static final QName INVOKE_Q = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "invoke");
+
+ InvokeMediator invoker;
+
+ @Override
+ protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
+ invoker = new InvokeMediator();
+ OMAttribute targetTemplateAttr = elem.getAttribute(ATT_TARGET);
+ if (targetTemplateAttr != null) {
+ invoker.setTargetTemplate(targetTemplateAttr.getAttributeValue());
+ buildParameters(elem);
+ } else {
+ String msg = "EIP Invoke mediator should have a target template specified.";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ return invoker;
+ }
+
+ private void buildParameters(OMElement elem) {
+ Iterator subElements = elem.getChildElements();
+ while (subElements.hasNext()) {
+ OMElement child = (OMElement) subElements.next();
+ if (child.getQName().equals(TemplateMediatorFactory.PARAMETER_Q)) {
+ OMAttribute paramNameAttr = child.getAttribute(ATT_NAME);
+ Value paramValue = new ValueFactory().createValue("value", child);
+ if (paramNameAttr != null) {
+ //set parameter value
+ invoker.addExpressionForParamName(paramNameAttr.getAttributeValue(), paramValue);
+ }
+ }
+ }
+
+ }
+
+
+ public QName getTagQName() {
+ return INVOKE_Q;
+ }
+}
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorSerializer.java?rev=1080145&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorSerializer.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/InvokeMediatorSerializer.java Thu Mar 10 08:04:41 2011
@@ -0,0 +1,81 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.Value;
+import org.apache.synapse.mediators.template.InvokeMediator;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Serialize a Invoke mediator to a configuration given below
+ * <invoke target="">
+ * <parameter name="p1" value="{expr}" />
+ * <parameter name="p1" value="{{expr}}" />
+ * <parameter name="p1" value="v2" />
+ * ...
+ * ..
+ * </invoke>
+ */
+public class InvokeMediatorSerializer extends AbstractMediatorSerializer {
+ public static final String INVOKE_N = "invoke";
+
+ @Override
+ protected OMElement serializeSpecificMediator(Mediator m) {
+ if (!(m instanceof InvokeMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+ InvokeMediator mediator = (InvokeMediator) m;
+ OMElement invokeElem = fac.createOMElement(INVOKE_N, synNS);
+
+ if (mediator.getTargetTemplate() != null) {
+ invokeElem.addAttribute(fac.createOMAttribute(
+ "target", nullNS, mediator.getTargetTemplate()));
+
+ serializeParams(invokeElem, mediator);
+ saveTracingState(invokeElem, mediator);
+ }
+
+ return invokeElem;
+ }
+
+ private void serializeParams(OMElement invokeElem, InvokeMediator mediator) {
+ Map<String, Value> paramsMap = mediator.getpName2ExpressionMap();
+ Iterator<String> paramIterator = paramsMap.keySet().iterator();
+ while (paramIterator.hasNext()) {
+ String paramName = paramIterator.next();
+ if (!"".equals(paramName)) {
+ OMElement paramEl = fac.createOMElement(TemplateMediatorFactory.PARAMETER_Q.getLocalPart(),
+ synNS);
+ paramEl.addAttribute(fac.createOMAttribute("name", nullNS, paramName));
+ //serialize value attribute
+ Value value = paramsMap.get(paramName);
+ new ValueSerializer().serializeValue(value, "value", paramEl);
+ invokeElem.addChild(paramEl);
+ }
+ }
+
+ }
+
+ public String getMediatorClassName() {
+ return InvokeMediator.class.getName();
+ }
+}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java Thu Mar 10 08:04:41 2011
@@ -38,7 +38,7 @@ import java.util.Properties;
/**
*
- *
+ *
* This class is based on J2SE Service Provider model
* http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
*/
@@ -50,7 +50,7 @@ public class MediatorFactoryFinder imple
private static final Class[] mediatorFactories = {
SequenceMediatorFactory.class,
LogMediatorFactory.class,
- SendMediatorFactory.class,
+ SendMediatorFactory.class,
FilterMediatorFactory.class,
SynapseMediatorFactory.class,
DropMediatorFactory.class,
@@ -60,7 +60,7 @@ public class MediatorFactoryFinder imple
SwitchMediatorFactory.class,
InMediatorFactory.class,
OutMediatorFactory.class,
- RMSequenceMediatorFactory.class,
+ RMSequenceMediatorFactory.class,
ClassMediatorFactory.class,
ValidateMediatorFactory.class,
XSLTMediatorFactory.class,
@@ -80,7 +80,9 @@ public class MediatorFactoryFinder imple
SamplingThrottleMediatorFactory.class,
URLRewriteMediatorFactory.class,
EnrichMediatorFactory.class,
- MessageStoreMediatorFactory.class
+ MessageStoreMediatorFactory.class,
+ TemplateMediatorFactory.class,
+ InvokeMediatorFactory.class
};
private final static MediatorFactoryFinder instance = new MediatorFactoryFinder();
@@ -148,7 +150,7 @@ public class MediatorFactoryFinder imple
* This method returns a Processor given an OMElement. This will be used
* recursively by the elements which contain processor elements themselves
* (e.g. rules)
- *
+ *
* @param element XML representation of a mediator
* @param properties bag of properties to pass in any information to the factory
* @return Processor
@@ -197,7 +199,7 @@ public class MediatorFactoryFinder imple
throw new SynapseException(msg, e);
}
}
-
+
/**
* This method exposes all the MediatorFactories and its Extensions
* @return factoryMap
@@ -208,7 +210,7 @@ public class MediatorFactoryFinder imple
/**
* Allow the mediator factory finder to act as an XMLToObjectMapper for Mediators
- * (i.e. Sequence Mediator) loaded dynamically from a Registry
+ * (i.e. Sequence Mediator) loaded dynamically from a Registry
* @param om node from which the object is expected
* @return Object buit from the om node
*/
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java Thu Mar 10 08:04:41 2011
@@ -65,6 +65,8 @@ public class MediatorSerializerFinder {
ConditionalRouterMediatorSerializer.class,
SamplingThrottleMediatorSerializer.class,
EnrichMediatorSerializer.class,
+ TemplateMediatorSerializer.class,
+ InvokeMediatorSerializer.class,
MessageStoreMediatorSerializer.class
};
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java Thu Mar 10 08:04:41 2011
@@ -26,6 +26,7 @@ import org.apache.commons.logging.LogFac
import org.apache.synapse.Mediator;
import org.apache.synapse.Startup;
import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.mediators.template.TemplateMediator;
import org.apache.synapse.SynapseException;
import org.apache.synapse.message.store.MessageStore;
import org.apache.synapse.commons.executors.PriorityExecutor;
@@ -72,6 +73,7 @@ public class MultiXMLConfigurationBuilde
public static final String PROXY_SERVICES_DIR = "proxy-services";
public static final String SEQUENCES_DIR = "sequences";
+ public static final String TEMPLATES_DIR = "templates";
public static final String ENDPOINTS_DIR = "endpoints";
public static final String LOCAL_ENTRY_DIR = "local-entries";
public static final String TASKS_DIR = "tasks";
@@ -120,6 +122,7 @@ public class MultiXMLConfigurationBuilde
createLocalEntries(synapseConfig, root, properties);
createEndpoints(synapseConfig, root, properties);
createSequences(synapseConfig, root, properties);
+ createTemplates(synapseConfig, root, properties);
createProxyServices(synapseConfig, root, properties);
createTasks(synapseConfig, root, properties);
createEventSources(synapseConfig, root, properties);
@@ -272,6 +275,31 @@ public class MultiXMLConfigurationBuilde
}
}
+ private static void createTemplates(SynapseConfiguration synapseConfig, String rootDirPath,
+ Properties properties) throws XMLStreamException {
+
+ File sequencesDir = new File(rootDirPath, TEMPLATES_DIR);
+ if (sequencesDir.exists()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Loading sequences from : " + sequencesDir.getPath());
+ }
+ File[] sequences = sequencesDir.listFiles(filter);
+ for (File file : sequences) {
+ try {
+ OMElement document = parseFile(file);
+ Mediator seq = SynapseXMLConfigurationFactory.defineTemplate(
+ synapseConfig, document, properties);
+ if (seq != null && seq instanceof TemplateMediator) {
+ TemplateMediator templateSeq = (TemplateMediator) seq;
+ templateSeq.setFileName(file.getName());
+ synapseConfig.getArtifactDeploymentStore().addArtifact(
+ file.getAbsolutePath(), templateSeq.getName());
+ }
+ } catch (FileNotFoundException ignored) {}
+ }
+ }
+ }
+
private static void createEndpoints(SynapseConfiguration synapseConfig, String rootDirPath,
Properties properties) throws XMLStreamException {
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationSerializer.java Thu Mar 10 08:04:41 2011
@@ -24,6 +24,7 @@ import org.apache.synapse.config.Synapse
import org.apache.synapse.config.Entry;
import org.apache.synapse.config.xml.eventing.EventSourceSerializer;
import org.apache.synapse.config.xml.endpoints.EndpointSerializer;
+import org.apache.synapse.mediators.template.TemplateMediator;
import org.apache.synapse.registry.Registry;
import org.apache.synapse.core.axis2.ProxyService;
import org.apache.synapse.eventing.SynapseEventSource;
@@ -171,7 +172,13 @@ public class MultiXMLConfigurationSerial
}
for (Object o : localEntries) {
- if (o instanceof SequenceMediator) {
+ if (o instanceof TemplateMediator) {
+ TemplateMediator template = (TemplateMediator) o;
+ if (template.getFileName() == null) {
+ MediatorSerializerFinder.getInstance().
+ getSerializer(template).serializeMediator(definitions, template);
+ }
+ } else if (o instanceof SequenceMediator) {
SequenceMediator seq = (SequenceMediator) o;
if (seq.getFileName() == null) {
MediatorSerializerFinder.getInstance().
@@ -308,6 +315,26 @@ public class MultiXMLConfigurationSerial
return seqElem;
}
+ public OMElement serializeTemplate(TemplateMediator template, SynapseConfiguration synapseConfig,
+ OMElement parent) throws Exception {
+
+ File seqDir = createDirectory(currentDirectory, MultiXMLConfigurationBuilder.TEMPLATES_DIR);
+
+ OMElement seqElem = MediatorSerializerFinder.getInstance().getSerializer(template).
+ serializeMediator(null, template);
+ String fileName = template.getFileName();
+ if (fileName != null) {
+ handleDeployment(seqDir, fileName, template.getName(),
+ synapseConfig.getArtifactDeploymentStore());
+ File seqFile = new File(seqDir, fileName);
+ writeToFile(seqElem, seqFile);
+ } else if (parent != null) {
+ parent.addChild(seqElem);
+ }
+
+ return seqElem;
+ }
+
public OMElement serializeEndpoint(Endpoint epr, SynapseConfiguration synapseConfig,
OMElement parent) throws Exception {
@@ -329,7 +356,9 @@ public class MultiXMLConfigurationSerial
public OMElement serializeLocalEntry(Object o, SynapseConfiguration synapseConfig,
OMElement parent) throws Exception {
- if (o instanceof SequenceMediator) {
+ if (o instanceof TemplateMediator) {
+ return serializeTemplate((TemplateMediator) o, synapseConfig, parent);
+ } else if (o instanceof SequenceMediator) {
return serializeSequence((SequenceMediator) o, synapseConfig, parent);
} else if (o instanceof Endpoint) {
return serializeEndpoint((Endpoint) o, synapseConfig, parent);
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java Thu Mar 10 08:04:41 2011
@@ -77,6 +77,8 @@ public class SynapseXMLConfigurationFact
} else {
defineSequence(config, elt, properties);
}
+ } else if (XMLConfigConstants.TEMPLATE_ELT.equals(elt.getQName())) {
+ defineTemplate(config, elt, properties);
} else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
defineEndpoint(config, elt, properties);
} else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
@@ -213,6 +215,35 @@ public class SynapseXMLConfigurationFact
return null;
}
+ public static Mediator defineTemplate(SynapseConfiguration config, OMElement ele,
+ Properties properties) {
+
+ boolean failSafeSequenceEnabled = isFailSafeEnabled(
+ SynapseConstants.FAIL_SAFE_MODE_SEQUENCES);
+
+ Mediator mediator = null;
+ String name = ele.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
+ if (name != null) {
+ try {
+ mediator = MediatorFactoryFinder.getInstance().getMediator(ele, properties);
+ if (mediator != null) {
+ config.addSequence(name, mediator);
+ }
+ } catch (Exception e) {
+ if (failSafeSequenceEnabled) {
+ log.warn("Template configuration : " + name +" cannot be built.", e);
+ log.warn("Continue in fail-safe mode.");
+ } else {
+ handleException("Template configuration : " + name +" cannot be built.");
+ }
+ }
+ return mediator;
+ } else {
+ handleException("Invalid template definition without a name");
+ }
+ return null;
+ }
+
public static Endpoint defineEndpoint(SynapseConfiguration config, OMElement ele,
Properties properties) {
boolean failSafeEpEnabled = isFailSafeEnabled(SynapseConstants.FAIL_SAFE_MODE_EP);
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java Thu Mar 10 08:04:41 2011
@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFac
import org.apache.synapse.Startup;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.template.TemplateMediator;
import org.apache.synapse.message.processors.MessageProcessor;
import org.apache.synapse.message.store.MessageStore;
import org.apache.synapse.commons.executors.PriorityExecutor;
@@ -95,6 +96,7 @@ public class SynapseXMLConfigurationSeri
Map<String, Entry> entries = new HashMap<String, Entry>();
Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
Map<String, SequenceMediator> sequences = new HashMap<String, SequenceMediator>();
+ Map<String, TemplateMediator> templates = new HashMap<String, TemplateMediator>();
itr = synCfg.getLocalRegistry().keySet().iterator();
while (itr.hasNext()) {
@@ -103,7 +105,9 @@ public class SynapseXMLConfigurationSeri
continue;
}
Object o = synCfg.getLocalRegistry().get(key);
- if (o instanceof SequenceMediator) {
+ if (o instanceof TemplateMediator){
+ templates.put(key.toString(), (TemplateMediator) o);
+ } else if (o instanceof SequenceMediator) {
sequences.put(key.toString(), (SequenceMediator) o);
} else if (o instanceof Endpoint) {
endpoints.put(key.toString(), (Endpoint) o);
@@ -124,6 +128,9 @@ public class SynapseXMLConfigurationSeri
// process sequences
serializeSequences(definitions, sequences);
+ // process templates
+ serializeTemplates(definitions, templates);
+
// handle startups
serializeStartups(definitions, synCfg.getStartups());
@@ -168,6 +175,15 @@ public class SynapseXMLConfigurationSeri
}
}
+ private static void serializeTemplates(OMElement definitions,
+ Map<String, TemplateMediator> eipSequences) {
+ for (TemplateMediator template : eipSequences.values()) {
+ MediatorSerializerFinder.getInstance().getSerializer(template)
+ .serializeMediator(definitions, template);
+
+ }
+ }
+
private static void serializeExecutors(OMElement definitions,
Map<String, PriorityExecutor> executors) {
for (PriorityExecutor exec : executors.values()) {
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorFactory.java?rev=1080145&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorFactory.java Thu Mar 10 08:04:41 2011
@@ -0,0 +1,91 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.template.TemplateMediator;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+/**
+ * Factory class for Template configuration as follows
+ * <template name="simple_func">
+ <parameter name="p1"/>
+ <parameter name="p2"/>*
+ <mediator/>+
+ </template>
+ */
+public class TemplateMediatorFactory extends AbstractListMediatorFactory {
+ private static final QName TEMPLATE_Q
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "template");
+ private TemplateMediator templateTemplateMediator;
+ private OMElement templateElem;
+ /**
+ * Element QName Definitions
+ */
+ public static final QName PARAMETER_Q = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "parameter");
+
+
+ protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
+ templateTemplateMediator = new TemplateMediator();
+ templateElem = elem;
+ OMAttribute nameAttr = templateElem.getAttribute(ATT_NAME);
+ OMAttribute errorHandlerAttr = templateElem.getAttribute(ATT_ONERROR);
+ if (nameAttr != null) {
+ templateTemplateMediator.setName(nameAttr.getAttributeValue());
+ if (errorHandlerAttr != null) {
+ templateTemplateMediator.setErrorHandler(errorHandlerAttr.getAttributeValue());
+ }
+ processAuditStatus(templateTemplateMediator, templateElem);
+ initParameters();
+ addChildren(templateElem, templateTemplateMediator, properties);
+ } else {
+ String msg = "A EIP template should be a named mediator .";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ return templateTemplateMediator;
+ }
+
+ private void initParameters() {
+ Iterator subElements = templateElem.getChildElements();
+ Collection<String> paramNames = new ArrayList<String>();
+ while (subElements.hasNext()) {
+ OMElement child = (OMElement) subElements.next();
+ if (child.getQName().equals(PARAMETER_Q)) {
+ OMAttribute paramNameAttr = child.getAttribute(ATT_NAME);
+ if (paramNameAttr != null) {
+ paramNames.add(paramNameAttr.getAttributeValue());
+ }
+ child.detach();
+ }
+ }
+ templateTemplateMediator.setParameters(paramNames);
+ }
+
+ public QName getTagQName() {
+ return TEMPLATE_Q;
+ }
+
+}
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorSerializer.java?rev=1080145&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorSerializer.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TemplateMediatorSerializer.java Thu Mar 10 08:04:41 2011
@@ -0,0 +1,77 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.template.TemplateMediator;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * Serializer class for Template to serialize into a configuration as follows
+ * <template name="simple_func">
+ <parameter name="p1"/>
+ <parameter name="p2"/>*
+ <mediator/>+
+ </template>
+ */
+public class TemplateMediatorSerializer extends AbstractListMediatorSerializer {
+ @Override
+ protected OMElement serializeSpecificMediator(Mediator m) {
+ if (!(m instanceof TemplateMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ TemplateMediator mediator = (TemplateMediator) m;
+ OMElement templateElem = fac.createOMElement("template", synNS);
+
+ if (mediator.getName() != null) {
+ templateElem.addAttribute(fac.createOMAttribute(
+ "name", nullNS, mediator.getName()));
+
+ if (mediator.getErrorHandler() != null) {
+ templateElem.addAttribute(fac.createOMAttribute(
+ "onError", nullNS, mediator.getErrorHandler()));
+ }
+ serializeParams(templateElem,mediator);
+ saveTracingState(templateElem, mediator);
+ serializeChildren(templateElem, mediator.getList());
+ }
+
+ return templateElem;
+ }
+
+ private void serializeParams(OMElement templateElem, TemplateMediator mediator) {
+ Collection<String> params = mediator.getParameters();
+ Iterator<String> paramIterator = params.iterator();
+ while (paramIterator.hasNext()){
+ String paramName = paramIterator.next();
+ if(!"".equals(paramName)){
+ OMElement paramEl = fac.createOMElement("parameter", synNS);
+ paramEl.addAttribute(fac.createOMAttribute("name",nullNS,paramName));
+ templateElem.addChild(paramEl);
+ }
+ }
+ }
+
+ public String getMediatorClassName() {
+ return TemplateMediator.class.getName();
+ }
+}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueFactory.java Thu Mar 10 08:04:41 2011
@@ -21,9 +21,11 @@ package org.apache.synapse.config.xml;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.SynapseConfigUtils;
import org.apache.synapse.mediators.Value;
import org.apache.synapse.util.xpath.SynapseXPath;
import org.jaxen.JaxenException;
@@ -53,10 +55,15 @@ public class ValueFactory {
if (attKey != null) {
String attributeValue = attKey.getAttributeValue();
- if (isDynamicKey(attributeValue)) {
+ boolean hasEscape = isEscapedExpression(attributeValue);
+ if (!hasEscape && isDynamicKey(attributeValue)) {
/** dynamic key */
SynapseXPath synXpath = createSynXpath(elem, attributeValue);
key = new Value(synXpath);
+ } else if (hasEscape) {
+ /** escaped expr */
+ key = new Value(getEscapedExpression(attributeValue));
+ key.setNamespaces(elem);
} else {
/** static key */
key = new Value(attributeValue);
@@ -92,6 +99,33 @@ public class ValueFactory {
}
/**
+ * we'll focus on the trivial escape ie:- ones that have escape characters at start and end
+ */
+ private boolean isEscapedExpression(String escapeExpr){
+ final char startEscapeChar = '{';
+ final char endEscapeChar = '}';
+ String expr = escapeExpr.trim();
+ if(expr.length() <= 3){
+ return false;
+ }
+ //check if this is a escape expression ie:- {{//m0:getQuote}}
+ char firstChar = expr.charAt(0);
+ char nextTofirstChar = expr.charAt(1);
+ char lastChar = expr.charAt(expr.length() - 1);
+ char prevTolastChar = expr.charAt(expr.length() - 2);
+ //if starting and ending chars have braces ;
+ if (startEscapeChar == firstChar && endEscapeChar == lastChar) {
+ return firstChar == nextTofirstChar && lastChar == prevTolastChar;
+ }
+ return false;
+ }
+
+ private String getEscapedExpression(String originalExpr){
+ return originalExpr.trim().substring(1, originalExpr.length() - 1);
+ }
+
+
+ /**
* Create synapse xpath expression
* {} type user input is used to create real xpath expression
*
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueSerializer.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ValueSerializer.java Thu Mar 10 08:04:41 2011
@@ -46,9 +46,15 @@ public class ValueSerializer {
//static key
elem.addAttribute(fac.createOMAttribute(name, nullNS, key.getKeyValue()));
} else {
+ String startChar = "{" , endChar = "}";
+ //if this is an expr type key we add an additional opening and closing brace
+ if(key.hasExprTypeKey()){
+ startChar = startChar + "{";
+ endChar = endChar + "}";
+ }
//dynamic key
- SynapseXPathSerializer.serializeXPath(key.getExpression(), "{" +
- key.getExpression().toString() + "}", elem, name);
+ SynapseXPathSerializer.serializeXPath(key.getExpression(), startChar +
+ key.getExpression().toString() + endChar, elem, name);
}
}
return elem;
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java Thu Mar 10 08:04:41 2011
@@ -37,6 +37,8 @@ public class XMLConfigConstants {
//-- PropertyMediator --
/** The scope name for synapse message context properties */
public static final String SCOPE_DEFAULT = "default";
+ /** The scope name for synapse function template properties */
+ public static final String SCOPE_FUNC = "func";
/** The scope name for axis2 message context properties */
public static final String SCOPE_AXIS2 = "axis2";
/** The scope name for axis2 message context client options properties */
@@ -63,6 +65,7 @@ public class XMLConfigConstants {
public static final QName DEFINITIONS_ELT = new QName(SYNAPSE_NAMESPACE, "definitions");
public static final QName DESCRIPTION_ELT = new QName(SYNAPSE_NAMESPACE, "description");
public static final QName SEQUENCE_ELT = new QName(SYNAPSE_NAMESPACE, "sequence");
+ public static final QName TEMPLATE_ELT = new QName(SYNAPSE_NAMESPACE, "template");
public static final QName ENDPOINT_ELT = new QName(SYNAPSE_NAMESPACE, "endpoint");
public static final QName ENTRY_ELT = new QName(SYNAPSE_NAMESPACE, "localEntry");
public static final QName REGISTRY_ELT = new QName(SYNAPSE_NAMESPACE, "registry");
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java Thu Mar 10 08:04:41 2011
@@ -30,6 +30,7 @@ import org.apache.synapse.SynapseConstan
import org.apache.synapse.config.Entry;
import org.apache.synapse.config.xml.XMLConfigConstants;
import org.apache.synapse.core.axis2.Axis2MessageContext;
+import org.apache.synapse.mediators.template.TemplateContext;
import org.apache.synapse.registry.Registry;
import org.jaxen.Context;
import org.jaxen.Function;
@@ -42,6 +43,7 @@ import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Stack;
/**
* Implements the XPath extension function synapse:get-property(scope,prop-name)
@@ -104,7 +106,8 @@ public class GetPropertyFunction impleme
if (!XMLConfigConstants.SCOPE_AXIS2.equals(argOne) &&
!XMLConfigConstants.SCOPE_DEFAULT.equals(argOne) &&
!XMLConfigConstants.SCOPE_TRANSPORT.equals(argOne) &&
- !XMLConfigConstants.SCOPE_REGISTRY.equals(argOne)) {
+ !XMLConfigConstants.SCOPE_REGISTRY.equals(argOne) &&
+ !XMLConfigConstants.SCOPE_FUNC.equals(argOne)) {
return evaluate(XMLConfigConstants.SCOPE_DEFAULT, args.get(0),
args.get(1), context.getNavigator());
} else {
@@ -268,6 +271,12 @@ public class GetPropertyFunction impleme
= ((Axis2MessageContext) synCtx).getAxis2MessageContext();
return axis2MessageContext.getProperty(key);
+ } else if (XMLConfigConstants.SCOPE_FUNC.equals(scope)) {
+ Stack<TemplateContext> functionStack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
+ TemplateContext topCtxt = functionStack.peek();
+ if (topCtxt!=null) {
+ return topCtxt.getParameterValue(key);
+ }
} else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)
&& synCtx instanceof Axis2MessageContext) {
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/Value.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/Value.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/Value.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/Value.java Thu Mar 10 08:04:41 2011
@@ -19,11 +19,18 @@
package org.apache.synapse.mediators;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseException;
import org.apache.synapse.util.xpath.SynapseXPath;
+import org.jaxen.JaxenException;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
/**
* Represents a Value
@@ -48,6 +55,7 @@ public class Value {
*/
private SynapseXPath expression = null;
+ private List<OMNamespace> namespaceList = new ArrayList<OMNamespace>();
/**
* Create a key instance using a static key
*
@@ -81,6 +89,18 @@ public class Value {
* @return SynapseXpath
*/
public SynapseXPath getExpression() {
+ if(expression == null && keyValue != null && hasExprTypeKey()){
+ try {
+ expression = new SynapseXPath (keyValue.substring(1, keyValue.length()-1));
+ for (OMNamespace aNamespaceList : namespaceList) {
+ expression.addNamespace(aNamespaceList);
+ }
+ } catch (JaxenException e) {
+ expression = null;
+ handleException("Can not evaluate escaped expression..");
+
+ }
+ }
return expression;
}
@@ -125,6 +145,23 @@ public class Value {
throw new SynapseException(msg);
}
+
+ /**
+ * checks whether key returned by #getKeyValue() is a string of an expression type.
+ * @return if true if this is an expression
+ */
+ public boolean hasExprTypeKey() {
+ return keyValue != null && keyValue.startsWith("{") && keyValue.endsWith("}");
+ }
+
+ public void setNamespaces(OMElement elem){
+ Iterator namespaces = elem.getAllDeclaredNamespaces();
+ while (namespaces.hasNext()){
+ OMNamespace ns = (OMNamespace) namespaces.next();
+ namespaceList.add(ns);
+ }
+ }
+
@Override
public String toString() {
return "Value {" +
@@ -133,6 +170,7 @@ public class Value {
(expression != null ? ", expression =" + expression : "") +
'}';
}
+
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java Thu Mar 10 08:04:41 2011
@@ -24,6 +24,7 @@ import org.apache.axiom.om.OMNode;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.MessageContext;
import org.apache.synapse.util.xpath.SynapseXPath;
import org.jaxen.JaxenException;
@@ -48,8 +49,21 @@ public class EIPUtils {
*/
public static List getMatchingElements(SOAPEnvelope envelope, SynapseXPath expression)
throws JaxenException {
+ return getMatchingElements(envelope,null,expression);
+ }
- Object o = expression.evaluate(envelope);
+ /**
+ * Return the set of elements specified by the XPath over the given envelope
+ *
+ * @param envelope SOAPEnvelope from which the elements will be extracted
+ * @param expression SynapseXPath expression describing the elements to be extracted
+ * @return List OMElements in the envelope matching the expression
+ * @throws JaxenException if the XPath expression evaluation fails
+ */
+ public static List getMatchingElements(SOAPEnvelope envelope,MessageContext synCtxt, SynapseXPath expression)
+ throws JaxenException {
+
+ Object o = expression.evaluate(envelope, synCtxt);
if (o instanceof OMNode) {
List list = new ArrayList();
list.add(o);
@@ -69,11 +83,12 @@ public class EIPUtils {
* @return List detached OMElements in the envelope matching the expression
* @throws JaxenException if the XPath expression evaluation fails
*/
- public static List<OMNode> getDetachedMatchingElements(SOAPEnvelope envelope, SynapseXPath expression)
+ public static List<OMNode> getDetachedMatchingElements(SOAPEnvelope envelope, MessageContext synCtxt,
+ SynapseXPath expression)
throws JaxenException {
List<OMNode> elementList = new ArrayList<OMNode>();
- Object o = expression.evaluate(envelope);
+ Object o = expression.evaluate(envelope, synCtxt);
if (o instanceof OMNode) {
elementList.add(((OMNode) o).detach());
} else if (o instanceof List) {
@@ -95,11 +110,11 @@ public class EIPUtils {
* @param expression SynapseXPath describing the enriching element
* @throws JaxenException on failing of processing the xpath
*/
- public static void enrichEnvelope(SOAPEnvelope envelope, SOAPEnvelope enricher,
+ public static void enrichEnvelope(SOAPEnvelope envelope, SOAPEnvelope enricher, MessageContext synCtxt,
SynapseXPath expression) throws JaxenException {
OMElement enrichingElement;
- List elementList = getMatchingElements(envelope, expression);
+ List elementList = getMatchingElements(envelope, synCtxt, expression);
if (elementList != null && !elementList.isEmpty()) {
@@ -114,7 +129,7 @@ public class EIPUtils {
enrichingElement = envelope.getBody();
}
- List list = getMatchingElements(enricher, expression);
+ List list = getMatchingElements(enricher, synCtxt, expression);
if (list != null) {
Iterator itr = list.iterator();
while (itr.hasNext()) {
@@ -125,5 +140,19 @@ public class EIPUtils {
}
}
}
- }
+ }
+
+ /**
+ * Util functions related to EIP Templates
+ */
+ public static String getTemplatePropertyMapping(String templateName, String parameter) {
+ return templateName + ":" + parameter;
+ }
+
+ public static void createSynapseEIPTemplateProperty(MessageContext synCtxt, String templateName,
+ String paramName, Object value) {
+ String targetSynapsePropName = getTemplatePropertyMapping(templateName,paramName);
+ synCtxt.setProperty(targetSynapsePropName,value);
+ }
+
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/aggregator/AggregateMediator.java Thu Mar 10 08:04:41 2011
@@ -365,7 +365,7 @@ public class AggregateMediator extends A
}
EIPUtils.enrichEnvelope(
- newCtx.getEnvelope(), synCtx.getEnvelope(), aggregationExpression);
+ newCtx.getEnvelope(), synCtx.getEnvelope(), synCtx, aggregationExpression);
if (log.isDebugEnabled()) {
log.debug("Merged result : " + newCtx.getEnvelope());
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java Thu Mar 10 08:04:41 2011
@@ -99,7 +99,7 @@ public class IterateMediator extends Abs
// get the iteration elements and iterate through the list,
// this call will also detach all the iteration elements
- List splitElements = EIPUtils.getDetachedMatchingElements(envelope, expression);
+ List splitElements = EIPUtils.getDetachedMatchingElements(envelope, synCtx, expression);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Splitting with XPath : " + expression + " resulted in " +
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java?rev=1080145&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/InvokeMediator.java Thu Mar 10 08:04:41 2011
@@ -0,0 +1,106 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.synapse.mediators.template;
+
+import org.apache.synapse.Mediator;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseLog;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.Value;
+import org.apache.synapse.mediators.eip.EIPUtils;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * This class handles invocation of a synapse function template.
+ * <invoke target="">
+ * <parameter name="p1" value="{expr} | {{expr}} | value" />*
+ * ..
+ * </invoke>
+ */
+public class InvokeMediator extends AbstractMediator {
+ /**
+ * refers to the target template this is going to invoke
+ * this is a read only attribute of the mediator
+ */
+ private String targetTemplate;
+
+ /**
+ * maps each parameter name to a Expression/Value
+ * this is a read only attribute of the mediator
+ */
+ private Map<String, Value> pName2ExpressionMap;
+
+ public InvokeMediator() {
+ pName2ExpressionMap = new HashMap<String, Value>();
+ }
+
+ public boolean mediate(MessageContext synCtx) {
+ SynapseLog synLog = getLog(synCtx);
+
+ if (synLog.isTraceOrDebugEnabled()) {
+ synLog.traceOrDebug("Invoking Target EIP Sequence " + targetTemplate + " paramNames : " +
+ pName2ExpressionMap.keySet());
+ if (synLog.isTraceTraceEnabled()) {
+ synLog.traceTrace("Message : " + synCtx.getEnvelope());
+ }
+ }
+ populateParameters(synCtx);
+ //get the target function template and invoke by passing populated parameters
+ Mediator mediator = synCtx.getConfiguration().getSequence(targetTemplate);
+ if (mediator != null && mediator instanceof TemplateMediator) {
+ return mediator.mediate(synCtx);
+ }
+ return false;
+ }
+
+ /**
+ * poplulate declared parameters on temp synapse properties
+ * @param synCtx
+ */
+ private void populateParameters(MessageContext synCtx) {
+ Iterator<String> params = pName2ExpressionMap.keySet().iterator();
+ while (params.hasNext()) {
+ String parameter = params.next();
+ if (!"".equals(parameter)) {
+ Value expression = pName2ExpressionMap.get(parameter);
+ if (expression != null) {
+ EIPUtils.createSynapseEIPTemplateProperty(synCtx, targetTemplate, parameter, expression);
+ }
+ }
+ }
+ }
+
+ public String getTargetTemplate() {
+ return targetTemplate;
+ }
+
+ public void setTargetTemplate(String targetTemplate) {
+ this.targetTemplate = targetTemplate;
+ }
+
+ public Map<String, Value> getpName2ExpressionMap() {
+ return pName2ExpressionMap;
+ }
+
+ public void addExpressionForParamName(String pName, Value expr) {
+ pName2ExpressionMap.put(pName, expr);
+ }
+}
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateContext.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateContext.java?rev=1080145&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateContext.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateContext.java Thu Mar 10 08:04:41 2011
@@ -0,0 +1,111 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.synapse.mediators.template;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.mediators.Value;
+import org.apache.synapse.mediators.eip.EIPUtils;
+import org.jaxen.JaxenException;
+
+import java.util.*;
+
+/**
+ * This class will store runtime context of a synapse function template. For each invoked Template
+ * a context will be populated with function parameters.
+ */
+public class TemplateContext {
+ /**
+ * refers to the function-template name this context is binded to
+ */
+ private String fName;
+ /**
+ * refers to the parameter names of the function
+ */
+ private Collection<String> parameters;
+ /**
+ * contains a map for parameterNames to evaluated values
+ */
+ private Map mappedValues;
+
+ TemplateContext(String name, Collection<String> parameters) {
+ this.fName = name;
+ this.parameters = parameters;
+ mappedValues = new HashMap();
+ }
+
+ /**
+ * evaluate raw parameters passed from an invoke medaiator and store them in this context
+ * @param synCtxt Synapse MessageContext
+ */
+ public void setupParams(MessageContext synCtxt) {
+ Iterator<String> paramNames = parameters.iterator();
+ while (paramNames.hasNext()) {
+ String parameter = paramNames.next();
+ String mapping = EIPUtils.getTemplatePropertyMapping(fName, parameter);
+ Object propertyValue = synCtxt.getProperty(mapping);
+ Object paramValue = getEvaluatedParamValue(synCtxt, parameter, (Value) propertyValue);
+ if (paramValue != null) {
+ mappedValues.put(parameter, paramValue);
+ //remove temp property from the context
+ removeProperty(synCtxt, mapping);
+ }
+ }
+ }
+
+ /**
+ * This method will go through the provided expression and try to evaluate if an xpath expression
+ * or would return plain value. special case is present for a expression type plain value .
+ * ie:- plain values in an expression format ie:- {expr} .
+ * @return evaluated value/expression
+ */
+ private Object getEvaluatedParamValue(MessageContext synCtx, String parameter, Value expression) {
+ if (expression != null) {
+ if (expression.getExpression() != null) {
+ if(expression.hasExprTypeKey()){
+ return expression.getExpression();
+ } else {
+ return expression.evaluateValue(synCtx);
+ }
+ } else if (expression.getKeyValue() != null) {
+ return expression.evaluateValue(synCtx);
+ }
+ }
+ return null;
+ }
+
+
+ private void removeProperty(MessageContext synCtxt, String deletedMapping) {
+ //Removing property from the Synapse Context
+ Set keys = synCtxt.getPropertyKeySet();
+ if (keys != null) {
+ keys.remove(deletedMapping);
+ }
+ }
+
+ public Object getParameterValue(String paramName) {
+ return mappedValues.get(paramName);
+ }
+
+ public String getName() {
+ return fName;
+ }
+
+ public Collection getParameters() {
+ return parameters;
+ }
+}
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateMediator.java?rev=1080145&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateMediator.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/template/TemplateMediator.java Thu Mar 10 08:04:41 2011
@@ -0,0 +1,109 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.synapse.mediators.template;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.SynapseLog;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.mediators.base.SequenceMediator;
+
+import java.util.Collection;
+import java.util.Stack;
+
+/**
+ * This mediator is responsible for handling function templates for synapse. This will parse parameters
+ * passed from an <invoke> mediator and will be made available to sequences defined within this template.
+ * parameters will be accessible through synapse 'function stack'. Users should access these through an
+ * xpath extension var or function , defined under function scope
+ * ie:- $func:p1 or get-property('func','p2')
+ */
+public class TemplateMediator extends SequenceMediator {
+
+ private Collection<String> paramNames;
+
+ private String eipPatternName;
+
+ public void setParameters(Collection<String> paramNames) {
+ this.paramNames = paramNames;
+ }
+
+ public Collection<String> getParameters() {
+ return paramNames;
+ }
+
+ public void setName(String name) {
+ this.eipPatternName = name;
+ }
+
+ public String getName() {
+ return eipPatternName;
+ }
+
+ public void init(SynapseEnvironment env) {
+ super.init(env);
+ }
+
+ public boolean mediate(MessageContext synCtx) {
+ SynapseLog synLog = getLog(synCtx);
+
+ if (synLog.isTraceOrDebugEnabled()) {
+ synLog.traceOrDebug("Start : EIP Sequence " + "paramNames : " + paramNames);
+
+ if (synLog.isTraceTraceEnabled()) {
+ synLog.traceTrace("Message : " + synCtx.getEnvelope());
+ }
+ }
+ pushFuncContextTo(synCtx);
+ boolean result = false;
+ try {
+ result = super.mediate(synCtx);
+ } finally {
+ popFuncContextFrom(synCtx);
+ }
+ return result;
+ }
+
+ /**
+ * for each message coming to this function template ,pushes a function context containing
+ * parameters into Synapse Function Stack.
+ * @param synCtx Synapse Message context
+ */
+ private void pushFuncContextTo(MessageContext synCtx) {
+ TemplateContext funcContext = new TemplateContext(eipPatternName, paramNames);
+ //process the raw parameters parsed in
+ funcContext.setupParams(synCtx);
+ //if a function stack has not already been created for this message flow create new one
+ Stack<TemplateContext> stack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
+ if (stack == null) {
+ stack = new Stack<TemplateContext>();
+ stack.push(funcContext);
+ synCtx.setProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK, stack);
+ } else {
+ stack.push(funcContext);
+ }
+ }
+
+ private void popFuncContextFrom(MessageContext synCtx) {
+ Stack<TemplateContext> stack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
+ if (stack != null) {
+ stack.pop();
+ }
+ }
+
+}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java Thu Mar 10 08:04:41 2011
@@ -78,7 +78,7 @@ import java.util.*;
*/
public class SynapseXPath extends AXIOMXPath {
private static final long serialVersionUID = 7639226137534334222L;
-
+
private static final Log log = LogFactory.getLog(SynapseXPath.class);
/**
@@ -95,7 +95,7 @@ public class SynapseXPath extends AXIOMX
/**
* Construct an XPath expression from a given string and initialize its
* namespace context based on a given element.
- *
+ *
* @param element The element that determines the namespace context of the
* XPath expression. See {@link #addNamespaces(OMElement)}
* for more details.
@@ -111,8 +111,8 @@ public class SynapseXPath extends AXIOMX
* Construct an XPath expression from a given attribute.
* The string representation of the expression is taken from the attribute
* value, while the attribute's owner element is used to determine the
- * namespace context of the expression.
- *
+ * namespace context of the expression.
+ *
* @param attribute the attribute to construct the expression from
* @throws JaxenException if there is a syntax error while parsing the expression
* or if the namespace context could not be set up
@@ -125,7 +125,7 @@ public class SynapseXPath extends AXIOMX
if (xPathStr.indexOf('{') == -1) {
return new SynapseXPath(xPathStr);
}
-
+
int count = 0;
StringBuffer newXPath = new StringBuffer();
@@ -221,6 +221,37 @@ public class SynapseXPath extends AXIOMX
return null;
}
+ /**
+ * Specialized form of xpath evaluation function.An xpath evaluate() will be performed using two contexts
+ * (ie:-soap-envelope and on Synapse Message Context). This is useful for evaluating xpath on a
+ * nodeset for function contexts (we need both nodeset and synapse ctxts for evaluating function
+ * scope expressions)
+ * @param primaryContext a context object ie:- a soap envelope
+ * @param secondaryContext a context object ie:-synapse message ctxt
+ * @return result
+ */
+ public Object evaluate(Object primaryContext, MessageContext secondaryContext) {
+ Object result = null;
+ //if result is still not found use second ctxt ie:-syn-ctxt with a wrapper to evaluate
+ if (secondaryContext != null) {
+ try {
+ //wrapper Context is used to evaluate 'dynamic' function scope objects
+ result = evaluate(new ContextWrapper((SOAPEnvelope) primaryContext,secondaryContext));
+ } catch (Exception e) {
+ handleException("Evaluation of the XPath expression " + this.toString() +
+ " resulted in an error", e);
+ }
+ } else {
+ try {
+ result = evaluate(primaryContext);
+ } catch (JaxenException e) {
+ handleException("Evaluation of the XPath expression " + this.toString() +
+ " resulted in an error", e);
+ }
+ }
+ return result;
+ }
+
public void addNamespace(OMNamespace ns) throws JaxenException {
addNamespace(ns.getPrefix(), ns.getNamespaceURI());
}
@@ -245,7 +276,7 @@ public class SynapseXPath extends AXIOMX
* Note that the behavior described here also applies to all evaluation
* methods such as {@link #evaluate(Object)} or {@link #selectSingleNode(Object)},
* given that these methods all use {@link #getContext(Object)}.
- *
+ *
* @see SynapseXPathFunctionContext#getFunction(String, String, String)
* @see SynapseXPathVariableContext#getVariableValue(String, String, String)
*/
@@ -273,6 +304,18 @@ public class SynapseXPath extends AXIOMX
Context context = new Context(contextSupport);
context.setNodeSet(new SingletonList(env));
return context;
+ } else if (obj instanceof ContextWrapper) {
+ ContextWrapper wrapper = (ContextWrapper) obj;
+ ContextSupport baseContextSupport = getContextSupport();
+ ContextSupport contextSupport =
+ new ContextSupport(baseContextSupport.getNamespaceContext(),
+ baseContextSupport.getFunctionContext(),
+ new SynapseXPathVariableContext(baseContextSupport.getVariableContext(), wrapper.getMessageCtxt(),
+ wrapper.getEnvelope()),
+ baseContextSupport.getNavigator());
+ Context context = new Context(contextSupport);
+ context.setNodeSet(new SingletonList(wrapper.getEnvelope()));
+ return context;
} else {
return super.getContext(obj);
}
@@ -282,4 +325,26 @@ public class SynapseXPath extends AXIOMX
log.error(msg, e);
throw new SynapseException(msg, e);
}
+
+ /**
+ * This is a wrapper class used to inject both envelope and message contexts for xpath
+ * We use this to resolve function scope xpath variables
+ */
+ private static class ContextWrapper{
+ private MessageContext ctxt;
+ private SOAPEnvelope env;
+
+ public ContextWrapper(SOAPEnvelope env, MessageContext ctxt){
+ this.env = env;
+ this.ctxt = ctxt;
+ }
+
+ public SOAPEnvelope getEnvelope() {
+ return env;
+ }
+
+ public MessageContext getMessageCtxt() {
+ return ctxt;
+ }
+ }
}
\ No newline at end of file
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathConstants.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathConstants.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathConstants.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathConstants.java Thu Mar 10 08:04:41 2011
@@ -39,6 +39,9 @@ public final class SynapseXPathConstants
/** Variable prefix for accessing the MessageContext properties through XPath variables */
public static final String MESSAGE_CONTEXT_VARIABLE_PREFIX = "ctx";
+ /** Variable prefix for accessing the Function/Template Context properties through XPath variables */
+ public static final String FUNC_CONTEXT_VARIABLE_PREFIX = "func";
+
/** Variable prefix for accessing the axis2 MessageContext properties through XPath variables */
public static final String AXIS2_CONTEXT_VARIABLE_PREFIX = "axis2";
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathVariableContext.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathVariableContext.java?rev=1080145&r1=1080144&r2=1080145&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathVariableContext.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPathVariableContext.java Thu Mar 10 08:04:41 2011
@@ -21,6 +21,7 @@ package org.apache.synapse.util.xpath;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseConstants;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.description.AxisBindingOperation;
@@ -30,12 +31,15 @@ import org.apache.axis2.Constants;
import org.apache.axis2.transport.http.util.URIEncoderDecoder;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
+import org.apache.synapse.mediators.template.TemplateContext;
import org.apache.synapse.util.xpath.ext.XpathExtensionUtil;
+import org.jaxen.JaxenException;
import org.jaxen.UnresolvableException;
import org.jaxen.VariableContext;
import java.util.Map;
import java.io.UnsupportedEncodingException;
+import java.util.Stack;
/**
* Jaxen variable context for the XPath variables implicitly exposed by Synapse.
@@ -85,6 +89,19 @@ public class SynapseXPathVariableContext
}
/**
+ * <p>Initializes the <code>SynapseVariableContext</code> with the specified envelope</p>
+ *
+ * @param parent the parent variable context
+ * @param synCtx Synapse Message context to be initialized for the variable resolution
+ * @param env envelope to be initialized for the variable resolution
+ */
+ public SynapseXPathVariableContext(VariableContext parent, MessageContext synCtx, SOAPEnvelope env) {
+ this.parent = parent;
+ this.synCtx = synCtx;
+ this.env = env;
+ }
+
+ /**
* Gets the variable values resolved from the context. This includes the
* <dl>
* <dt><tt>body</tt></dt>
@@ -103,7 +120,7 @@ public class SynapseXPathVariableContext
* </dl>
* If the variable is unknown, this method attempts to resolve it using
* the parent variable context.
- *
+ *
* @param namespaceURI namespaces for the variable resolution
* @param prefix string prefix for the variable resolution
* @param localName string local name for the variable resolution
@@ -114,9 +131,9 @@ public class SynapseXPathVariableContext
throws UnresolvableException {
if (namespaceURI == null) {
-
+
if (env != null) {
-
+
if (SynapseXPathConstants.SOAP_BODY_VARIABLE.equals(localName)) {
return env.getBody();
} else if (SynapseXPathConstants.SOAP_HEADER_VARIABLE.equals(localName)) {
@@ -135,6 +152,22 @@ public class SynapseXPathVariableContext
return ((Axis2MessageContext)
synCtx).getAxis2MessageContext().getProperty(localName);
+ } else if (SynapseXPathConstants.FUNC_CONTEXT_VARIABLE_PREFIX.equals(prefix)) {
+ Stack<TemplateContext> functionStack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
+ TemplateContext topCtxt = functionStack.peek();
+ if (topCtxt != null) {
+ Object result = topCtxt.getParameterValue(localName);
+ if (result != null && result instanceof SynapseXPath && env != null) {
+ SynapseXPath expression = (SynapseXPath) topCtxt.getParameterValue(localName);
+ try {
+ return expression.evaluate(env);
+ } catch (JaxenException e) {
+ return null;
+ }
+ } else {
+ return result;
+ }
+ }
} else if (SynapseXPathConstants.TRANSPORT_VARIABLE_PREFIX.equals(prefix)) {
org.apache.axis2.context.MessageContext axis2MessageContext =
@@ -167,7 +200,7 @@ public class SynapseXPathVariableContext
int i = completeURL.indexOf("?");
if (i > -1) {
String queryString = completeURL.substring(i + 1);
-
+
if (queryString != null && !queryString.equals("")) {
String params[] = queryString.split(queryParameterSeparator);