...
JMS Extension Namespace
Code Block |
---|
xmlns:soapjms="http://www.w3.org/2010/soapjms/"
|
...
CXF supports three variants, "jndi", "queue", and "topic".
For example:
Code Block |
---|
jms:jndi:SomeJndiNameForDestination?jndiInitialContextFactory=com.example.jndi.JndiFactory&priority=3
jms:queue:ExampleQueueName?timeToLive=1000
|
Properties are as follows:
Property | From Version | DefaultValue | Description |
---|---|---|---|
conduitIdSelectorPrefix | 3.0.0 | ||
deliveryMode | PERSISTENT | NON_PERSISTENT messages will kept only in memory | |
durableSubscriptionName | 3.0.0 | ||
jndiConnectionFactoryName | ConnectionFactory | Specifies the JNDI name bound to the JMS connection factory to use when connecting to the JMS destination. | |
jndiInitialContextFactory |
| Specifies the fully qualified Java class name of the "InitialContextFactory" implementation class to use. | |
jndiTransactionManagerName | 3.0.0 | Name of the JTA TransactionManager. Will be searched in spring, blueprint and jndi | |
jndiURL |
| Specifies the JNDI provider URL | |
replyToName |
| Specifies the JNDI name bound to the JMS destinations where replies are sent. | |
priority | 4 | Priority for the messages. See your JMS provider documentation for details | |
timeToLive | 0 | Time (in ms) after which the message will be discarded by the jms provider | |
Additional JNDI Parameters |
| Additional parameters for a JNDI provider. A custom parameter name must start with the prefix "jndi-". |
...
Here is an example:
Code Block | ||||
---|---|---|---|---|
| ||||
<wsdl11:binding name="exampleBinding">
<soapjms:jndiContextParameter name="name" value="value" />
<soapjms:jndiConnectionFactoryName>ConnectionFactory
</soapjms:jndiConnectionFactoryName>
<soapjms:jndiInitialContextFactory>
org.apache.activemq.jndi.ActiveMQInitialContextFactory
</soapjms:jndiInitialContextFactory>
<soapjms:jndiURL>tcp://localhost:61616
</soapjms:jndiURL>
<soapjms:deliveryMode>PERSISTENT</soapjms:deliveryMode>
<soapjms:priority>5</soapjms:priority>
<soapjms:timeToLive>200</soapjms:timeToLive>
</wsdl11:binding>
<wsdl11:service name="exampleService">
<soapjms:jndiInitialContextFactory>
com.example.jndi.InitialContextFactory
</soapjms:jndiInitialContextFactory>
<soapjms:timeTolive>100</soapjms:timeToLive>
...
<wsdl11:port name="quickPort" binding="tns:exampleBinding">
...
<soapjms:timeToLive>10</soapjms:timeToLive>
</wsdl11:port>
<wsdl11:port name="slowPort" binding="tns:exampleBinding">
...
</wsdl11:port>
</wsdl11:service>
|
...
For this example:
Code Block | ||||
---|---|---|---|---|
| ||||
<wsdl:definitions name="JMSGreeterService"
<wsdl:binding name="JMSGreeterPortBinding" type="tns:JMSGreeterPortType">
<soap:binding style="document"
transport="http://www.w3.org/2010/soapjms/" />
<soapjms:jndiContextParameter name="name"
value="value" />
<soapjms:jndiConnectionFactoryName>ConnectionFactory
</soapjms:jndiConnectionFactoryName>
<soapjms:jndiInitialContextFactory>
org.apache.activemq.jndi.ActiveMQInitialContextFactory
</soapjms:jndiInitialContextFactory>
<soapjms:jndiURL>tcp://localhost:61616
</soapjms:jndiURL>
<soapjms:deliveryMode>PERSISTENT</soapjms:deliveryMode>
<soapjms:priority>5</soapjms:priority>
<soapjms:timeToLive>1000</soapjms:timeToLive>
<wsdl:operation name="greetMe">
<soap:operation soapAction="test" style="document" />
<wsdl:input name="greetMeRequest">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="greetMeResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="JMSGreeterService">
<soapjms:jndiConnectionFactoryName>ConnectionFactory
</soapjms:jndiConnectionFactoryName>
<soapjms:jndiInitialContextFactory>
org.apache.activemq.jndi.ActiveMQInitialContextFactory
</soapjms:jndiInitialContextFactory>
<wsdl:port binding="tns:JMSGreeterPortBinding" name="GreeterPort">
<soap:address location="jms:jndi:dynamicQueues/test.cxf.jmstransport.queue" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
|
...
Developers who don't wish to modify the WSDL file can also publish the endpoint information using Java code. For CXF's SOAP over JMS implementation you can write the following:
Code Block | ||||
---|---|---|---|---|
| ||||
// You just need to set the address with JMS URI
String address = "jms:jndi:dynamicQueues/test.cxf.jmstransport.queue3"
+ "?jndiInitialContextFactory"
+ "=org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+ "&jndiConnectionFactoryName=ConnectionFactory&jndiURL=tcp://localhost:61500";
Hello implementor = new HelloImpl();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setServiceClass(Hello.class);
svrFactory.setAddress(address);
// And specify the transport ID with SOAP over JMS specification
svrFactory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICATION_TRANSPORTID);
svrFactory.setServiceBean(implementor);
svrFactory.create();
|
...
Sample code to consume a SOAP-over-JMS service is as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
public void invoke() throws Exception {
// You just need to set the address with JMS URI
String address = "jms:jndi:dynamicQueues/test.cxf.jmstransport.queue3"
+ "?jndiInitialContextFactory"
+ "=org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+ "&jndiConnectionFactoryName=ConnectionFactory&jndiURL="
+ "tcp://localhost:61500";
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// And specify the transport ID with SOAP over JMS specification
factory.setTransportId(JMSSpecConstants.SOAP_JMS_SPECIFICIATION_TRANSPORTID);
factory.setServiceClass(Hello.class);
factory.setAddress(address);
Hello client = (Hello)factory.create();
String reply = client.sayHi(" HI");
System.out.println(reply);
}
|
Even if you want to use the 'queue' or 'topic' variants and avoid dealing with JNDI directly, you still have to specify the two factory parameters in the address:
Code Block |
---|
svrFactory.setAddress("jms:queue:test.cxf.jmstransport.queue?timeToLive=1000"
+ "&jndiConnectionFactoryName=ConnectionFactory"
+ "&jndiInitialContextFactory"
+ "=org.apache.activemq.jndi.ActiveMQInitialContextFactory");
|