...
Query Parameter | From Version | DefaultValue | Description | ||||
---|---|---|---|---|---|---|---|
conduitIdSelectorPrefix | 3.0.0 | If set then this string will be the prefix for all correlation ids the conduit creates and also be used in the selector for listening to replies | |||||
deliveryMode | PERSISTENT | NON_PERSISTENT messages will kept only in memory | |||||
durableSubscriptionClientId | 3.0.1 | Optional Client identifier for the connection. The purpose is to associate a connection with a state maintained on behalf of the client by a provider. The only such state identified by the JMS API is that required to support durable subscriptions. | |||||
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 | |||||
jndi-* | Additional parameters for a JNDI provider | ||||||
messageType | 3.0.0 | byte | JMS message type used by CXF (byte, text or binary) | ||||
password | 3.0.0 | Password for creating the connection. Using this in the URI is discouraged | |||||
priority | 3.0.0 | 4 | Priority for the messages. See your JMS provider documentation for details. Values range from 0 to 9 where 0 is lowest priority | ||||
replyToName |
| Specifies the JNDI name bound to the JMS destinations where replies are sent | |||||
receiveTimeout | 3.0.0 | 60000 | Timeout in milliseconds the client waits for a reply in case of request / repy exchanges | ||||
reconnectOnException | deprecated in 3.0.0 | true | Should the transport reconnect in case of exceptions. From version 3.0.0 on the transport will always reconnect in case of exceptions | ||||
sessionTransacted | 3.0.0 | false | Set to true for resource local transactions. Do not set if you use JTAtargetService | ||||
timeToLive | timeToLive | 0 | Time (in ms) after which the message will be discarded by the jms provider | ||||
topicReplyToName | Reply to messages on a topic with this name. Depending on the variant this is either a jndi or jms name. | ||||||
useConduitIdSelector | 3.0.0 | true | Each conduit is assigned with a UUID. If set to true this conduit id will be the prefix for all correlation ids. This allows several endpoints to share a JMS queue or topic | ||||
username | 3.0.0 |
| Username for creating the connection | ||||
concurrentConsumers | 1 | Number of consumers listening queue concurrently |
Some of these attributes are specified in the JMS URI specification.
...
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 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://cxf.apache.org/jms_greeter" xmlns:xsd="http://www.w3.org/20102001/soapjms/XMLSchema" /> <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 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:x1="http://cxf.apache.org/jms_greeter/types" xmlns:soapjms="http://www.w3.org/2010/soapjms/" name="JMSGreeterService" targetNamespace="http://cxf.apache.org/jms_greeter"> ... <wsdl:binding name="JMSGreeterPortBinding" type="tns:JMSGreeterPortType"> <soap:binding style="document" transport="http://www.w3.org/2010/soapjms/" /> <soapjms:jndiContextParameter name="name" value="value" /> </wsdl:input><soapjms:jndiConnectionFactoryName>ConnectionFactory</soapjms:jndiConnectionFactoryName> <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" /> <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:port>input> </wsdl:service> </wsdl:definitions> |
- The transport URI (http://www.w3.org/2010/soapjms/) is defined in the <soap:binding>.
- The jms: URI is defined in the <soap:address>
- The extension properties are in the <soap:binding>
Define service endpoint or proxy in spring or blueprint
The JAXWS endpoint or proxy can be defined like in the SOAP/HTTP case. Just use a jms: uri like described above.
In CXF 3 it is possible to omit the jndi settings. Just specify an endpoint like this:
Code Block | ||||
---|---|---|---|---|
| ||||
|
Publishing a service with the JAVA API
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 | ||
---|---|---|
java | java | // You just need to set the address with JMS URI String address = <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.queue3queue" + "?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(); // Alternatively using JAXWS Endpoint.create and avoiding JNDI ConnectionFactory cf = new ActiveMQConnectionFactory( /> </wsdl:port> </wsdl:service> </wsdl:definitions> |
- The transport URI (http://www.w3.org/2010/soapjms/) is defined in the <soap:binding>.
- The jms: URI is defined in the <soap:address>
- The extension properties are in the <soap:binding>
Define service endpoint or proxy in spring or blueprint
The JAXWS endpoint or proxy can be defined like in the SOAP/HTTP case. Just use a jms: uri like described above.
In CXF 3 it is possible to omit the jndi settings. Just specify an endpoint like this:
Code Block | ||||
---|---|---|---|---|
| ||||
<bean id="ConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61500"); EndpointImpl ep = (EndpointImpl)Endpoint.create(impl); ep.setBus(bus); ep.getFeatures().add(new ConnectionFactoryFeature(cf)); ep.publish("jms:queue:test.cxf.jmstransport.queue?timeToLive=1000"); |
NOTE: For tests it can be useful to create an embedded broker like this:
61616"/>
</bean>
<jaxws:endpoint id="CustomerService"
address="jms:queue:test.cxf.jmstransport.queue?timeToLive=1000"
implementor="com.example.customerservice.impl.CustomerServiceImpl">
</jaxws:endpoint> |
or a Client like this:
Code Block | ||||
---|---|---|---|---|
| ||||
<bean id="ConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<jaxws:client id="CustomerService"
address="jms:queue:test.cxf.jmstransport.queue?timeToLive=1000"
serviceClass="com.example.customerservice.CustomerService">
</jaxws:client> |
The connection factory will be looked up as a bean in the context. By default the name "ConnectionFactory" is assumed but it can be configured using the jndiConnectionFactoryName uri parameter.
Alternatively the connection factory can be set using the ConnectionFactoryFeature.
Publishing a service with the JAVA API
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();
// Alternatively using JAXWS Endpoint.create and avoiding JNDI
ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61500");
EndpointImpl ep = (EndpointImpl)Endpoint.create(impl);
ep.getFeatures().add(new ConnectionFactoryFeature(cf));
ep.publish("jms:queue:test.cxf.jmstransport.queue?timeToLive=1000"); |
NOTE: For tests it can be useful to create an embedded broker like this:
Code Block |
---|
public final void run() {
try {
broker = new BrokerService();
broker.setPersistent(false);
broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
broker.setTmpDataDirectory(new File("./target"));
broker.setUseJmx(false);
if (brokerName != null) {
broker.setBrokerName(brokerName);
}
broker.addConnector(brokerUrl1);
broker.start();
} catch (Exception e) {
e.printStackTrace();
}
}
|
Wiki Markup |
{snippet:id=broker|lang=java|url=cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/EmbeddedJMSBrokerLauncher.java} |
Consume the service with the API
...
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); } // Alternatively using the JAXWS API with jms details defined in WSDL while avoiding JNDI SOAPService2 service = new SOAPService2(wsdl, serviceName); // Using the generated service ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61500"); ConnectionFactoryFeature cff = new ConnectionFactoryFeature(cf); Greeter greeter = markForClose(service.getPort(portName, Greeter.class, cff)); // Connection Factory can be set as a feature in CXF >= 3.0.0 |
...