ServiceMix Script
The ServiceMix Script component provides JBI integration with scripting engines.
Note that this component is only available in releases >= 3.1 and older scripting component will be deprecated in future releases.
Deployment
Here is an example of a SU deploymennt. The SU is only a zip of these two files:
<beans xmlns:script="http:
xmlns:lang="http:
xmlns:test="urn:test">
<script:exchangeProcessor service="test:groovy" endpoint="endpoint">
<property name="helpers">
<list>
<ref bean="groovyExchangeHelper" />
</list>
</property>
<property name="implementation" ref="groovyExchangeProcessor" />
</script:exchangeProcessor>
<script:exchangeHelper id="groovyExchangeHelper" singleton="true" />
<lang:groovy id="groovyExchangeProcessor"
script-source="classpath:GroovyExchangeProcessor.groovy">
<lang:property name="exchangeHelper" ref="groovyExchangeHelper" />
</lang:groovy>
</beans>
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";
}
}