Versions Compared

Key

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

...

Code Block
languagexml
titleGreeter Service with JMS transaport
collapsetrue
<wsdl:definitions name="JMSGreeterService"
	<wsdl:binding name="JMSGreeterPortBinding" type xmlns:soap="tns:JMSGreeterPortType">
		<soap:binding style="document" transporthttp://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="literalxmlns: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
languagexml
titleEndpoint in spring
<bean id="ConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
  <property name="brokerURL" value="tcp://localhost: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:

<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>
  • 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
languagexml
titleEndpoint
Code Block
languagexml
titleProxy in spring
<bean id="ConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
  <property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<jaxws:clientendpoint id="CustomerService"
  address="jms:queue:test.cxf.jmstransport.queue?timeToLive=1000"
  serviceClassimplementor="com.example.customerservice.CustomerServiceimpl.CustomerServiceImpl">
</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:

endpoint>

or a Client like this:

Code Block
languagexml
titleProxy in spring
<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
java
java
  // 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=
Code Block
javajava
  // 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");
  EndpointImplHello epimplementor = (EndpointImpl)Endpoint.create(implnew HelloImpl();
  ep.getFeatures().add(JaxWsServerFactoryBean svrFactory = new ConnectionFactoryFeatureJaxWsServerFactoryBean(cf));
  epsvrFactory.publish("jms:queue:test.cxf.jmstransport.queue?timeToLive=1000");

NOTE: For tests it can be useful to create an embedded broker like this:

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:

Wiki Markup
{code}
    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();
        }
    }
{code
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

...