You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by an...@apache.org on 2006/10/27 10:50:52 UTC
svn commit: r468322 - in /incubator/synapse/trunk/java: ./
modules/core/src/org/apache/synapse/config/xml/
modules/core/test/org/apache/synapse/mediators/ modules/extensions/
modules/extensions/src/META-INF/services/
modules/extensions/src/org/apache/s...
Author: antelder
Date: Fri Oct 27 01:50:50 2006
New Revision: 468322
URL: http://svn.apache.org/viewvc?view=rev&rev=468322
Log:
Add the repo where the Axis2 1.1 snapshots are currently going
Added:
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/InlineScriptMediator.java
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediator.java
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMessageContext.java
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ThreadLocalMessageContext.java
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java
incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java
incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/
incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/InlineScriptMediatorTest.java
incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorFactoryTest.java
incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorTest.java
incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMessageContextTest.java
incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_js.xml
incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_script.xml
incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteIn.js
incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteOut.js
Modified:
incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java
incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java
incubator/synapse/trunk/java/modules/extensions/project.xml
incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorFactory
incubator/synapse/trunk/java/project.properties
Modified: incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java?view=diff&rev=468322&r1=468321&r2=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java (original)
+++ incubator/synapse/trunk/java/modules/core/src/org/apache/synapse/config/xml/MediatorFactoryFinder.java Fri Oct 27 01:50:50 2006
@@ -142,9 +142,17 @@
*/
public Mediator getMediator(OMElement element) {
- QName qName = new QName(element.getNamespace().getName(), element.getLocalName());
+ String localName = element.getLocalName();
+ QName qName = new QName(element.getNamespace().getName(), localName);
log.debug("getMediator(" + qName + ")");
Class cls = (Class) factoryMap.get(qName);
+
+ if (cls == null && localName.indexOf('.') > -1) {
+ String newLocalName = localName.substring(0, localName.indexOf('.'));
+ qName = new QName(element.getNamespace().getName(), newLocalName);
+ log.debug("getMediator.2(" + qName + ")");
+ cls = (Class) factoryMap.get(qName);
+ }
if (cls == null) {
String msg = "Unknown mediator referenced by configuration element : " + qName;
Modified: incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java?view=diff&rev=468322&r1=468321&r2=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java (original)
+++ incubator/synapse/trunk/java/modules/core/test/org/apache/synapse/mediators/TestUtils.java Fri Oct 27 01:50:50 2006
@@ -15,26 +15,28 @@
*/
package org.apache.synapse.mediators;
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.synapse.MessageContext;
import org.apache.synapse.TestMessageContext;
-import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.config.Property;
+import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
import org.apache.synapse.registry.url.SimpleURLRegistry;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
-import java.io.StringReader;
-import java.util.Iterator;
-import java.util.Map;
public class TestUtils {
@@ -74,7 +76,7 @@
}
public static MessageContext createLightweightSynapseMessageContext(
- String paylod) throws Exception {
+ String payload) throws Exception {
org.apache.axis2.context.MessageContext mc =
new org.apache.axis2.context.MessageContext();
SynapseConfiguration config = new SynapseConfiguration();
@@ -86,14 +88,23 @@
OMAbstractFactory.getSOAP11Factory().createOMDocument();
omDoc.addChild(envelope);
- XMLStreamReader parser = XMLInputFactory.newInstance().
- createXMLStreamReader(new StringReader(paylod));
- StAXOMBuilder builder = new StAXOMBuilder(parser);
-
- // set a dummy static message
- envelope.getBody().addChild(builder.getDocumentElement());
+ envelope.getBody().addChild(createOMElement(payload));
synMc.setEnvelope(envelope);
return synMc;
}
+
+ public static OMElement createOMElement(String xml) {
+ try {
+
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
+ StAXOMBuilder builder = new StAXOMBuilder(reader);
+ OMElement omElement = builder.getDocumentElement();
+ return omElement;
+
+ } catch (XMLStreamException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
Modified: incubator/synapse/trunk/java/modules/extensions/project.xml
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/project.xml?view=diff&rev=468322&r1=468321&r2=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/project.xml (original)
+++ incubator/synapse/trunk/java/modules/extensions/project.xml Fri Oct 27 01:50:50 2006
@@ -1,107 +1,116 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project>
-
- <pomVersion>3</pomVersion>
- <extend>../../project.xml</extend>
-
- <!-- ============ -->
- <!-- Dependencies -->
- <!-- ============ -->
- <name>Apache Synapse - Extensions</name>
- <id>synapse-extensions</id>
- <groupId>synapse</groupId>
-
- <dependencies>
- <dependency>
- <groupId>synapse</groupId>
- <artifactId>synapse-core</artifactId>
- <version>${synapse.version}</version>
- </dependency>
-
- <!-- external JARs -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring</artifactId>
- <version>${spring.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
-
- <dependency>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- <version>${xerces.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
-
- <dependency>
- <groupId>xml-apis</groupId>
- <artifactId>xml-apis</artifactId>
- <version>${xml_apis.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
-
- <dependency>
- <groupId>xalan</groupId>
- <artifactId>xalan</artifactId>
- <version>${xalan.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
-
- <dependency>
- <groupId>rhino</groupId>
- <artifactId>js</artifactId>
- <version>${js.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
-
- <dependency>
- <groupId>xmlbeans</groupId>
- <artifactId>xbean</artifactId>
- <version>${xbean.version}</version>
- <properties>
- <module>true</module>
- </properties>
- </dependency>
-
- </dependencies>
-
- <build>
- <nagEmailAddress>synapse-dev@ws.apache.org</nagEmailAddress>
- <sourceDirectory>src</sourceDirectory>
- <unitTestSourceDirectory>test</unitTestSourceDirectory>
-
- <unitTest>
- <includes>
- <include>**/*Test.java</include>
- </includes>
-
- <resources>
- <resource>
- <directory>src</directory>
- <includes>
- <include>**/org.apache.synapse.config.xml.MediatorFactory</include>
- <include>**/org.apache.synapse.config.xml.ExtensionFactory</include>
- </includes>
- </resource>
- <resource>
- <directory>./../core/target/test-classes</directory>
- <includes>
- <include>**/*</include>
- </includes>
- </resource>
- </resources>
- </unitTest>
-
- </build>
-</project>
-
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+
+ <pomVersion>3</pomVersion>
+ <extend>../../project.xml</extend>
+
+ <!-- ============ -->
+ <!-- Dependencies -->
+ <!-- ============ -->
+ <name>Apache Synapse - Extensions</name>
+ <id>synapse-extensions</id>
+ <groupId>synapse</groupId>
+
+ <dependencies>
+ <dependency>
+ <groupId>synapse</groupId>
+ <artifactId>synapse-core</artifactId>
+ <version>${synapse.version}</version>
+ </dependency>
+
+ <!-- external JARs -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ <version>${spring.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>${xerces.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ <version>${xml_apis.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>${xalan.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ <version>${js.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <groupId>xmlbeans</groupId>
+ <artifactId>xbean</artifactId>
+ <version>${xbean.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <groupId>bsf</groupId>
+ <artifactId>bsf</artifactId>
+ <version>${bsf.version}</version>
+ <properties>
+ <module>true</module>
+ </properties>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <nagEmailAddress>synapse-dev@ws.apache.org</nagEmailAddress>
+ <sourceDirectory>src</sourceDirectory>
+ <unitTestSourceDirectory>test</unitTestSourceDirectory>
+
+ <unitTest>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+
+ <resources>
+ <resource>
+ <directory>src</directory>
+ <includes>
+ <include>**/org.apache.synapse.config.xml.MediatorFactory</include>
+ <include>**/org.apache.synapse.config.xml.ExtensionFactory</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>./../core/target/test-classes</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ </resources>
+ </unitTest>
+
+ </build>
+</project>
+
Modified: incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorFactory
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorFactory?view=diff&rev=468322&r1=468321&r2=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorFactory (original)
+++ incubator/synapse/trunk/java/modules/extensions/src/META-INF/services/org.apache.synapse.config.xml.MediatorFactory Fri Oct 27 01:50:50 2006
@@ -3,3 +3,4 @@
org.apache.synapse.mediators.spring.SpringMediatorFactory
org.apache.synapse.mediators.json.JsonMediatorFactory
org.apache.synapse.mediators.javascript.JavaScriptMediatorFactory
+org.apache.synapse.mediators.bsf.ScriptMediatorFactory
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/InlineScriptMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/InlineScriptMediator.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/InlineScriptMediator.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/InlineScriptMediator.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import org.apache.bsf.BSFException;
+import org.apache.bsf.BSFManager;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+
+
+/**
+ * An inline script mediator has the script source embedded in the config XML:
+ *
+ * <pre>
+ * <script.LL&gt...src code...<script.LL/>
+ * </pre>
+ *
+ * <p>
+ * where LL is the script language name extension. The environment of the script
+ * has the Synapse MessageContext predefined in a script variable named 'mc'.
+ */
+public class InlineScriptMediator extends ScriptMediator {
+
+ private String scriptName;
+
+ private String scriptSrc;
+
+ public InlineScriptMediator(String scriptName, String scriptSrc) {
+ super(null, null);
+ this.scriptName = scriptName;
+ this.scriptSrc = scriptSrc;
+ }
+
+ public boolean mediate(MessageContext synCtx) {
+ try {
+
+ ThreadLocalMessageContext.setMC(new ScriptMessageContext(synCtx, convertor));
+
+ Object response = bsfEngine.eval(scriptName, 0, 0, scriptSrc);
+
+ if (response instanceof Boolean) {
+ return ((Boolean) response).booleanValue();
+ }
+
+ return true; // default to returning true
+
+ } catch (BSFException e) {
+ throw new SynapseException(e);
+ }
+ }
+
+ public void init() {
+ try {
+ this.bsfManager.declareBean("mc", new ThreadLocalMessageContext(), ThreadLocalMessageContext.class);
+ String scriptLanguage = BSFManager.getLangFromFilename(scriptName);
+ this.bsfEngine = bsfManager.loadScriptingEngine(scriptLanguage);
+ this.convertor = createOMElementConvertor(scriptName);
+ convertor.setEngine(bsfEngine);
+ } catch (BSFException e) {
+ throw new SynapseException(e);
+ }
+ }
+}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediator.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediator.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediator.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediator.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.bsf.BSFEngine;
+import org.apache.bsf.BSFException;
+import org.apache.bsf.BSFManager;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.Property;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.bsf.convertors.DefaultOMElementConvertor;
+import org.apache.synapse.mediators.bsf.convertors.OMElementConvertor;
+
+/**
+ * A Synapse mediator that calls a function in any scripting language supported by BSF. The ScriptMediator using a registry property to define the
+ * registry property which contains the script source.
+ * <p>
+ *
+ * <pre>
+ * <script key="property-key" function="script-function-name" <script/>
+ * </pre>
+ *
+ * <p>
+ * The function is an optional attribute defining the name of the script function to call, if not specified it defaults to a function named 'mediate'.
+ * The function takes a single parameter which is the Synapse MessageContext. The function may return a boolean, if it does not then true is assumed.
+ */
+public class ScriptMediator extends AbstractMediator {
+
+ protected String scriptKey;
+
+ protected String functionName;
+
+ protected BSFEngine bsfEngine;
+
+ protected OMElementConvertor convertor;
+
+ protected BSFManager bsfManager;
+
+ public ScriptMediator(String scriptKey, String functionName) {
+ this.scriptKey = scriptKey;
+ this.functionName = functionName;
+ bsfManager = new BSFManager();
+ }
+
+ public boolean mediate(MessageContext synCtx) {
+ try {
+
+ BSFEngine engine = getBSFEngine(synCtx.getConfiguration());
+
+ Object[] args = new Object[] { new ScriptMessageContext(synCtx, convertor) };
+
+ Object response = engine.call(null, functionName, args);
+ if (response instanceof Boolean) {
+ return ((Boolean) response).booleanValue();
+ }
+
+ return true; // default to returning true
+
+ } catch (BSFException e) {
+ throw new SynapseException(e);
+ }
+ }
+
+ public synchronized BSFEngine getBSFEngine(SynapseConfiguration synapseConfig) {
+
+ Property dp = synapseConfig.getPropertyObject(scriptKey);
+ // boolean requiresRefresh = (dp != null) && (!dp.isCached() || dp.isExpired());
+ // if (bsfEngine == null || requiresRefresh) { TODO: sort out caching
+ if (bsfEngine == null) {
+ OMElement el = (OMElement) synapseConfig.getProperty(scriptKey);
+ String scriptSrc = el.getText();
+ String scriptName = dp.getSrc().toString();
+ this.bsfEngine = createBSFEngine(scriptName, scriptSrc);
+ this.convertor = createOMElementConvertor(scriptName);
+ convertor.setEngine(bsfEngine);
+ }
+
+ return bsfEngine;
+ }
+
+ protected BSFEngine createBSFEngine(String scriptName, String scriptSrc) {
+ try {
+
+ String scriptLanguage = BSFManager.getLangFromFilename(scriptName);
+ BSFEngine bsfEngine = bsfManager.loadScriptingEngine(scriptLanguage);
+ bsfEngine.exec(scriptName, 0, 0, scriptSrc);
+
+ return bsfEngine;
+
+ } catch (BSFException e) {
+ throw new SynapseException(e.getTargetException());
+ }
+ }
+
+ protected OMElementConvertor createOMElementConvertor(String scriptName) {
+ OMElementConvertor oc = null;
+ int lastDot = scriptName.lastIndexOf('.');
+ if (lastDot > -1) {
+ String suffix = scriptName.substring(lastDot + 1).toUpperCase();
+ String className = OMElementConvertor.class.getName();
+ int i = className.lastIndexOf('.');
+ String packageName = className.substring(0, i + 1);
+ String convertorClassName = packageName + suffix + className.substring(i + 1);
+ try {
+ oc = (OMElementConvertor) Class.forName(convertorClassName, true, getClass().getClassLoader()).newInstance();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ if (oc == null) {
+ oc = new DefaultOMElementConvertor();
+ }
+ return oc;
+ }
+
+}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import javax.xml.namespace.QName;
+
+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.config.xml.Constants;
+import org.apache.synapse.config.xml.MediatorFactory;
+
+/**
+ * Creates an instance of a Script mediator. <p/>
+ * <p>
+ * There are two ways of defining a script mediator, either using a registry property or
+ * inline in the Synapse config XML.
+ * <p>
+ * A script mediator using a registry property is defined as follows:
+ * <p>
+ * <pre>
+ * <script key="property-key" function="script-function-name" <script/>
+ * </pre>
+ * <p>
+ * The property-key is a Synapse registry property containing the script source. The function is an
+ * optional attribute defining the name of the script function to call, if not specified it
+ * defaults to a function named 'mediate'. The function takes a single parameter which is the
+ * Synapse MessageContext. The function may return a boolean, if it does not then true is assumed.
+ * <p>
+ * An inline script mediator has the script source embedded in the config XML:
+ * <pre>
+ * <script.LL>...src code...<script.LL/>
+ * </pre>
+ * <p>
+ * where LL is the script language name extension. The environment of the script has the Synapse
+ * MessageContext predefined in a script variable named 'mc'.
+ * <p>
+ * An example of an inline mediator using JavaScript/E4X which returns false if the SOAP message
+ * body contains an element named 'symbol' which has a value of 'IBM' would be:
+ * <p>
+ * <pre>
+ * <script.js>mc.getPayloadXML()..symbol != "IBM";<script.js/>
+ * </pre>
+ * <p>
+ * The boolean response from the inlined mediator is either the response from the evaluation of the
+ * script statements or if that result is not a boolean then a response of true is assumed.
+ * <p>
+ * The MessageContext passed in to the script mediator has additional methods over the Synapse
+ * MessageContext to enable working with the XML in a way natural to the scripting language. For
+ * example when using JavaScript get/setPayloadXML use E4X XML objects, when using Ruby they
+ * use REXML documents.
+ */
+public class ScriptMediatorFactory implements MediatorFactory {
+
+ private static final QName TAG_NAME = new QName(Constants.SYNAPSE_NAMESPACE, "script");
+
+ public Mediator createMediator(OMElement elem) {
+
+ ScriptMediator sm;
+
+ OMAttribute scriptKey = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "key"));
+ if (scriptKey != null) {
+ OMAttribute function = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "function"));
+ String functionName = (function == null) ? "mediate" : function.getAttributeValue();
+ sm = new ScriptMediator(scriptKey.getAttributeValue(), functionName);
+ } else if (elem.getLocalName().indexOf('.') > -1){
+ sm = new InlineScriptMediator(elem.getLocalName(), elem.getText());
+ ((InlineScriptMediator)sm).init();
+ } else {
+ throw new SynapseException("must specify 'key' attribute or inline script source");
+ }
+
+ return sm;
+ }
+
+ public QName getTagQName() {
+ return TAG_NAME;
+ }
+}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMessageContext.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMessageContext.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMessageContext.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ScriptMessageContext.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,233 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import java.util.Set;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.RelatesTo;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.mediators.bsf.convertors.OMElementConvertor;
+
+/**
+ * ScriptMessageContext decorates the Synapse MessageContext adding methods to use the message payload XML in a way natural to the scripting language.
+ */
+public class ScriptMessageContext implements MessageContext {
+
+ private MessageContext mc;
+
+ private OMElementConvertor convertor;
+
+ public ScriptMessageContext(MessageContext mc, OMElementConvertor convertor) {
+ this.mc = mc;
+ this.convertor = convertor;
+ }
+
+ /**
+ * Get the XML representation of SOAP Body payload.
+ * The payload is the first element inside the SOAP <Body> tags
+ *
+ * @return the XML SOAP Body
+ */
+ public Object getPayloadXML() {
+ return convertor.toScript(mc.getEnvelope().getBody().getFirstElement());
+ }
+
+ /**
+ * Set the SOAP body payload from XML
+ *
+ * @param payload
+ * @throws XMLStreamException
+ */
+ public void setPayloadXML(Object payload) {
+ mc.getEnvelope().getBody().setFirstChild(convertor.fromScript(payload));
+ }
+
+ /**
+ * Get the XML representation of the complete SOAP envelope
+ */
+ public Object getEnvelopeXML() {
+ return convertor.toScript(mc.getEnvelope());
+ }
+
+ // helpers to set EPRs from a script string
+
+ public void setTo(String reference) {
+ mc.setTo(new EndpointReference(reference));
+ }
+ public void setFaultTo(String reference) {
+ mc.setFaultTo(new EndpointReference(reference));
+ }
+ public void setFrom(String reference) {
+ mc.setFrom(new EndpointReference(reference));
+ }
+ public void setReplyTo(String reference) {
+ mc.setReplyTo(new EndpointReference(reference));
+ }
+
+ // -- all the remainder just use the underlying MessageContext
+
+ public SynapseConfiguration getConfiguration() {
+ return mc.getConfiguration();
+ }
+
+ public void setConfiguration(SynapseConfiguration cfg) {
+ mc.setConfiguration(cfg);
+ }
+
+ public SynapseEnvironment getEnvironment() {
+ return mc.getEnvironment();
+ }
+
+ public void setEnvironment(SynapseEnvironment se) {
+ mc.setEnvironment(se);
+ }
+
+ public Object getProperty(String key) {
+ return mc.getConfiguration();
+ }
+
+ public void setProperty(String key, Object value) {
+ mc.setProperty(key, value);
+ }
+
+ public Set getPropertyKeySet() {
+ return mc.getPropertyKeySet();
+ }
+
+ public SOAPEnvelope getEnvelope() {
+ return mc.getEnvelope();
+ }
+
+ public void setEnvelope(SOAPEnvelope envelope) throws AxisFault {
+ mc.setEnvelope(envelope);
+ }
+
+ public EndpointReference getFaultTo() {
+ return mc.getFaultTo();
+ }
+
+ public void setFaultTo(EndpointReference reference) {
+ mc.setFaultTo(reference);
+ }
+
+ public EndpointReference getFrom() {
+ return mc.getFrom();
+ }
+
+ public void setFrom(EndpointReference reference) {
+ mc.setFrom(reference);
+ }
+
+ public String getMessageID() {
+ return mc.getMessageID();
+ }
+
+ public void setMessageID(String string) {
+ mc.setMessageID(string);
+ }
+
+ public RelatesTo getRelatesTo() {
+ return mc.getRelatesTo();
+ }
+
+ public void setRelatesTo(RelatesTo[] reference) {
+ mc.setRelatesTo(reference);
+ }
+
+ public EndpointReference getReplyTo() {
+ return mc.getReplyTo();
+ }
+
+ public void setReplyTo(EndpointReference reference) {
+ mc.setReplyTo(reference);
+ }
+
+ public EndpointReference getTo() {
+ return mc.getTo();
+ }
+
+ public void setTo(EndpointReference reference) {
+ mc.setTo(reference);
+ }
+
+ public void setWSAAction(String actionURI) {
+ mc.setWSAAction(actionURI);
+ }
+
+ public String getWSAAction() {
+ return mc.getWSAAction();
+ }
+
+ public String getSoapAction() {
+ return mc.getSoapAction();
+ }
+
+ public void setSoapAction(String string) {
+ mc.setSoapAction(string);
+ }
+
+ public void setMessageId(String messageID) {
+ mc.setMessageId(messageID);
+ }
+
+ public String getMessageId() {
+ return mc.getMessageId();
+ }
+
+ public boolean isDoingMTOM() {
+ return mc.isDoingMTOM();
+ }
+
+ public void setDoingMTOM(boolean b) {
+ mc.setDoingMTOM(b);
+ }
+
+ public boolean isDoingREST() {
+ return mc.isDoingREST();
+ }
+
+ public void setDoingREST(boolean b) {
+ mc.setDoingREST(b);
+ }
+
+ public boolean isSOAP11() {
+ return mc.isSOAP11();
+ }
+
+ public void setResponse(boolean b) {
+ mc.setResponse(b);
+ }
+
+ public boolean isResponse() {
+ return mc.isResponse();
+ }
+
+ public void setFaultResponse(boolean b) {
+ mc.setFaultResponse(b);
+ }
+
+ public boolean isFaultResponse() {
+ return mc.isFaultResponse();
+ }
+
+}
\ No newline at end of file
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ThreadLocalMessageContext.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ThreadLocalMessageContext.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ThreadLocalMessageContext.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/ThreadLocalMessageContext.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import java.util.Set;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.addressing.RelatesTo;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.core.SynapseEnvironment;
+
+/**
+ * This delegates all method calls to thread specific MessageContext.
+ *
+ * This is required for the InlineScriptMediator to enable concurrent requests to run against the same inline script. As there is a single BSFEngine
+ * holding the inline script fragment and the MessageContext is pre-registered in that BSFEngine means there is a single MessageContext instance
+ * shared over all requests. Using this class as the single pre-registered MessageContext enables delegating all the method calls to a thread specific
+ * MessageContext instance that is registerd on the thread just prior to the script being invoked.
+ */
+public class ThreadLocalMessageContext implements MessageContext {
+
+ private static ThreadLocal threadLocalMC = new ThreadLocal();
+
+ public static void setMC(ScriptMessageContext mc) {
+ threadLocalMC.set(mc);
+ }
+
+ public ScriptMessageContext getMC() {
+ return (ScriptMessageContext) threadLocalMC.get();
+ }
+
+ // non-MessageContext helpers on the ScriptMessageContext class
+
+ public Object getPayloadXML() {
+ return getMC().getPayloadXML();
+ }
+
+ public void setPayloadXML(Object payload) {
+ getMC().setPayloadXML(payload);
+ }
+
+ public Object getEnvelopeXML() {
+ return getMC().getEnvelopeXML();
+ }
+
+ public void setTo(String reference) {
+ getMC().setTo(reference);
+ }
+
+ public void setFaultTo(String reference) {
+ getMC().setFaultTo(reference);
+ }
+
+ public void setFrom(String reference) {
+ getMC().setFrom(reference);
+ }
+
+ public void setReplyTo(String reference) {
+ getMC().setReplyTo(reference);
+ }
+
+ // -- all the MessageContext interface methods
+
+ public SynapseConfiguration getConfiguration() {
+ return getMC().getConfiguration();
+ }
+
+ public SOAPEnvelope getEnvelope() {
+ return getMC().getEnvelope();
+ }
+
+ public SynapseEnvironment getEnvironment() {
+ return getMC().getEnvironment();
+ }
+
+ public EndpointReference getFaultTo() {
+ return getMC().getFaultTo();
+ }
+
+ public EndpointReference getFrom() {
+ return getMC().getFrom();
+ }
+
+ public String getMessageID() {
+ return getMC().getMessageID();
+ }
+
+ public String getMessageId() {
+ return getMC().getMessageId();
+ }
+
+ public Object getProperty(String key) {
+ return getMC().getProperty(key);
+ }
+
+ public Set getPropertyKeySet() {
+ return getMC().getPropertyKeySet();
+ }
+
+ public RelatesTo getRelatesTo() {
+ return getMC().getRelatesTo();
+ }
+
+ public EndpointReference getReplyTo() {
+ return getMC().getReplyTo();
+ }
+
+ public String getSoapAction() {
+ return getMC().getSoapAction();
+ }
+
+ public EndpointReference getTo() {
+ return getMC().getTo();
+ }
+
+ public String getWSAAction() {
+ return getMC().getWSAAction();
+ }
+
+ public boolean isDoingMTOM() {
+ return getMC().isDoingMTOM();
+ }
+
+ public boolean isDoingREST() {
+ return getMC().isDoingREST();
+ }
+
+ public boolean isFaultResponse() {
+ return getMC().isFaultResponse();
+ }
+
+ public boolean isResponse() {
+ return getMC().isResponse();
+ }
+
+ public boolean isSOAP11() {
+ return getMC().isSOAP11();
+ }
+
+ public void setConfiguration(SynapseConfiguration cfg) {
+ getMC().setConfiguration(cfg);
+ }
+
+ public void setDoingMTOM(boolean b) {
+ getMC().setDoingMTOM(b);
+ }
+
+ public void setDoingREST(boolean b) {
+ getMC().setDoingREST(b);
+ }
+
+ public void setEnvelope(SOAPEnvelope envelope) throws AxisFault {
+ getMC().setEnvelope(envelope);
+ }
+
+ public void setEnvironment(SynapseEnvironment se) {
+ getMC().setEnvironment(se);
+ }
+
+ public void setFaultResponse(boolean b) {
+ getMC().setFaultResponse(b);
+ }
+
+ public void setFaultTo(EndpointReference reference) {
+ getMC().setFaultTo(reference);
+ }
+
+ public void setFrom(EndpointReference reference) {
+ getMC().setFrom(reference);
+ }
+
+ public void setMessageID(String string) {
+ getMC().setMessageID(string);
+ }
+
+ public void setMessageId(String messageID) {
+ getMC().setMessageId(messageID);
+ }
+
+ public void setProperty(String key, Object value) {
+ getMC().setProperty(key, value);
+ }
+
+ public void setRelatesTo(RelatesTo[] reference) {
+ getMC().setRelatesTo(reference);
+ }
+
+ public void setReplyTo(EndpointReference reference) {
+ getMC().setReplyTo(reference);
+ }
+
+ public void setResponse(boolean b) {
+ getMC().setResponse(b);
+ }
+
+ public void setSoapAction(String string) {
+ getMC().setSoapAction(string);
+ }
+
+ public void setTo(EndpointReference reference) {
+ getMC().setTo(reference);
+ }
+
+ public void setWSAAction(String actionURI) {
+ getMC().setWSAAction(actionURI);
+ }
+
+}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf.convertors;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.bsf.BSFEngine;
+import org.apache.synapse.SynapseException;
+
+/**
+ * The DefaultOMElementConvertor converts between Synapse OMElements and Strings
+ */
+public class DefaultOMElementConvertor implements OMElementConvertor {
+
+ public OMElement fromScript(Object o) {
+ try {
+
+ byte[] xmlBytes = o.toString().getBytes();
+ StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(xmlBytes));
+ OMElement omElement = builder.getDocumentElement();
+ return omElement;
+
+ } catch (XMLStreamException e) {
+ throw new SynapseException(e);
+ }
+ }
+
+ public Object toScript(OMElement omElement) {
+ return omElement.toString();
+ }
+
+ public void setEngine(BSFEngine e) {
+ }
+
+}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf.convertors;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.synapse.SynapseException;
+import org.apache.xmlbeans.XmlObject;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.Wrapper;
+import org.mozilla.javascript.xml.XMLObject;
+
+/**
+ * JSObjectConvertor converts between Synapse OMElements and JavaScript E4X XML objects
+ */
+public class JSOMElementConvertor extends DefaultOMElementConvertor {
+
+ protected Scriptable scope;
+
+ public JSOMElementConvertor() {
+ Context cx = Context.enter();
+ try {
+ this.scope = cx.initStandardObjects();
+ } finally {
+ Context.exit();
+ }
+ }
+
+ public Object toScript(OMElement o) {
+ XmlObject xml;
+ try {
+ xml = XmlObject.Factory.parse(new ByteArrayInputStream(o.toString().getBytes()));
+ } catch (Exception e) {
+ throw new SynapseException("exception getting message XML: " + e);
+ }
+
+ Context cx = Context.enter();
+ try {
+
+ Object wrappedXML = cx.getWrapFactory().wrap(cx, scope, xml, XmlObject.class);
+ Scriptable jsXML = cx.newObject(scope, "XML", new Object[] { wrappedXML });
+
+ return jsXML;
+
+ } finally {
+ Context.exit();
+ }
+ }
+
+ public OMElement fromScript(Object o) {
+ if (!(o instanceof XMLObject)) {
+ return super.fromScript(o);
+ }
+
+ // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost???
+ Scriptable jsXML = (Scriptable) ScriptableObject.callMethod((Scriptable) o, "copy", new Object[0]);
+ Wrapper wrapper = (Wrapper) ScriptableObject.callMethod(jsXML, "getXmlObject", new Object[0]);
+ Object response = wrapper.unwrap();
+
+ try {
+
+ byte[] xmlBytes = response.toString().getBytes();
+ StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(xmlBytes));
+ OMElement omElement = builder.getDocumentElement();
+
+ return omElement;
+
+ } catch (XMLStreamException e) {
+ throw new SynapseException(e);
+ }
+ }
+
+}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf.convertors;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.bsf.BSFEngine;
+
+/**
+ * The OMElementConvertor interface enables customizing the conversion of
+ * XML between Synapse and a script language. Some script languages have their
+ * own ways of using XML, such as E4X in JavaScript or REXML in Ruby. But BSF
+ * has no support for those so Synapse needs to handle this itself, which is what
+ * the OMElementConvertor does.
+ *
+ * Which OMElementConvertor type to use is discovered based on the file name suffix of
+ * the mediator script. The suffix is converted to uppercase and used as the prefix to
+ * the OMElementConvertor classname. For example, with a JavaScript script named myscript.js
+ * the .js suffix is taken to make the convertor class name
+ * "org.apache.synapse.mediators.bsf.convertors.JSOMElementConvertor"
+ * If the convertor class is not found then a default convertor is used which converts
+ * XML to a String representation.
+ */
+public interface OMElementConvertor {
+
+ public void setEngine(BSFEngine e);
+ public Object toScript(OMElement omElement);
+
+ public OMElement fromScript(Object o);
+
+}
Added: incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/src/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf.convertors;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.bsf.BSFEngine;
+import org.apache.bsf.BSFException;
+import org.apache.synapse.SynapseException;
+
+/**
+ * OMElementConvertor for Ruby scripts
+ *
+ * TODO: Right now this goes via Strings and likely isn't very fast
+ * There could well be much better ways to do this :)
+ */
+public class RBOMElementConvertor implements OMElementConvertor {
+
+ protected BSFEngine bsfEngine;
+
+ public RBOMElementConvertor() {
+ }
+
+ public Object toScript(OMElement omElement) {
+ try {
+
+ StringBuilder srcFragment = new StringBuilder("Document.new(<<EOF\n");
+ srcFragment.append(omElement.toString());
+ srcFragment.append("\nEOF\n");
+ srcFragment.append(")");
+
+ Object o = bsfEngine.eval("RBOMElementConvertor", 0, 0, srcFragment.toString());
+ return o;
+
+ } catch (BSFException e) {
+ throw new SynapseException(e);
+ }
+ }
+
+ public OMElement fromScript(Object o) {
+ try {
+
+ byte[] xmlBytes = o.toString().getBytes();
+ StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(xmlBytes));
+ OMElement omElement = builder.getDocumentElement();
+
+ return omElement;
+
+ } catch (XMLStreamException e) {
+ throw new SynapseException(e);
+ }
+ }
+
+ public void setEngine(BSFEngine e) {
+ this.bsfEngine = e;
+ }
+}
Added: incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/InlineScriptMediatorTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/InlineScriptMediatorTest.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/InlineScriptMediatorTest.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/InlineScriptMediatorTest.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import java.net.MalformedURLException;
+
+import junit.framework.TestCase;
+
+import org.apache.synapse.mediators.TestUtils;
+
+public class InlineScriptMediatorTest extends TestCase {
+
+ public void testTrueMediator() throws MalformedURLException {
+ InlineScriptMediator mediator = new InlineScriptMediator("true.js", "true");
+ mediator.init();
+ assertTrue(mediator.mediate(null));
+ }
+
+ public void testFalseMediator() throws MalformedURLException {
+ InlineScriptMediator mediator = new InlineScriptMediator("false.js", "false");
+ mediator.init();
+ assertFalse(mediator.mediate(null));
+ }
+
+ public void testXMLMediator() throws Exception {
+ InlineScriptMediator mediator = new InlineScriptMediator("xml.js", "'xml' == (typeof mc.getPayloadXML());");
+ mediator.init();
+ assertTrue(mediator.mediate(TestUtils.getTestContext("<foo/>")));
+ }
+
+}
Added: incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorFactoryTest.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorFactoryTest.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorFactoryTest.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.config.Property;
+import org.apache.synapse.mediators.TestUtils;
+
+public class ScriptMediatorFactoryTest extends TestCase {
+
+ private static final OMElement INLINE_MEDIATOR_CONFIG = TestUtils.createOMElement(
+ "<script.js>true</script.js>");
+
+ private static final OMElement REG_PROP_MEDIATOR_CONFIG = TestUtils.createOMElement(
+ "<script key=\"MyMediator\"/>");
+
+ private static final OMElement REG_PROP_FOO_FUNC_MEDIATOR_CONFIG = TestUtils.createOMElement(
+ "<script key=\"MyFooMediator\" function=\"foo\"/>");
+
+ private static final OMElement MY_MEDIATOR = TestUtils.createOMElement(
+ "<x><![CDATA[ function mediate(mc) { return true;} ]]></x>");
+
+ private static final OMElement MY_MEDIATOR_FOO_FUNC = TestUtils.createOMElement(
+ "<x><![CDATA[ function foo(mc) { return true;} ]]></x>");
+
+ public void testInlineScriptMediatorFactory() throws XMLStreamException {
+ ScriptMediatorFactory mf = new ScriptMediatorFactory();
+ Mediator mediator = mf.createMediator(INLINE_MEDIATOR_CONFIG);
+ assertTrue(mediator.mediate(null));
+ }
+
+ public void testRegPropMediatorFactory() throws Exception {
+ Property prop = new Property();
+ prop.setValue(MY_MEDIATOR);
+ prop.setSrc(new URL("http://MyMediator.js"));
+ Map props = new HashMap();
+ props.put("MyMediator", prop);
+ MessageContext mc = TestUtils.getTestContext("<foo/>", props);
+
+ ScriptMediatorFactory mf = new ScriptMediatorFactory();
+ Mediator mediator = mf.createMediator(REG_PROP_MEDIATOR_CONFIG);
+ assertTrue(mediator.mediate(mc));
+ }
+
+ public void testRegPropWithFunctionMediatorFactory() throws Exception {
+ Property prop = new Property();
+ prop.setValue(MY_MEDIATOR_FOO_FUNC);
+ prop.setSrc(new URL("http://MyFooMediator.js"));
+ Map props = new HashMap();
+ props.put("MyFooMediator", prop);
+ MessageContext mc = TestUtils.getTestContext("<foo/>", props);
+
+ ScriptMediatorFactory mf = new ScriptMediatorFactory();
+ Mediator mediator = mf.createMediator(REG_PROP_FOO_FUNC_MEDIATOR_CONFIG);
+ assertTrue(mediator.mediate(mc));
+ }
+
+}
Added: incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorTest.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorTest.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMediatorTest.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.config.Property;
+import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.mediators.bsf.convertors.DefaultOMElementConvertor;
+import org.apache.synapse.mediators.bsf.convertors.JSOMElementConvertor;
+import org.apache.synapse.mediators.bsf.convertors.OMElementConvertor;
+import org.apache.synapse.mediators.bsf.convertors.RBOMElementConvertor;
+
+public class ScriptMediatorTest extends TestCase {
+
+ private static final OMElement TRUE_MEDIATOR = TestUtils.createOMElement(
+ "<x><![CDATA[ function mediate(mc) { return true;} ]]></x>");
+
+ private static final OMElement FALSE_MEDIATOR = TestUtils.createOMElement(
+ "<x><![CDATA[ function mediate(mc) { return false;} ]]></x>");
+
+ private static final OMElement XML_MEDIATOR = TestUtils.createOMElement(
+ "<x><![CDATA[ function mediate(mc) { return 'xml' == (typeof mc.getPayloadXML());} ]]></x>");
+
+ public void testTrueMediator() throws Exception {
+
+ Property prop = new Property();
+ prop.setValue(TRUE_MEDIATOR);
+ prop.setSrc(new URL("http://MyMediator.js"));
+ Map props = new HashMap();
+ props.put("TRUE_MEDIATOR", prop);
+ MessageContext mc = TestUtils.getTestContext("<foo/>", props);
+
+ ScriptMediator mediator = new ScriptMediator("TRUE_MEDIATOR", "mediate");
+ assertTrue(mediator.mediate(mc));
+ }
+
+ public void testFalseMediator() throws Exception {
+ Property prop = new Property();
+ prop.setValue(FALSE_MEDIATOR);
+ prop.setSrc(new URL("http://MyFooMediator.js"));
+ Map props = new HashMap();
+ props.put("FALSE_MEDIATOR", prop);
+ MessageContext mc = TestUtils.getTestContext("<foo/>", props);
+
+ ScriptMediator mediator = new ScriptMediator("FALSE_MEDIATOR", "mediate");
+ assertFalse(mediator.mediate(mc));
+ }
+
+ public void testXMLMediator() throws Exception {
+
+ Property prop = new Property();
+ prop.setValue(XML_MEDIATOR);
+ prop.setSrc(new URL("http://MyFooMediator.js"));
+ Map props = new HashMap();
+ props.put("XML_MEDIATOR", prop);
+ MessageContext mc = TestUtils.getTestContext("<foo/>", props);
+
+ ScriptMediator mediator = new ScriptMediator("XML_MEDIATOR", "mediate");
+ assertTrue(mediator.mediate(mc));
+ }
+
+ public void testJSCreateOMElementConvertor() {
+ ScriptMediator mediator = new ScriptMediator(null, null);
+ OMElementConvertor convertor = mediator.createOMElementConvertor("foo.js");
+ assertTrue(convertor instanceof JSOMElementConvertor);
+ }
+
+ public void testRBCreateOMElementConvertor() {
+ ScriptMediator mediator = new ScriptMediator(null, null);
+ OMElementConvertor convertor = mediator.createOMElementConvertor("foo.rb");
+ assertTrue(convertor instanceof RBOMElementConvertor);
+ }
+
+ public void testDefaultCreateOMElementConvertor() {
+ ScriptMediator mediator = new ScriptMediator(null, null);
+ OMElementConvertor convertor = mediator.createOMElementConvertor("foo.bla");
+ assertTrue(convertor instanceof DefaultOMElementConvertor);
+ }
+
+}
Added: incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMessageContextTest.java
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMessageContextTest.java?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMessageContextTest.java (added)
+++ incubator/synapse/trunk/java/modules/extensions/test/org/apache/synapse/mediators/bsf/ScriptMessageContextTest.java Fri Oct 27 01:50:50 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.bsf;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.mediators.TestUtils;
+import org.apache.synapse.mediators.bsf.convertors.DefaultOMElementConvertor;
+
+public class ScriptMessageContextTest extends TestCase {
+
+ private static final String ENV =
+ "<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body><foo /></soapenv:Body></soapenv:Envelope>";
+
+ public void testGetPayloadXML() throws Exception {
+ ScriptMessageContext smc = new ScriptMessageContext(TestUtils.getTestContext("<foo/>"), new DefaultOMElementConvertor());
+ assertEquals("<foo />", smc.getPayloadXML());
+ }
+
+ public void testSetPayloadXML() throws Exception {
+ ScriptMessageContext smc = new ScriptMessageContext(TestUtils.getTestContext("<foo/>"), new DefaultOMElementConvertor());
+ smc.setPayloadXML("<petra/>");
+ OMElement payload = smc.getEnvelope().getBody().getFirstElement();
+ assertEquals("<petra />", payload.toString());
+ }
+
+ public void testGetEnvelopeXML() throws Exception {
+ ScriptMessageContext smc = new ScriptMessageContext(TestUtils.getTestContext("<foo/>"), new DefaultOMElementConvertor());
+ assertEquals(ENV, smc.getEnvelopeXML());
+ }
+
+}
Modified: incubator/synapse/trunk/java/project.properties
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/project.properties?view=diff&rev=468322&r1=468321&r2=468322
==============================================================================
--- incubator/synapse/trunk/java/project.properties (original)
+++ incubator/synapse/trunk/java/project.properties Fri Oct 27 01:50:50 2006
@@ -5,6 +5,7 @@
http://www.ibiblio.org/maven,\
http://people.apache.org/repository/,\
http://www.apache.org/dist/java-repository/,\
+http://ws.zones.apache.org/repository/,\
http://www.openejb.org/maven,\
http://dist.codehaus.org/,\
http://mirrors.sunsite.dk/maven/,\
@@ -84,6 +85,8 @@
js.version=1.6R2
xbean.version=2.1.0
+
+bsf.version=2.4.0
mina.version=0.8.0
slf4j.version=1.0
Added: incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_js.xml
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_js.xml?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_js.xml (added)
+++ incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_js.xml Fri Oct 27 01:50:50 2006
@@ -0,0 +1,35 @@
+<synapse xmlns="http://ws.apache.org/ns/synapse" xmlns:js="http://ws.apache.org/ns/synapse/js">
+ <rules>
+
+ <in>
+ <js:javascript><![CDATA[
+ function mediate(msg) {
+ msg.setPayloadXML(
+ <ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
+ <symbol xsi:type="xsd:string"> { msg.getPayloadXML()..*::symbol.toString() } </symbol>
+ </ns1:getQuote>);
+ }
+ ]]></js:javascript>
+
+ <header name="To" value="http://64.124.140.30:9090/soap"/>
+
+ </in>
+
+ <out>
+ <js:javascript><![CDATA[
+ function mediate(msg) {
+ msg.setPayloadXML(
+ <ns:getQuoteResponse xmlns:ns="http://services.samples/xsd">
+ <ns:return>
+ <ns:last> { msg.getPayloadXML()..Result.toString() } </ns:last>
+ </ns:return>
+ </ns:getQuoteResponse>);
+ }
+ ]]></js:javascript>
+ </out>
+
+ <send/>
+
+ </rules>
+</synapse>
+
Added: incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_script.xml
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_script.xml?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_script.xml (added)
+++ incubator/synapse/trunk/java/repository/conf/sample/synapse_sample_script.xml Fri Oct 27 01:50:50 2006
@@ -0,0 +1,25 @@
+<synapse xmlns="http://ws.apache.org/ns/synapse">
+
+ <definitions>
+
+ <set-property name="xmethodsStockquoteIn" src="file:synapse_repository/conf/sample/xmethodsStockquoteIn.js"/>
+ <set-property name="xmethodsStockquoteOut" src="file:synapse_repository/conf/sample/xmethodsStockquoteOut.js"/>
+
+ </definitions>
+
+ <rules>
+
+ <in>
+ <script key="xmethodsStockquoteIn"/>
+ <header name="To" value="http://64.124.140.30:9090/soap"/>
+ </in>
+
+ <out>
+ <script key="xmethodsStockquoteOut"/>
+ </out>
+
+ <send/>
+
+ </rules>
+
+</synapse>
\ No newline at end of file
Added: incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteIn.js
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteIn.js?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteIn.js (added)
+++ incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteIn.js Fri Oct 27 01:50:50 2006
@@ -0,0 +1,14 @@
+<x><![CDATA[
+
+ function mediate(msg) {
+
+ var payload = new XML(msg.getPayloadXML());
+ var newPayload = <ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
+ <symbol xsi:type="xsd:string"> { payload..*::symbol.toString() } </symbol>
+ </ns1:getQuote>;
+ msg.setPayloadXML(newPayload);
+ }
+
+]]></x>
+
+
Added: incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteOut.js
URL: http://svn.apache.org/viewvc/incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteOut.js?view=auto&rev=468322
==============================================================================
--- incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteOut.js (added)
+++ incubator/synapse/trunk/java/repository/conf/sample/xmethodsStockquoteOut.js Fri Oct 27 01:50:50 2006
@@ -0,0 +1,19 @@
+<x><![CDATA[
+
+ function mediate(msg) {
+
+ var payload = new XML(msg.getPayloadXML());
+
+ var newPayload = <ns:getQuoteResponse xmlns:ns="http://services.samples/xsd">
+ <ns:return>
+ <ns:last> { payload..Result.toString() } </ns:last>
+ </ns:return>
+ </ns:getQuoteResponse>;
+
+ msg.setPayloadXML(newPayload);
+ }
+
+
+]]></x>
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org