You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by as...@apache.org on 2007/03/17 17:18:47 UTC
svn commit: r519363 [10/16] - in /webservices/synapse/trunk/java:
modules/core/ modules/core/src/main/java/org/apache/synapse/
modules/core/src/main/java/org/apache/synapse/config/
modules/core/src/main/java/org/apache/synapse/config/xml/ modules/core/...
Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java Sat Mar 17 09:18:32 2007
@@ -1,309 +1,309 @@
-/*
- * 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.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.Constants;
-import org.apache.synapse.mediators.bsf.convertors.*;
-import org.apache.synapse.config.Entry;
-import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.synapse.mediators.bsf.convertors.DefaultOMElementConvertor;
-import org.apache.synapse.mediators.bsf.convertors.OMElementConvertor;
-import org.apache.synapse.mediators.bsf.convertors.RBOMElementConvertor;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.Vector;
-import java.util.Arrays;
-
-/**
- * A Synapse mediator that calls a function in any scripting language supported by the BSF.
- * The ScriptMediator supports scripts specified in-line or those loaded through a registry
- * <p/>
- * <pre>
- * <script [key="entry-key"]
- * [function="script-function-name"] language="javascript|groovy|ruby">
- * (text | xml)?
- * </script>
- * </pre>
- * <p/>
- * <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 {
-
- private static final Log log = LogFactory.getLog(ScriptMediator.class);
- private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
-
- /** The name of the variable made available to the scripting language to access the message */
- private static final String MC_VAR_NAME = "mc";
- private static final Vector PARAM_NAMES = new Vector(Arrays.asList(new String[]{MC_VAR_NAME}));
-
- /** The registry entry key for a script loaded from the registry */
- private String key;
- /** The language of the script code */
- private String language;
- /** The optional name of the function to be invoked, defaults to mediate */
- private String function = "mediate";
- /** The source code of the script */
- private String scriptSourceCode;
- /** The BSF Manager */
- private BSFManager bsfManager;
- /** The BSF engine created to process each message through the script */
- private BSFEngine bsfEngine;
- /** A converter to get the code for the scripting language from XML */
- private OMElementConvertor convertor;
-
- /**
- * Create a script mediator for the given language and given script source
- * @param language the BSF language
- * @param scriptSourceCode the source code of the script
- */
- public ScriptMediator(String language, String scriptSourceCode) {
- this.language = language;
- this.scriptSourceCode = scriptSourceCode;
- }
-
- /**
- * Create a script mediator for the given language and given script entry key and function
- * @param language the BSF language
- * @param key the registry entry key to load the script
- * @param function the function to be invoked
- */
- public ScriptMediator(String language, String key, String function) {
- this.language = language;
- this.key = key;
- this.function = function;
- }
-
- /**
- * Perform Script mediation
- * @param synCtx the Synapse message context
- * @return true for inline mediation and the boolean result (if any) for other scripts that
- * specify a function that returns a boolean value
- */
- public boolean mediate(MessageContext synCtx) {
-
- log.debug("Script Mediator - mediate() # Language : " + language +
- (key == null ? " inline script" : " script with key : " + key) +
- " function : " + function);
-
- boolean shouldTrace = shouldTrace(synCtx.getTracingState());
- if (shouldTrace) {
- trace.trace("Start : Script mediator # Language : " + language +
- (key == null ? " inline script" : " script with key : " + key) +
- " function : " + function);
- }
-
- boolean returnValue = false;
- if (key != null) {
- returnValue = mediateWithExternalScript(synCtx);
- } else {
- returnValue = mediateForInlineScript(synCtx);
- }
-
- if (shouldTrace && returnValue) {
- trace.trace("End : Script mediator");
- }
-
- return returnValue;
- }
-
- /**
- * Mediation implementation when the script to be executed should be loaded from the registry
- * @param synCtx the message context
- * @return script result
- */
- private boolean mediateWithExternalScript(MessageContext synCtx) {
-
- try {
- Entry entry = synCtx.getConfiguration().getEntryDefinition(key);
-
- // if the key refers to a dynamic script
- if (entry != null && entry.isDynamic()) {
- if (!entry.isCached() || entry.isExpired()) {
- scriptSourceCode = ((OMElement) (synCtx.getEntry(key))).getText();
- loadBSFEngine(synCtx, false);
- }
- // if the key is static, we will load the script and create a BSFEngine only once
- } else {
- // load script if not already loaded
- if (scriptSourceCode == null) {
- Object o = synCtx.getEntry(key);
- if (o instanceof OMElement) {
- scriptSourceCode = ((OMElement) (o)).getText();
- } else if (o instanceof String) {
- scriptSourceCode = (String) o;
- }
- }
- // load BSFEngine if not already loaded
- if (bsfEngine == null) {
- loadBSFEngine(synCtx, false);
- }
- }
-
- if (shouldTrace(synCtx.getTracingState())) {
- trace.trace("Invoking script for current message : " + synCtx);
- }
-
- // prepare engine for the execution of the script
- bsfEngine.exec(language, 0, 0, scriptSourceCode);
- // calling the function with script message context as a parameter
- Object[] args = new Object[]{ new ScriptMessageContext(synCtx, convertor) };
- Object response = bsfEngine.call(null, function, args);
-
- if (shouldTrace(synCtx.getTracingState())) {
- trace.trace("Result message after execution of script : " + synCtx);
- }
-
- if (response != null && response instanceof Boolean) {
- return ((Boolean) response).booleanValue();
- }
- return true;
-
- } catch (BSFException e) {
- handleException("Error invoking " + language +
- " script : " + key + " function : " + function, e);
- }
- return false;
- }
-
- /**
- * Perform mediation with static inline script of the given scripting language
- * @param synCtx message context
- * @return true, or the script return value
- */
- private boolean mediateForInlineScript(MessageContext synCtx) {
-
- try {
- if (bsfEngine == null) {
- loadBSFEngine(synCtx, true);
- }
-
- if (shouldTrace(synCtx.getTracingState())) {
- trace.trace("Invoking inline script for current message : " + synCtx);
- }
-
- ScriptMessageContext scriptMC = new ScriptMessageContext(synCtx, convertor);
- Vector paramValues = new Vector();
- paramValues.add(scriptMC);
-
- // applying the source to the specified engine with parameter names and values
- Object response = bsfEngine.apply(
- language, 0, 0, scriptSourceCode, PARAM_NAMES, paramValues);
-
- if (shouldTrace(synCtx.getTracingState())) {
- trace.trace("Result message after execution of script : " + synCtx);
- }
-
- if (response != null && response instanceof Boolean) {
- return ((Boolean) response).booleanValue();
- }
- return true;
-
- } catch (BSFException e) {
- handleException("Error executing inline " + language + " script", e);
- }
- return false;
- }
-
- /**
- * Load the BSFEngine through the BSFManager. BSF engines should be cached within this
- * mediator.
- * TODO check if the constructed engine thread safe?
- * TODO i.e. if a script defines var X = $1 and then reads it back, and if the
- * TODO first thread sets X to 10, and is context switched and second thread sets X to 20
- * TODO and completes. Now when the first thread comes back, will it read 10 or 20?
- * TODO hopefully 10
- * @param synCtx the message context
- * @param isInline true for inline scripts
- */
- public synchronized void loadBSFEngine(MessageContext synCtx, boolean isInline) {
-
- if (bsfManager == null) {
- bsfManager = new BSFManager();
- convertor = getOMElementConvertor();
- }
-
- try {
- if (isInline) {
- ScriptMessageContext scriptMC = new ScriptMessageContext(synCtx, convertor);
- bsfManager.declareBean(MC_VAR_NAME, scriptMC, ScriptMessageContext.class);
- bsfEngine = bsfManager.loadScriptingEngine(language);
- } else {
- bsfEngine = bsfManager.loadScriptingEngine(language);
- }
-
- } catch (BSFException e) {
- handleException("Error loading BSF Engine for : " + language +
- (isInline ? " for inline mediation" : " for external script execution"), e);
- }
-
- convertor.setEngine(bsfEngine);
- }
-
- /**
- * Return the appropriate OMElementConverter for the language of the script
- * @return a suitable OMElementConverter for the scripting language
- */
- public OMElementConvertor getOMElementConvertor() {
- OMElementConvertor oc = null;
-
- if ("javascript".equals(language)) {
- return new JSOMElementConvertor();
- } else if ("ruby".equals(language)) {
- return new RBOMElementConvertor();
- } else if ("groovy".equals(language)) {
- return new GROOVYOMElementConvertor();
- } else {
- return new DefaultOMElementConvertor();
- }
- }
-
- public String getLanguage() {
- return language;
- }
-
- public String getKey() {
- return key;
- }
-
- public String getFunction() {
- return function;
- }
-
- public String getScriptSrc() {
- return scriptSourceCode;
- }
-
- private void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
-
-}
+/*
+ * 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.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.Constants;
+import org.apache.synapse.mediators.bsf.convertors.*;
+import org.apache.synapse.config.Entry;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.bsf.convertors.DefaultOMElementConvertor;
+import org.apache.synapse.mediators.bsf.convertors.OMElementConvertor;
+import org.apache.synapse.mediators.bsf.convertors.RBOMElementConvertor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Vector;
+import java.util.Arrays;
+
+/**
+ * A Synapse mediator that calls a function in any scripting language supported by the BSF.
+ * The ScriptMediator supports scripts specified in-line or those loaded through a registry
+ * <p/>
+ * <pre>
+ * <script [key="entry-key"]
+ * [function="script-function-name"] language="javascript|groovy|ruby">
+ * (text | xml)?
+ * </script>
+ * </pre>
+ * <p/>
+ * <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 {
+
+ private static final Log log = LogFactory.getLog(ScriptMediator.class);
+ private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
+
+ /** The name of the variable made available to the scripting language to access the message */
+ private static final String MC_VAR_NAME = "mc";
+ private static final Vector PARAM_NAMES = new Vector(Arrays.asList(new String[]{MC_VAR_NAME}));
+
+ /** The registry entry key for a script loaded from the registry */
+ private String key;
+ /** The language of the script code */
+ private String language;
+ /** The optional name of the function to be invoked, defaults to mediate */
+ private String function = "mediate";
+ /** The source code of the script */
+ private String scriptSourceCode;
+ /** The BSF Manager */
+ private BSFManager bsfManager;
+ /** The BSF engine created to process each message through the script */
+ private BSFEngine bsfEngine;
+ /** A converter to get the code for the scripting language from XML */
+ private OMElementConvertor convertor;
+
+ /**
+ * Create a script mediator for the given language and given script source
+ * @param language the BSF language
+ * @param scriptSourceCode the source code of the script
+ */
+ public ScriptMediator(String language, String scriptSourceCode) {
+ this.language = language;
+ this.scriptSourceCode = scriptSourceCode;
+ }
+
+ /**
+ * Create a script mediator for the given language and given script entry key and function
+ * @param language the BSF language
+ * @param key the registry entry key to load the script
+ * @param function the function to be invoked
+ */
+ public ScriptMediator(String language, String key, String function) {
+ this.language = language;
+ this.key = key;
+ this.function = function;
+ }
+
+ /**
+ * Perform Script mediation
+ * @param synCtx the Synapse message context
+ * @return true for inline mediation and the boolean result (if any) for other scripts that
+ * specify a function that returns a boolean value
+ */
+ public boolean mediate(MessageContext synCtx) {
+
+ log.debug("Script Mediator - mediate() # Language : " + language +
+ (key == null ? " inline script" : " script with key : " + key) +
+ " function : " + function);
+
+ boolean shouldTrace = shouldTrace(synCtx.getTracingState());
+ if (shouldTrace) {
+ trace.trace("Start : Script mediator # Language : " + language +
+ (key == null ? " inline script" : " script with key : " + key) +
+ " function : " + function);
+ }
+
+ boolean returnValue = false;
+ if (key != null) {
+ returnValue = mediateWithExternalScript(synCtx);
+ } else {
+ returnValue = mediateForInlineScript(synCtx);
+ }
+
+ if (shouldTrace && returnValue) {
+ trace.trace("End : Script mediator");
+ }
+
+ return returnValue;
+ }
+
+ /**
+ * Mediation implementation when the script to be executed should be loaded from the registry
+ * @param synCtx the message context
+ * @return script result
+ */
+ private boolean mediateWithExternalScript(MessageContext synCtx) {
+
+ try {
+ Entry entry = synCtx.getConfiguration().getEntryDefinition(key);
+
+ // if the key refers to a dynamic script
+ if (entry != null && entry.isDynamic()) {
+ if (!entry.isCached() || entry.isExpired()) {
+ scriptSourceCode = ((OMElement) (synCtx.getEntry(key))).getText();
+ loadBSFEngine(synCtx, false);
+ }
+ // if the key is static, we will load the script and create a BSFEngine only once
+ } else {
+ // load script if not already loaded
+ if (scriptSourceCode == null) {
+ Object o = synCtx.getEntry(key);
+ if (o instanceof OMElement) {
+ scriptSourceCode = ((OMElement) (o)).getText();
+ } else if (o instanceof String) {
+ scriptSourceCode = (String) o;
+ }
+ }
+ // load BSFEngine if not already loaded
+ if (bsfEngine == null) {
+ loadBSFEngine(synCtx, false);
+ }
+ }
+
+ if (shouldTrace(synCtx.getTracingState())) {
+ trace.trace("Invoking script for current message : " + synCtx);
+ }
+
+ // prepare engine for the execution of the script
+ bsfEngine.exec(language, 0, 0, scriptSourceCode);
+ // calling the function with script message context as a parameter
+ Object[] args = new Object[]{ new ScriptMessageContext(synCtx, convertor) };
+ Object response = bsfEngine.call(null, function, args);
+
+ if (shouldTrace(synCtx.getTracingState())) {
+ trace.trace("Result message after execution of script : " + synCtx);
+ }
+
+ if (response != null && response instanceof Boolean) {
+ return ((Boolean) response).booleanValue();
+ }
+ return true;
+
+ } catch (BSFException e) {
+ handleException("Error invoking " + language +
+ " script : " + key + " function : " + function, e);
+ }
+ return false;
+ }
+
+ /**
+ * Perform mediation with static inline script of the given scripting language
+ * @param synCtx message context
+ * @return true, or the script return value
+ */
+ private boolean mediateForInlineScript(MessageContext synCtx) {
+
+ try {
+ if (bsfEngine == null) {
+ loadBSFEngine(synCtx, true);
+ }
+
+ if (shouldTrace(synCtx.getTracingState())) {
+ trace.trace("Invoking inline script for current message : " + synCtx);
+ }
+
+ ScriptMessageContext scriptMC = new ScriptMessageContext(synCtx, convertor);
+ Vector paramValues = new Vector();
+ paramValues.add(scriptMC);
+
+ // applying the source to the specified engine with parameter names and values
+ Object response = bsfEngine.apply(
+ language, 0, 0, scriptSourceCode, PARAM_NAMES, paramValues);
+
+ if (shouldTrace(synCtx.getTracingState())) {
+ trace.trace("Result message after execution of script : " + synCtx);
+ }
+
+ if (response != null && response instanceof Boolean) {
+ return ((Boolean) response).booleanValue();
+ }
+ return true;
+
+ } catch (BSFException e) {
+ handleException("Error executing inline " + language + " script", e);
+ }
+ return false;
+ }
+
+ /**
+ * Load the BSFEngine through the BSFManager. BSF engines should be cached within this
+ * mediator.
+ * TODO check if the constructed engine thread safe?
+ * TODO i.e. if a script defines var X = $1 and then reads it back, and if the
+ * TODO first thread sets X to 10, and is context switched and second thread sets X to 20
+ * TODO and completes. Now when the first thread comes back, will it read 10 or 20?
+ * TODO hopefully 10
+ * @param synCtx the message context
+ * @param isInline true for inline scripts
+ */
+ public synchronized void loadBSFEngine(MessageContext synCtx, boolean isInline) {
+
+ if (bsfManager == null) {
+ bsfManager = new BSFManager();
+ convertor = getOMElementConvertor();
+ }
+
+ try {
+ if (isInline) {
+ ScriptMessageContext scriptMC = new ScriptMessageContext(synCtx, convertor);
+ bsfManager.declareBean(MC_VAR_NAME, scriptMC, ScriptMessageContext.class);
+ bsfEngine = bsfManager.loadScriptingEngine(language);
+ } else {
+ bsfEngine = bsfManager.loadScriptingEngine(language);
+ }
+
+ } catch (BSFException e) {
+ handleException("Error loading BSF Engine for : " + language +
+ (isInline ? " for inline mediation" : " for external script execution"), e);
+ }
+
+ convertor.setEngine(bsfEngine);
+ }
+
+ /**
+ * Return the appropriate OMElementConverter for the language of the script
+ * @return a suitable OMElementConverter for the scripting language
+ */
+ public OMElementConvertor getOMElementConvertor() {
+ OMElementConvertor oc = null;
+
+ if ("javascript".equals(language)) {
+ return new JSOMElementConvertor();
+ } else if ("ruby".equals(language)) {
+ return new RBOMElementConvertor();
+ } else if ("groovy".equals(language)) {
+ return new GROOVYOMElementConvertor();
+ } else {
+ return new DefaultOMElementConvertor();
+ }
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getFunction() {
+ return function;
+ }
+
+ public String getScriptSrc() {
+ return scriptSourceCode;
+ }
+
+ private void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+
+}
Propchange: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java Sat Mar 17 09:18:32 2007
@@ -1,80 +1,80 @@
-/*
- * 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 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.AbstractMediatorFactory;
-
-/**
- * Creates an instance of a Script mediator for inline or external script mediation for BSF
- * scripting languages.
- *
- * * <pre>
- * <script [key="entry-key"]
- * [function="script-function-name"] language="javascript|groovy|ruby">
- * (text | xml)?
- * </script>
- * </pre>
- *
- * 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 extends AbstractMediatorFactory {
-
- private static final QName TAG_NAME = new QName(Constants.SYNAPSE_NAMESPACE, "script");
-
- public Mediator createMediator(OMElement elem) {
-
- ScriptMediator mediator;
- OMAttribute keyAtt = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "key"));
- OMAttribute langAtt = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "language"));
- OMAttribute funcAtt = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "function"));
-
- if (langAtt != null) {
- if (keyAtt != null) {
- String functionName = (funcAtt == null ? "mediate" : funcAtt.getAttributeValue());
- mediator = new ScriptMediator(
- langAtt.getAttributeValue(), keyAtt.getAttributeValue(), functionName);
- } else {
- mediator = new ScriptMediator(langAtt.getAttributeValue(), elem.getText());
- }
- } else {
- throw new SynapseException("The 'language' attribute is required for a script mediator");
- }
-
- initMediator(mediator, elem);
- return mediator;
- }
-
- public QName getTagQName() {
- return TAG_NAME;
- }
-}
+/*
+ * 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 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.AbstractMediatorFactory;
+
+/**
+ * Creates an instance of a Script mediator for inline or external script mediation for BSF
+ * scripting languages.
+ *
+ * * <pre>
+ * <script [key="entry-key"]
+ * [function="script-function-name"] language="javascript|groovy|ruby">
+ * (text | xml)?
+ * </script>
+ * </pre>
+ *
+ * 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 extends AbstractMediatorFactory {
+
+ private static final QName TAG_NAME = new QName(Constants.SYNAPSE_NAMESPACE, "script");
+
+ public Mediator createMediator(OMElement elem) {
+
+ ScriptMediator mediator;
+ OMAttribute keyAtt = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "key"));
+ OMAttribute langAtt = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "language"));
+ OMAttribute funcAtt = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "function"));
+
+ if (langAtt != null) {
+ if (keyAtt != null) {
+ String functionName = (funcAtt == null ? "mediate" : funcAtt.getAttributeValue());
+ mediator = new ScriptMediator(
+ langAtt.getAttributeValue(), keyAtt.getAttributeValue(), functionName);
+ } else {
+ mediator = new ScriptMediator(langAtt.getAttributeValue(), elem.getText());
+ }
+ } else {
+ throw new SynapseException("The 'language' attribute is required for a script mediator");
+ }
+
+ initMediator(mediator, elem);
+ return mediator;
+ }
+
+ public QName getTagQName() {
+ return TAG_NAME;
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorSerializer.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorSerializer.java Sat Mar 17 09:18:32 2007
@@ -1,79 +1,79 @@
-/*
- * 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.synapse.config.xml.AbstractMediatorSerializer;
-import org.apache.synapse.Mediator;
-import org.apache.synapse.SynapseException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.llom.OMTextImpl;
-
-import javax.xml.stream.XMLStreamConstants;
-
-/**
- * Serializer for a script mediator
- * @see org.apache.synapse.mediators.bsf.ScriptMediatorFactory
- */
-public class ScriptMediatorSerializer extends AbstractMediatorSerializer {
-
- private static final Log log = LogFactory.getLog(ScriptMediatorSerializer.class);
-
- public OMElement serializeMediator(OMElement parent, Mediator m) {
- if (!(m instanceof ScriptMediator) ) {
- handleException("Unsupported mediator passed in for serialization : " + m.getType());
- }
-
- ScriptMediator scriptMediator = (ScriptMediator) m;
- OMElement script = fac.createOMElement("script", synNS);
-
- String language = scriptMediator.getLanguage();
- String key = scriptMediator.getKey();
- String function = scriptMediator.getFunction();
-
- if (key != null) {
- script.addAttribute(fac.createOMAttribute("language", nullNS, language));
- script.addAttribute(fac.createOMAttribute("key", nullNS, key));
- if (!function.equals("mediate")) {
- script.addAttribute(fac.createOMAttribute("function", nullNS, function));
- }
- } else {
- script.addAttribute(fac.createOMAttribute("language", nullNS, language));
- OMTextImpl textData = (OMTextImpl) fac.createOMText(scriptMediator.getScriptSrc().trim());
- textData.setType(XMLStreamConstants.CDATA);
- script.addChild(textData);
- }
-
- finalizeSerialization(script, scriptMediator);
- if (parent != null) {
- parent.addChild(script);
- }
- return script;
- }
-
- public String getMediatorClassName() {
- return ScriptMediator.class.getName();
- }
-
- private void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-}
+/*
+ * 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.synapse.config.xml.AbstractMediatorSerializer;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.llom.OMTextImpl;
+
+import javax.xml.stream.XMLStreamConstants;
+
+/**
+ * Serializer for a script mediator
+ * @see org.apache.synapse.mediators.bsf.ScriptMediatorFactory
+ */
+public class ScriptMediatorSerializer extends AbstractMediatorSerializer {
+
+ private static final Log log = LogFactory.getLog(ScriptMediatorSerializer.class);
+
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+ if (!(m instanceof ScriptMediator) ) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ ScriptMediator scriptMediator = (ScriptMediator) m;
+ OMElement script = fac.createOMElement("script", synNS);
+
+ String language = scriptMediator.getLanguage();
+ String key = scriptMediator.getKey();
+ String function = scriptMediator.getFunction();
+
+ if (key != null) {
+ script.addAttribute(fac.createOMAttribute("language", nullNS, language));
+ script.addAttribute(fac.createOMAttribute("key", nullNS, key));
+ if (!function.equals("mediate")) {
+ script.addAttribute(fac.createOMAttribute("function", nullNS, function));
+ }
+ } else {
+ script.addAttribute(fac.createOMAttribute("language", nullNS, language));
+ OMTextImpl textData = (OMTextImpl) fac.createOMText(scriptMediator.getScriptSrc().trim());
+ textData.setType(XMLStreamConstants.CDATA);
+ script.addChild(textData);
+ }
+
+ finalizeSerialization(script, scriptMediator);
+ if (parent != null) {
+ parent.addChild(script);
+ }
+ return script;
+ }
+
+ public String getMediatorClassName() {
+ return ScriptMediator.class.getName();
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediatorSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMessageContext.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMessageContext.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMessageContext.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMessageContext.java Sat Mar 17 09:18:32 2007
@@ -1,286 +1,286 @@
-/*
- * 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 java.util.Set;
-import java.util.Stack;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.om.OMElement;
-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.Mediator;
-import org.apache.synapse.FaultHandler;
-import org.apache.synapse.config.SynapseConfiguration;
-import org.apache.synapse.core.SynapseEnvironment;
-import org.apache.synapse.mediators.bsf.convertors.OMElementConvertor;
-import org.apache.synapse.endpoints.Endpoint;
-
-/**
- * ScriptMessageContext decorates the Synapse MessageContext adding methods to use the
- * message payload XML in a way natural to the scripting languageS
- */
-public class ScriptMessageContext implements MessageContext {
-
- /** The actual Synapse message context reference */
- private MessageContext mc;
- /** The OMElement to scripting language object converter for the selected language */
- 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
- *
- */
-
- public void setPayloadXML(Object payload) {
- OMElement firstChild = mc.getEnvelope().getBody().getFirstElement();
- firstChild.insertSiblingAfter(convertor.fromScript(payload));
- firstChild.detach();
- }
-
- /**
- * Get the XML representation of the complete SOAP envelope
- * @return return an object that represents the payload in the current scripting language
- */
- 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.getProperty(key);
- }
-
- public Object getEntry(String key) {
- return mc.getEntry(key);
- }
-
- public void setProperty(String key, Object value) {
- mc.setProperty(key, value);
- }
-
- public Set getPropertyKeySet() {
- return mc.getPropertyKeySet();
- }
-
- public Mediator getMainSequence() {
- return mc.getMainSequence();
- }
-
- public Mediator getFaultSequence() {
- return mc.getFaultSequence();
- }
-
- public Mediator getSequence(String key) {
- return mc.getSequence(key);
- }
-
- public Endpoint getEndpoint(String key) {
- return mc.getEndpoint(key);
- }
-
- 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 setWSAMessageID(String messageID) {
- mc.setWSAMessageID(messageID);
- }
-
- public String getWSAMessageID() {
- return mc.getWSAMessageID();
- }
-
- public boolean isDoingMTOM() {
- return mc.isDoingMTOM();
- }
-
- public boolean isDoingSWA() {
- return mc.isDoingSWA();
- }
-
- public void setDoingMTOM(boolean b) {
- mc.setDoingMTOM(b);
- }
-
- public void setDoingSWA(boolean b) {
- mc.setDoingSWA(b);
- }
-
- public boolean isDoingPOX() {
- return mc.isDoingPOX();
- }
-
- public void setDoingPOX(boolean b) {
- mc.setDoingPOX(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();
- }
-
- public int getTracingState() {
- return mc.getTracingState();
- }
-
- public void setTracingState(int tracingState) {
- mc.setTracingState(tracingState);
- }
-
- public Stack getFaultStack() {
- return mc.getFaultStack();
- }
-
- public void pushFaultHandler(FaultHandler fault) {
- mc.pushFaultHandler(fault);
- }
-}
+/*
+ * 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 java.util.Set;
+import java.util.Stack;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.om.OMElement;
+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.Mediator;
+import org.apache.synapse.FaultHandler;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.mediators.bsf.convertors.OMElementConvertor;
+import org.apache.synapse.endpoints.Endpoint;
+
+/**
+ * ScriptMessageContext decorates the Synapse MessageContext adding methods to use the
+ * message payload XML in a way natural to the scripting languageS
+ */
+public class ScriptMessageContext implements MessageContext {
+
+ /** The actual Synapse message context reference */
+ private MessageContext mc;
+ /** The OMElement to scripting language object converter for the selected language */
+ 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
+ *
+ */
+
+ public void setPayloadXML(Object payload) {
+ OMElement firstChild = mc.getEnvelope().getBody().getFirstElement();
+ firstChild.insertSiblingAfter(convertor.fromScript(payload));
+ firstChild.detach();
+ }
+
+ /**
+ * Get the XML representation of the complete SOAP envelope
+ * @return return an object that represents the payload in the current scripting language
+ */
+ 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.getProperty(key);
+ }
+
+ public Object getEntry(String key) {
+ return mc.getEntry(key);
+ }
+
+ public void setProperty(String key, Object value) {
+ mc.setProperty(key, value);
+ }
+
+ public Set getPropertyKeySet() {
+ return mc.getPropertyKeySet();
+ }
+
+ public Mediator getMainSequence() {
+ return mc.getMainSequence();
+ }
+
+ public Mediator getFaultSequence() {
+ return mc.getFaultSequence();
+ }
+
+ public Mediator getSequence(String key) {
+ return mc.getSequence(key);
+ }
+
+ public Endpoint getEndpoint(String key) {
+ return mc.getEndpoint(key);
+ }
+
+ 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 setWSAMessageID(String messageID) {
+ mc.setWSAMessageID(messageID);
+ }
+
+ public String getWSAMessageID() {
+ return mc.getWSAMessageID();
+ }
+
+ public boolean isDoingMTOM() {
+ return mc.isDoingMTOM();
+ }
+
+ public boolean isDoingSWA() {
+ return mc.isDoingSWA();
+ }
+
+ public void setDoingMTOM(boolean b) {
+ mc.setDoingMTOM(b);
+ }
+
+ public void setDoingSWA(boolean b) {
+ mc.setDoingSWA(b);
+ }
+
+ public boolean isDoingPOX() {
+ return mc.isDoingPOX();
+ }
+
+ public void setDoingPOX(boolean b) {
+ mc.setDoingPOX(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();
+ }
+
+ public int getTracingState() {
+ return mc.getTracingState();
+ }
+
+ public void setTracingState(int tracingState) {
+ mc.setTracingState(tracingState);
+ }
+
+ public Stack getFaultStack() {
+ return mc.getFaultStack();
+ }
+
+ public void pushFaultHandler(FaultHandler fault) {
+ mc.pushFaultHandler(fault);
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMessageContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java Sat Mar 17 09:18:32 2007
@@ -1,68 +1,68 @@
-/*
- * 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.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;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * The DefaultOMElementConvertor converts between OMElements and Strings
- */
-public class DefaultOMElementConvertor implements OMElementConvertor {
-
- private static final Log log = LogFactory.getLog(DefaultOMElementConvertor.class);
-
- public OMElement fromScript(Object o) {
- if (o == null) {
- handleException("Cannot convert null JavaScript Object to an OMElement");
- }
-
- try {
- StAXOMBuilder builder = new StAXOMBuilder(
- new ByteArrayInputStream(o.toString().getBytes()));
- return builder.getDocumentElement();
-
- } catch (XMLStreamException e) {
- handleException("Error converting Object of type : " + o.getClass().getName() + " to String");
- }
- return null;
- }
-
- public Object toScript(OMElement omElement) {
- return omElement.toString();
- }
-
- public void setEngine(BSFEngine e) {
- }
-
- private void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
-}
+/*
+ * 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.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;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The DefaultOMElementConvertor converts between OMElements and Strings
+ */
+public class DefaultOMElementConvertor implements OMElementConvertor {
+
+ private static final Log log = LogFactory.getLog(DefaultOMElementConvertor.class);
+
+ public OMElement fromScript(Object o) {
+ if (o == null) {
+ handleException("Cannot convert null JavaScript Object to an OMElement");
+ }
+
+ try {
+ StAXOMBuilder builder = new StAXOMBuilder(
+ new ByteArrayInputStream(o.toString().getBytes()));
+ return builder.getDocumentElement();
+
+ } catch (XMLStreamException e) {
+ handleException("Error converting Object of type : " + o.getClass().getName() + " to String");
+ }
+ return null;
+ }
+
+ public Object toScript(OMElement omElement) {
+ return omElement.toString();
+ }
+
+ public void setEngine(BSFEngine e) {
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+}
Propchange: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/DefaultOMElementConvertor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java Sat Mar 17 09:18:32 2007
@@ -1,138 +1,138 @@
-/*
- * 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.convertors;
-
-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.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.Log;
-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 OMElements and JavaScript E4X XML objects
- */
-public class JSOMElementConvertor extends DefaultOMElementConvertor {
-
- private static final Log log = LogFactory.getLog(JSOMElementConvertor.class);
-
- private static boolean axiomJavaScript = false;
- static {
- try {
- Class.forName("org.mozilla.javascript.xmlimpl.AxiomNode");
- axiomJavaScript = true;
- } catch (ClassNotFoundException ignore) {}
- }
-
- protected Scriptable scope;
-
- public JSOMElementConvertor() {
- Context cx = Context.enter();
- try {
- this.scope = cx.initStandardObjects();
- } finally {
- Context.exit();
- }
- }
-
- public Object toScript(OMElement o) {
- if (axiomJavaScript) {
- Context cx = Context.enter();
- try {
- return cx.newObject(scope, "XML", new Object[]{o});
-
- } finally {
- Context.exit();
- }
-
- } else {
- XmlObject xml = null;
- try {
- xml = XmlObject.Factory.parse(o.getXMLStreamReader());
- } catch (Exception e) {
- handleException("Error converting OMElement to a JavaSript XmlObject", e);
- }
-
- Context cx = Context.enter();
- try {
-
- Object wrappedXML = cx.getWrapFactory().wrap(cx, scope, xml, XmlObject.class);
- return cx.newObject(scope, "XML", new Object[]{wrappedXML});
-
- } finally {
- Context.exit();
- }
- }
- }
-
- public OMElement fromScript(Object o) {
-
- if (o == null) {
- handleException("Cannot convert null JavaScript Object to an OMElement");
- }
-
- if (!(o instanceof XMLObject)) {
- log.debug("Converting Object of type : " + o.getClass().getName() + " to an OMElement");
- return super.fromScript(o);
- }
-
- if (axiomJavaScript) {
- return (OMElement) ScriptableObject.callMethod(
- (Scriptable) o, "getXmlObject", new Object[0]);
-
- } else {
- // 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((XMLObject)jsXML, "getXmlObject", new Object[0]);
-
- XmlObject xmlObject = (XmlObject) wrapper.unwrap();
-
- try {
- StAXOMBuilder builder = new StAXOMBuilder(xmlObject.newInputStream());
- return builder.getDocumentElement();
-
- } catch (XMLStreamException e) {
- handleException("Error converting JavaScipt object of type : "
- + o.getClass().getName() + " to an OMElement", e);
- }
- return null;
- }
- }
-
- private void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
-
- private void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
-}
+/*
+ * 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.convertors;
+
+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.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+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 OMElements and JavaScript E4X XML objects
+ */
+public class JSOMElementConvertor extends DefaultOMElementConvertor {
+
+ private static final Log log = LogFactory.getLog(JSOMElementConvertor.class);
+
+ private static boolean axiomJavaScript = false;
+ static {
+ try {
+ Class.forName("org.mozilla.javascript.xmlimpl.AxiomNode");
+ axiomJavaScript = true;
+ } catch (ClassNotFoundException ignore) {}
+ }
+
+ protected Scriptable scope;
+
+ public JSOMElementConvertor() {
+ Context cx = Context.enter();
+ try {
+ this.scope = cx.initStandardObjects();
+ } finally {
+ Context.exit();
+ }
+ }
+
+ public Object toScript(OMElement o) {
+ if (axiomJavaScript) {
+ Context cx = Context.enter();
+ try {
+ return cx.newObject(scope, "XML", new Object[]{o});
+
+ } finally {
+ Context.exit();
+ }
+
+ } else {
+ XmlObject xml = null;
+ try {
+ xml = XmlObject.Factory.parse(o.getXMLStreamReader());
+ } catch (Exception e) {
+ handleException("Error converting OMElement to a JavaSript XmlObject", e);
+ }
+
+ Context cx = Context.enter();
+ try {
+
+ Object wrappedXML = cx.getWrapFactory().wrap(cx, scope, xml, XmlObject.class);
+ return cx.newObject(scope, "XML", new Object[]{wrappedXML});
+
+ } finally {
+ Context.exit();
+ }
+ }
+ }
+
+ public OMElement fromScript(Object o) {
+
+ if (o == null) {
+ handleException("Cannot convert null JavaScript Object to an OMElement");
+ }
+
+ if (!(o instanceof XMLObject)) {
+ log.debug("Converting Object of type : " + o.getClass().getName() + " to an OMElement");
+ return super.fromScript(o);
+ }
+
+ if (axiomJavaScript) {
+ return (OMElement) ScriptableObject.callMethod(
+ (Scriptable) o, "getXmlObject", new Object[0]);
+
+ } else {
+ // 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((XMLObject)jsXML, "getXmlObject", new Object[0]);
+
+ XmlObject xmlObject = (XmlObject) wrapper.unwrap();
+
+ try {
+ StAXOMBuilder builder = new StAXOMBuilder(xmlObject.newInputStream());
+ return builder.getDocumentElement();
+
+ } catch (XMLStreamException e) {
+ handleException("Error converting JavaScipt object of type : "
+ + o.getClass().getName() + " to an OMElement", e);
+ }
+ return null;
+ }
+ }
+
+ private void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+}
Propchange: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/JSOMElementConvertor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java Sat Mar 17 09:18:32 2007
@@ -1,46 +1,46 @@
-/*
- * 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.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 determined by the script language specified for
- * the mediator script. If a suitable convertor class is not found then a default convertor
- * is used which converts XML to a String representation.
- */
-public interface OMElementConvertor {
-
- /** Set a reference to the BSFEngine to evalue the script */
- public void setEngine(BSFEngine e);
-
- /** Convert the OMElement to a suitable script object for the scripting language */
- public Object toScript(OMElement omElement);
-
- /** Convert a scripting language object into an OMElement */
- public OMElement fromScript(Object o);
-}
+/*
+ * 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.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 determined by the script language specified for
+ * the mediator script. If a suitable convertor class is not found then a default convertor
+ * is used which converts XML to a String representation.
+ */
+public interface OMElementConvertor {
+
+ /** Set a reference to the BSFEngine to evalue the script */
+ public void setEngine(BSFEngine e);
+
+ /** Convert the OMElement to a suitable script object for the scripting language */
+ public Object toScript(OMElement omElement);
+
+ /** Convert a scripting language object into an OMElement */
+ public OMElement fromScript(Object o);
+}
Propchange: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/OMElementConvertor.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java Sat Mar 17 09:18:32 2007
@@ -1,94 +1,94 @@
-/*
- * 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.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;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * 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 {
-
- private static final Log log = LogFactory.getLog(RBOMElementConvertor.class);
-
- protected BSFEngine bsfEngine;
-
- public Object toScript(OMElement omElement) {
-
- try {
- StringBuffer srcFragment = new StringBuffer("Document.new(<<EOF\n");
- srcFragment.append(omElement.toString());
- srcFragment.append("\nEOF\n");
- srcFragment.append(")");
-
- if (bsfEngine == null) {
- handleException("Cannot convert OMElement to Ruby Object as BSF Engine is not set");
- }
- return bsfEngine.eval("RBOMElementConvertor", 0, 0, srcFragment.toString());
-
- } catch (Exception e) {
- handleException("Error converting OMElement to Ruby Object", e);
- }
- return null;
- }
-
- public OMElement fromScript(Object o) {
- if (o == null) {
- handleException("Cannot convert null Ruby Object to an OMElement");
- }
-
- try {
- byte[] xmlBytes = o.toString().getBytes();
- StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(xmlBytes));
- return builder.getDocumentElement();
- } catch (Exception e) {
- handleException("Error converting Ruby object of type : " + o.getClass().getName() +
- " to an OMElement", e);
- }
- return null;
- }
-
- public void setEngine(BSFEngine e) {
- this.bsfEngine = e;
- }
-
- private void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
-
- private void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-}
+/*
+ * 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.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;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * 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 {
+
+ private static final Log log = LogFactory.getLog(RBOMElementConvertor.class);
+
+ protected BSFEngine bsfEngine;
+
+ public Object toScript(OMElement omElement) {
+
+ try {
+ StringBuffer srcFragment = new StringBuffer("Document.new(<<EOF\n");
+ srcFragment.append(omElement.toString());
+ srcFragment.append("\nEOF\n");
+ srcFragment.append(")");
+
+ if (bsfEngine == null) {
+ handleException("Cannot convert OMElement to Ruby Object as BSF Engine is not set");
+ }
+ return bsfEngine.eval("RBOMElementConvertor", 0, 0, srcFragment.toString());
+
+ } catch (Exception e) {
+ handleException("Error converting OMElement to Ruby Object", e);
+ }
+ return null;
+ }
+
+ public OMElement fromScript(Object o) {
+ if (o == null) {
+ handleException("Cannot convert null Ruby Object to an OMElement");
+ }
+
+ try {
+ byte[] xmlBytes = o.toString().getBytes();
+ StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(xmlBytes));
+ return builder.getDocumentElement();
+ } catch (Exception e) {
+ handleException("Error converting Ruby object of type : " + o.getClass().getName() +
+ " to an OMElement", e);
+ }
+ return null;
+ }
+
+ public void setEngine(BSFEngine e) {
+ this.bsfEngine = e;
+ }
+
+ private void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/convertors/RBOMElementConvertor.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org