Author: lhein
Date: Tue Jun 10 08:36:31 2008
New Revision: 666160
URL: http://svn.apache.org/viewvc?rev=666160&view=rev
Log:
added new endpoint type for script component which supports JSR-223 compliant
scripting - not finished yet
Added:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/DefaultScriptingMarshaler.java
(with props)
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpoint.java
(with props)
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpointType.java
(with props)
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptingMarshalerSupport.java
(with props)
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/GroovyExchangeProcessorJSR223.groovy
Modified:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/pom.xml
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptComponent.java
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml
Modified:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/pom.xml?rev=666160&r1=666159&r2=666160&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/pom.xml
(original)
+++ servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/pom.xml
Tue Jun 10 08:36:31 2008
@@ -45,6 +45,23 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.livetribe</groupId>
+ <artifactId>livetribe-jsr223</artifactId>
+ <version>2.0.3</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.script</groupId>
+ <artifactId>groovy-engine</artifactId>
+ <version>20070112</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<scope>provided</scope>
@@ -100,7 +117,7 @@
<version>3.8.1</version>
<scope>test</scope>
</dependency>
- <dependency>
+ <dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<version>2.2.3</version>
Added:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/DefaultScriptingMarshaler.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/DefaultScriptingMarshaler.java?rev=666160&view=auto
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/DefaultScriptingMarshaler.java
(added)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/DefaultScriptingMarshaler.java
Tue Jun 10 08:36:31 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.servicemix.script;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.script.Bindings;
+import javax.script.ScriptEngine;
+
+/**
+ * @author lhein
+ */
+public class DefaultScriptingMarshaler implements ScriptingMarshalerSupport {
+ /* (non-Javadoc)
+ * @see
org.apache.servicemix.script.ScriptingMarshalerSupport#onStartup(org.apache.servicemix.script.ScriptEndpoint)
+ */
+ public void onStartup(ScriptEndpoint endpoint) throws Exception {
+ // nothing to do for now
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.servicemix.script.ScriptingMarshalerSupport#onShutdown(org.apache.servicemix.script.ScriptEndpoint)
+ */
+ public void onShutdown(ScriptEndpoint endpoint) throws Exception {
+ // nothing to do for now
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.servicemix.script.ScriptingMarshalerSupport#registerUserBeans(org.apache.servicemix.script.ScriptEndpoint,
javax.jbi.messaging.MessageExchange, javax.script.Bindings)
+ */
+ public void registerUserBeans(ScriptEndpoint endpoint, MessageExchange
exchange, Bindings bindings) {
+ // no additional beans needed for now
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.servicemix.script.ScriptingMarshalerSupport#getScriptCode(org.apache.servicemix.script.ScriptEndpoint,
javax.jbi.messaging.MessageExchange)
+ */
+ public InputStream getScriptCode(ScriptEndpoint endpoint, MessageExchange
exchange) throws IOException {
+ return endpoint.getScript().getInputStream();
+ }
+}
Propchange:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/DefaultScriptingMarshaler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptComponent.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptComponent.java?rev=666160&r1=666159&r2=666160&view=diff
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptComponent.java
(original)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptComponent.java
Tue Jun 10 08:36:31 2008
@@ -26,17 +26,17 @@
*/
public class ScriptComponent extends DefaultComponent {
- private ScriptExchangeProcessorEndpoint[] endpoints;
+ private ScriptEndpointType[] endpoints;
protected Class[] getEndpointClasses() {
- return new Class[] {ScriptExchangeProcessorEndpoint.class };
+ return new Class[] {ScriptExchangeProcessorEndpoint.class,
ScriptEndpoint.class };
}
- public ScriptExchangeProcessorEndpoint[] getEndpoints() {
+ public ScriptEndpointType[] getEndpoints() {
return endpoints;
}
- public void setEndpoints(ScriptExchangeProcessorEndpoint[] endpoints) {
+ public void setEndpoints(ScriptEndpointType[] endpoints) {
this.endpoints = endpoints;
}
Added:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpoint.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpoint.java?rev=666160&view=auto
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpoint.java
(added)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpoint.java
Tue Jun 10 08:36:31 2008
@@ -0,0 +1,358 @@
+/*
+ * 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.servicemix.script;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.MessageExchange.Role;
+import javax.script.Bindings;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.common.endpoints.ProviderEndpoint;
+import org.springframework.core.io.Resource;
+
+/**
+ * @org.apache.xbean.XBean element="jsr223"
+ * @author lhein
+ */
+public class ScriptEndpoint extends ProviderEndpoint implements
ScriptEndpointType {
+ private static Log logger = LogFactory.getLog(ScriptEndpoint.class);
+
+ public static final String KEY_CONTEXT = "context";
+ public static final String KEY_ENDPOINT = "endpoint";
+ public static final String KEY_IN_EXCHANGE = "exchange";
+ public static final String KEY_CHANNEL = "channel";
+ public static final String KEY_ENDPOINTNAME = "endpointname";
+ public static final String KEY_SERVICENAME = "servicename";
+ public static final String KEY_INTERFACENAME = "interfacename";
+ public static final String KEY_SCRIPT = "script";
+ public static final String KEY_LOGGER = "logger";
+ public static final String KEY_USER_BINDINGS = "bindings";
+
+ private ScriptEngineManager manager = null;
+ private ScriptEngine engine = null;
+ private ScriptingMarshalerSupport marshaler = new
DefaultScriptingMarshaler();
+ private Resource script;
+ private boolean disableOutput = false;
+ private Map<String, Object> bindings;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.servicemix.common.Endpoint#validate()
+ */
+ public void validate() throws DeploymentException {
+ super.validate();
+ if (script == null) {
+ throw new DeploymentException("Property script must be set");
+ } else {
+ if (this.manager == null) {
+ // lazy instatiation
+ this.manager = new ScriptEngineManager();
+ }
+ // initialize the script engine
+ this.engine =
this.manager.getEngineByExtension(FilenameUtils.getExtension(script.getFilename()));
+ if (this.engine == null) {
+ throw new DeploymentException("There is no script engine
registered for extension "
+ +
FilenameUtils.getExtension(script.getFilename()));
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.servicemix.common.endpoints.ProviderEndpoint#start()
+ */
+ public void start() throws Exception {
+ super.start();
+ try {
+ // lazy instatiation
+ this.manager = new ScriptEngineManager();
+
+ if (script == null) {
+ throw new IllegalArgumentException("Property script must be
set");
+ } else {
+ // initialize the script engine
+ this.engine =
this.manager.getEngineByExtension(FilenameUtils.getExtension(script
+ .getFilename()));
+ if (this.engine == null) {
+ throw new RuntimeException("There is no script engine
registered for extension "
+ +
FilenameUtils.getExtension(script.getFilename()));
+ }
+ }
+
+ // do custom startup logic
+ marshaler.onStartup(this);
+ } catch (Exception ex) {
+ throw new JBIException(ex);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.servicemix.common.endpoints.ProviderEndpoint#stop()
+ */
+ @Override
+ public void stop() throws Exception {
+ try {
+ // do custom startup logic
+ marshaler.onShutdown(this);
+ } catch (Exception ex) {
+ throw new JBIException(ex);
+ }
+
+ super.stop();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.servicemix.common.endpoints.ProviderEndpoint#process(javax.jbi.messaging.MessageExchange)
+ */
+ @Override
+ public void process(MessageExchange exchange) throws Exception {
+ doScripting(exchange);
+ }
+
+ /**
+ * processes an incoming message
+ *
+ * @param exchange the exchange
+ * @throws Exception on any errors
+ */
+ protected void doScripting(MessageExchange exchange) throws Exception {
+ if (exchange == null) {
+ return;
+ }
+
+ // The component acts as a consumer, this means this exchange is
+ // received because
+ // we sent it to another component. As it is active, this is either an
+ // out or a fault
+ // If this component does not create / send exchanges, you may just
+ // throw an
+ // UnsupportedOperationException
+ if (exchange.getRole() == Role.CONSUMER) {
+ return;
+ }
+
+ // The component acts as a provider, this means that another component
+ // has requested our
+ // service
+ // As this exchange is active, this is either an in or a fault (out are
+ // send by this
+ // component)
+ else if (exchange.getRole() == MessageExchange.Role.PROVIDER) {
+ // Exchange is finished
+ if (exchange.getStatus() == ExchangeStatus.DONE) {
+ return;
+ }
+ // Exchange has been aborted with an exception
+ else if (exchange.getStatus() == ExchangeStatus.ERROR) {
+ return;
+ }
+ // Fault message
+ else if (exchange.getFault() != null) {
+ done(exchange);
+ } else {
+ Bindings scriptBindings = engine.createBindings();
+
+ scriptBindings.put(KEY_IN_EXCHANGE, exchange);
+
+ // exec script engine code to do its thing for this
+ scriptBindings.put(KEY_CONTEXT, getContext());
+ scriptBindings.put(KEY_IN_EXCHANGE, exchange);
+ scriptBindings.put(KEY_ENDPOINT, this);
+ scriptBindings.put(KEY_CHANNEL, getChannel());
+ scriptBindings.put(KEY_ENDPOINTNAME, getEndpoint());
+ scriptBindings.put(KEY_SERVICENAME, getService());
+ scriptBindings.put(KEY_INTERFACENAME, getInterfaceName());
+ scriptBindings.put(KEY_LOGGER, logger);
+
+ try {
+ scriptBindings.put(KEY_SCRIPT,
getScript().getFile().getAbsolutePath());
+ } catch (IOException ioex) {
+ scriptBindings.put(KEY_SCRIPT, getScript());
+ }
+
+ scriptBindings.put(KEY_USER_BINDINGS, bindings);
+
+ // call back method for custom marshaler to inject it's own
+ // beans
+ this.marshaler.registerUserBeans(this, exchange,
scriptBindings);
+
+ // get the input stream to the script code
+ InputStream is = null;
+ try {
+ is = this.marshaler.getScriptCode(this, exchange);
+ } catch (IOException ioex) {
+ logger
+ .error("Unable to load script in marshaler: " +
this.marshaler.getClass().getName(),
+ ioex);
+ // io error getting the script code
+ try {
+ is = this.script.getInputStream();
+ } catch (IOException i2) {
+ logger.error("Unable to load the script " +
script.getFilename(), i2);
+ throw new MessagingException("Unable to load the
script " + script.getFilename());
+ }
+ }
+
+ // create a reader for the stream
+ Reader reader = new InputStreamReader(is);
+
+ try {
+ // execute the script
+ this.engine.eval(reader, scriptBindings);
+
+ exchange =
(MessageExchange)scriptBindings.get(KEY_IN_EXCHANGE);
+
+ if (!isDisableOutput()) {
+ if (exchange instanceof InOnly) {
+ done(exchange);
+ } else {
+ send(exchange);
+ }
+ }
+ } catch (ScriptException ex) {
+ logger.error("Error executing the script: " +
ex.getFileName() + " at line: "
+ + ex.getLineNumber() + " and column: " +
ex.getColumnNumber(), ex);
+ fail(exchange, ex);
+ } catch (NullPointerException ex) {
+ logger.error("Error executing the script: " +
script.getFilename()
+ + ". A unexpected NullPointerException
occured.", ex);
+ fail(exchange, ex);
+ }
+ }
+ }
+
+ // Unknown role
+ else {
+ throw new MessagingException("ScriptEndpoint.doScripting():
Unknown role: " + exchange.getRole());
+ }
+ }
+
+ /**
+ * @return the script
+ */
+ public Resource getScript() {
+ return this.script;
+ }
+
+ /**
+ * @param script the script to set
+ */
+ public void setScript(Resource script) {
+ this.script = script;
+ }
+
+ /**
+ * @return the marshaler
+ */
+ public ScriptingMarshalerSupport getMarshaler() {
+ return this.marshaler;
+ }
+
+ /**
+ * @param marshaler the marshaler to set
+ */
+ public void setMarshaler(ScriptingMarshalerSupport marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * @return the disableOutput
+ */
+ public boolean isDisableOutput() {
+ return this.disableOutput;
+ }
+
+ /**
+ * @param disableOutput the disableOutput to set
+ */
+ public void setDisableOutput(boolean disableOutput) {
+ this.disableOutput = disableOutput;
+ }
+
+ /**
+ * @return the bindings
+ */
+ public Map<String, Object> getBindings() {
+ return this.bindings;
+ }
+
+ /**
+ * @param bindings the bindings to set
+ */
+ public void setBindings(Map<String, Object> bindings) {
+ this.bindings = bindings;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.servicemix.common.endpoints.SimpleEndpoint#fail(javax.jbi.messaging.MessageExchange,
+ * java.lang.Exception)
+ */
+ protected void fail(MessageExchange messageExchange, Exception e) throws
MessagingException {
+ super.fail(messageExchange, e);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.servicemix.common.endpoints.SimpleEndpoint#send(javax.jbi.messaging.MessageExchange)
+ */
+ protected void send(MessageExchange messageExchange) throws
MessagingException {
+ super.send(messageExchange);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.servicemix.common.endpoints.SimpleEndpoint#sendSync(javax.jbi.messaging.MessageExchange)
+ */
+ protected void sendSync(MessageExchange messageExchange) throws
MessagingException {
+ super.sendSync(messageExchange);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.servicemix.common.endpoints.SimpleEndpoint#done(javax.jbi.messaging.MessageExchange)
+ */
+ protected void done(MessageExchange messageExchange) throws
MessagingException {
+ super.done(messageExchange);
+ }
+}
Propchange:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpoint.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpointType.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpointType.java?rev=666160&view=auto
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpointType.java
(added)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpointType.java
Tue Jun 10 08:36:31 2008
@@ -0,0 +1,24 @@
+/*
+ * 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.servicemix.script;
+
+/**
+ * @author lhein
+ */
+public interface ScriptEndpointType {
+ // just a grouping interface
+}
Propchange:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptEndpointType.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java?rev=666160&r1=666159&r2=666160&view=diff
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java
(original)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java
Tue Jun 10 08:36:31 2008
@@ -29,7 +29,7 @@
/**
* @org.apache.xbean.XBean element="exchangeProcessor"
*/
-public class ScriptExchangeProcessorEndpoint extends ProviderEndpoint {
+public class ScriptExchangeProcessorEndpoint extends ProviderEndpoint
implements ScriptEndpointType {
private ExchangeProcessor implementation;
Added:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptingMarshalerSupport.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptingMarshalerSupport.java?rev=666160&view=auto
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptingMarshalerSupport.java
(added)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptingMarshalerSupport.java
Tue Jun 10 08:36:31 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.servicemix.script;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.script.Bindings;
+
+/**
+ * @author lhein
+ */
+public interface ScriptingMarshalerSupport {
+ /**
+ * hook method to allow a custom marshaler to do things on endpoint startup
+ *
+ * @param endpoint the endpoint
+ * @throws Exception on any exception
+ */
+ void onStartup(final ScriptEndpoint endpoint) throws Exception;
+
+ /**
+ * hook method to allow a custom marshaler to do things on endpoint
shutdown
+ *
+ * @param endpoint the endpoint
+ * @throws Exception on any exception
+ */
+ void onShutdown(final ScriptEndpoint endpoint) throws Exception;
+
+ /**
+ * returns the code of the script as input stream
+ *
+ * @param endpoint the endpoint
+ * @param exchange the message exchange
+ * @return the code of the script as string
+ */
+ InputStream getScriptCode(final ScriptEndpoint endpoint, final
MessageExchange exchange) throws IOException;
+
+ /**
+ * hook method for filling user beans into the available variables from
+ * script
+ *
+ * @param endpoint the endpoint
+ * @param exchange the exchange
+ * @param bindings the bindings
+ */
+ void registerUserBeans(final ScriptEndpoint endpoint, final
MessageExchange exchange,
+ final Bindings bindings);
+}
Propchange:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptingMarshalerSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java?rev=666160&r1=666159&r2=666160&view=diff
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java
(original)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java
Tue Jun 10 08:36:31 2008
@@ -89,6 +89,25 @@
client.done(me);
}
+ public void testGroovyJSR223() throws Exception {
+ DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+ InOut me = client.createInOutExchange();
+ me.setService(new QName("urn:test", "groovy-jsr223"));
+ me.getInMessage().setContent(new
StringSource("<hello>jsr-223</hello>"));
+ client.sendSync(me);
+ if (me.getStatus() == ExchangeStatus.ERROR) {
+ if (me.getError() != null) {
+ throw me.getError();
+ } else {
+ fail("Received ERROR status");
+ }
+ } else if (me.getFault() != null) {
+ fail("Received fault: " + new
SourceTransformer().toString(me.getFault().getContent()));
+ }
+ log.info(new
SourceTransformer().toString(me.getOutMessage().getContent()));
+ client.done(me);
+ }
+
protected AbstractXmlApplicationContext createBeanFactory() {
return new ClassPathXmlApplicationContext("spring.xml");
}
Added:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/GroovyExchangeProcessorJSR223.groovy
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/GroovyExchangeProcessorJSR223.groovy?rev=666160&view=auto
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/GroovyExchangeProcessorJSR223.groovy
(added)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/GroovyExchangeProcessorJSR223.groovy
Tue Jun 10 08:36:31 2008
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+
+println "Starting JSR-223 groovy processor";
+
+println exchange;
+def inputMessage = new
SourceTransformer().toString(exchange.getInMessage().getContent());
+println "Hello, I got an input message " + inputMessage;
+NormalizedMessage out = exchange.createMessage();
+out.setContent(new StringSource("<response>" + bindings.get("answer") +
"</response>"));
+exchange.setMessage(out, "out");
+println exchange;
+
+println "Stopping JSR-223 groovy processor";
Modified:
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml
URL:
http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml?rev=666160&r1=666159&r2=666160&view=diff
==============================================================================
---
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml
(original)
+++
servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml
Tue Jun 10 08:36:31 2008
@@ -20,6 +20,7 @@
<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
xmlns:script="http://org.apache.servicemix/script/1.0"
xmlns:lang="http://www.springframework.org/schema/lang"
+ xmlns:util="http://www.springframework.org/schema/util"
xmlns:test="urn:test">
<sm:container id="jbi" embedded="true" createMBeanServer="false">
@@ -65,7 +66,14 @@
</property>
<property name="implementation" ref="jrubyExchangeProcessor" />
</script:exchangeProcessor>
-
+
+ <!-- Groovy JSR-223 Endpoint -->
+ <script:jsr223
+ service="test:groovy-jsr223" endpoint="endpoint"
+ script="classpath:GroovyExchangeProcessorJSR223.groovy"
+ bindings="#customBindings">
+ </script:jsr223>
+
</sm:endpoints>
</sm:container>
@@ -91,4 +99,8 @@
<lang:property name="exchangeHelper" ref="jrubyExchangeHelper"
/>
</lang:jruby>
+ <util:map id="customBindings">
+ <entry key="answer" value="JSR-223 seems to work fine..." />
+ </util:map>
+
</beans>