Upgrading Rhino version to 1.7R5; Applying patch from Nuwan submitted at SYNAPSE-1013
git-svn-id: https://svn.apache.org/repos/asf/synapse/trunk@1745672 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/java/modules/extensions/pom.xml b/java/modules/extensions/pom.xml
index 1c8b065..f93a809 100644
--- a/java/modules/extensions/pom.xml
+++ b/java/modules/extensions/pom.xml
@@ -136,8 +136,8 @@
<artifactId>wso2throttle-core</artifactId>
</dependency>
<dependency>
- <groupId>rhino</groupId>
- <artifactId>js</artifactId>
+ <groupId>org.mozilla</groupId>
+ <artifactId>rhino</artifactId>
</dependency>
<dependency>
<groupId>xerces</groupId>
diff --git a/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/JavaScriptXmlHelper.java b/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/JavaScriptXmlHelper.java
new file mode 100644
index 0000000..cf3883f
--- /dev/null
+++ b/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/JavaScriptXmlHelper.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.bsf;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.bsf.xml.DefaultXMLHelper;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.xml.XMLObject;
+
+import javax.script.ScriptException;
+import javax.xml.stream.XMLStreamException;
+
+/**
+ * This class will provide the operation to getPayloadXML and setPayload of
+ * ScriptMessageContext to convert between XML and ScriptXML object
+ * since there is an api change in rhino17,This class is provided instead of
+ * getting Helper class by XMLHelper.getArgHelper(engine) in bsf
+ */
+
+public class JavaScriptXmlHelper extends DefaultXMLHelper {
+
+ private final Scriptable scope;
+
+ JavaScriptXmlHelper() {
+ Context cx = Context.enter();
+ try {
+ this.scope = cx.initStandardObjects();
+ } finally {
+ Context.exit();
+ }
+ }
+
+ /**
+ * This method will convert the message payload in to xml
+ *
+ * @param scriptXML from java script Scriptable
+ * @return XML content as OMElement wrapped in Scriptable object
+ * @throws javax.script.ScriptException when error
+ */
+ public OMElement toOMElement(Object scriptXML) throws ScriptException {
+ if (scriptXML == null) {
+ return null;
+ }
+ if (!(scriptXML instanceof XMLObject)) {
+ return null;
+ }
+ // TODO: E4X Bug? Shouldn't need this copy, but without it the outer element gets lost???
+ Scriptable jsXML = (Scriptable) ScriptableObject.callMethod(
+ (Scriptable) scriptXML, "copy", new Object[0]);
+
+ OMElement omElement;
+ try {
+ omElement = AXIOMUtil.stringToOM((String) ScriptableObject.callMethod(
+ jsXML, "toXMLString", new Object[0]));
+ } catch (XMLStreamException e) {
+ throw new ScriptException(e);
+ }
+ return omElement;
+ }
+
+ /**
+ * This method will convert the message payload in to ScriptXML Object
+ *
+ * @param omElement
+ * @return Scriptable object by adding the xml content
+ * @throws javax.script.ScriptException when error
+ */
+ public Object toScriptXML(OMElement omElement)
+ throws ScriptException {
+ if (omElement == null) {
+ return null;
+ }
+ Context cx = Context.enter();
+ try {
+ XmlObject xml;
+ try {
+ xml = XmlObject.Factory.parse(omElement.getXMLStreamReader());
+ } catch (XmlException e) {
+ throw new ScriptException(e);
+ }
+ Object wrappedXML = cx.getWrapFactory().wrap(cx, this.scope, xml, XmlObject.class);
+ Object obj = cx.newObject(this.scope, "XML", new Object[]{wrappedXML});
+ return obj;
+ } finally {
+ Context.exit();
+ }
+ }
+}
diff --git a/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java b/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
index c4d60d1..1217621 100644
--- a/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
+++ b/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
@@ -66,6 +66,11 @@
private static final String MC_VAR_NAME = "mc";
/**
+ * Name of the JavaScript language
+ */
+ private static final String JAVA_SCRIPT = "js";
+
+ /**
* The registry entry key for a script loaded from the registry
* Handle both static and dynamic(Xpath) Keys
*/
@@ -428,7 +433,12 @@
if (scriptEngine == null) {
handleException("No script engine found for language: " + language);
}
- xmlHelper = XMLHelper.getArgHelper(scriptEngine);
+ //Invoking a custom Helper class since there is an api change in rhino17 for js
+ if (language.equalsIgnoreCase(JAVA_SCRIPT)) {
+ xmlHelper = new JavaScriptXmlHelper();
+ } else {
+ xmlHelper = XMLHelper.getArgHelper(scriptEngine);
+ }
this.multiThreadedEngine = scriptEngine.getFactory().getParameter("THREADING") != null;
log.debug("Script mediator for language : " + language +
diff --git a/java/modules/integration/pom.xml b/java/modules/integration/pom.xml
index 814e3f7..91e0343 100644
--- a/java/modules/integration/pom.xml
+++ b/java/modules/integration/pom.xml
@@ -394,8 +394,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>rhino</groupId>
- <artifactId>js</artifactId>
+ <groupId>org.mozilla</groupId>
+ <artifactId>rhino</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/java/pom.xml b/java/pom.xml
index c1258d6..edc9915 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -834,8 +834,8 @@
<version>${bsf.version}</version>
</dependency>
<dependency>
- <groupId>rhino</groupId>
- <artifactId>js</artifactId>
+ <groupId>org.mozilla</groupId>
+ <artifactId>rhino</artifactId>
<version>${rhino.version}</version>
</dependency>
@@ -1114,7 +1114,7 @@
<bsf.version>3.0</bsf.version>
<groovy.version>1.1-rc-1</groovy.version>
<spring.version>1.2.8</spring.version>
- <rhino.version>1.6R5</rhino.version>
+ <rhino.version>1.7R5</rhino.version>
<activation.version>1.1</activation.version>
<!-- Maven Tools -->