Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note that this component is only available in releases >= 3.1 and older scripting component will be deprecated in future releases.
This component leverages Spring support for dynamic languages, so you will find useful informations on the Spring site.

Deployment

Here is an example of a SU deploymennt. The SU is only a zip of these two files:

...

Code Block
titleGroovyExchangeProcessor.groovy
import org.apache.servicemix.common.ExchangeProcessor;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.script.ScriptExchangeHelper;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;

class GroovyExchangeProcessor implements ExchangeProcessor {

    @Property ScriptExchangeHelper exchangeHelper;

	def void start() {
	    println "Starting";
	}

    def void process(MessageExchange 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("<world>hello</world>"));
        exchange.setMessage(out, "out");
        exchangeHelper.sendExchange(exchange);    	
    }
    
    def void stop() {
    	println "Stopping";
    }
}

Inlining script

Alternatively, you can inline the script in the xbean.xml file the following way:

Code Block
langxml

  <lang:groovy id="groovyExchangeProcessor">
    <lang:inline-script><![CDATA[
        ... put your script here ...
    ]]></lang:inline-script>
    <lang:property name="exchangeHelper" ref="groovyExchangeHelper" />
  </lang:groovy>

Accessing the Delivery Channel

...