Camel JMS binding - Unable to use customized ContextMapper
calvinchu101 Oct 25, 2012 12:09 PMI am implementing a SOAP > BPM service with SwitchYard 0.6.0.Beta1 (with AS7 download from release), my BPM would call external application by JMS and listense the reply as a signal event. I pass the processInstanceId as an attribute of my domain object and the external application would reply a JMS object message with the processInstanceId for SY to signal the corresponsing process instance. I implemented my ContextMapper and try to read the processInstanceId from the JMS body and set the SY context property {urn:switchyard-component-bpm:process:1.0}processInstanceId, but I found that I am not able to override the default ContextMapper and SY always use the CamelContextMapper when I debug the server.
Here's my switchyard.xml
<?xml version="1.0" encoding="UTF-8"?>
<switchyard xmlns="urn:switchyard-config:switchyard:1.0"
xmlns:bpm="urn:switchyard-component-bpm:config:1.0"
xmlns:camel="urn:switchyard-component-camel:config:1.0"
xmlns:selector="urn:switchyard-component-common-selector:config:1.0"
xmlns:bean="urn:switchyard-component-bean:config:1.0"
name="switchyard-example"
targetNamespace="urn:com.example.switchyard:switchyard-example:0.0.1-SNAPSHOT">
<sca:composite xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" name="switchyard-example" targetNamespace="urn:com.example.switchyard:switchyard-example:0.0.1-SNAPSHOT">
<sca:service name="HelloWorkflowPortType" promote="HelloWorkflow/HelloWorkflow">
<sca:interface.wsdl interface="META-INF/HelloWorkflow.wsdl#wsdl.porttype(HelloWorkflowPortType)"/>
<soap:binding.soap xmlns:soap="urn:switchyard-component-soap:config:1.0">
<soap:contextMapper/>
<soap:wsdl>META-INF/HelloWorkflow.wsdl</soap:wsdl>
<soap:socketAddr>:18001</soap:socketAddr>
<soap:contextPath>switchyard-example</soap:contextPath>
</soap:binding.soap>
</sca:service>
<sca:component name="HelloWorkflow">
<bpm:implementation.bpm processDefinition="META-INF/HelloWorkflow.bpmn"
processId="HelloWorkflow" messageContentInName="input"
messageContentOutName="output">
<bpm:action name="start" type="START_PROCESS"/>
<bpm:action eventType="myEvent" name="signal" type="SIGNAL_EVENT"/>
<bpm:taskHandler name="SwitchYard Service"
class="org.switchyard.component.bpm.task.work.SwitchYardServiceTaskHandler" />
</bpm:implementation.bpm>
<sca:service name="HelloWorkflow">
<sca:interface.java interface="com.example.switchyard.switchyard_example.HelloWorkflow"/>
</sca:service>
</sca:component>
<sca:service name="HelloSignal" promote="HelloService/HelloService">
<sca:interface.java interface="com.example.switchyard.switchyard_example.HelloService"/>
<camel:binding.jms>
<camel:contextMapper includes=".*" class="com.example.switchyard.switchyard_example.JMSResponseContextMapper"/>
<camel:queue>importResponseQueue</camel:queue>
<camel:connectionFactory>#ConnectionFactory</camel:connectionFactory>
</camel:binding.jms>
</sca:service>
<sca:component name="HelloService">
<camel:implementation.camel>
<route xmlns="http://camel.apache.org/schema/spring">
<log message="Input: ${body}" />
<to uri="switchyard://HelloWorkflow?operationName=signal" />
</route>
</camel:implementation.camel>
<!-- <bean:implementation.bean class="com.example.switchyard.switchyard_example.HelloServiceBean"/>
-->
<sca:service name="HelloService">
<sca:interface.java interface="com.example.switchyard.switchyard_example.HelloService"/>
</sca:service>
<sca:reference name="HelloWorkflow">
<sca:interface.java interface="com.example.switchyard.switchyard_example.HelloWorkflow"/>
</sca:reference>
</sca:component>
</sca:composite>
<transforms>
<!--
<transform.java xmlns="urn:switchyard-config:transform:1.0" class="com.example.switchyard.switchyard_example.Transformers" from="java:java.lang.String" to="{urn:com.example.switchyard:switchyard-example:0.0.1-SNAPSHOT}sayHelloResponse"/>
-->
<transform.java xmlns="urn:switchyard-config:transform:1.0" class="com.example.switchyard.switchyard_example.Transformers" from="{urn:com.example.switchyard:switchyard-example:0.0.1-SNAPSHOT}start" to="java:java.lang.String"/>
<transform.java xmlns="urn:switchyard-config:transform:1.0" class="com.example.switchyard.switchyard_example.Transformers" from="{urn:com.example.switchyard:switchyard-example:0.0.1-SNAPSHOT}signal" to="java:java.lang.String"/>
</transforms>
</switchyard>
And here's my ContextMapper
public class JMSResponseContextMapper extends CamelContextMapper {
private static final Logger log = Logger.getLogger(JMSResponseContextMapper.class.getName()) ;
@Override
public void mapFrom(CamelBindingData source, Context context)
throws Exception {
log.info("mapFrom start") ;
super.mapFrom(source, context);
log.info("mapFrom end") ;
}
@Override
public void mapTo(Context context, CamelBindingData target)
throws Exception {
log.info("mapTo start") ;
super.mapTo(context, target);
log.info("mapTo end") ;
}
}
I inserted a break point before call super.mapFrom and super.mapTo and within the CamelContextMapper, I only found CamelContextMapper is called in the debug. Can some experts tell me how to override the default ContextMapper of Camel JMS binding ? Thanks!
Also, I got below exception if I include my JMSResponseMessageComposer in my deployment, I need to add the dependencies of org.switchyard.component.common in order to deploy my jar. Should SY take care of such dependencies instead ?
11:46:40,251 INFO [org.jboss.weld.ClassLoading] (MSC service thread 1-3) catching: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading class com.example.switchyard.switchyard_example.JMSResponseMessageComposer at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:167) [weld-core-1.1.6.Final.jar:2012-03-21 18:52] ...Caused by: java.lang.NoClassDefFoundError: org/switchyard/component/common/composer/BindingData
-
switchyard-example.zip 9.8 KB