Imho it seems to be the fact, that there’s a lack on real world examples while combining standard technologies and products in the Java EE ecosystem which have been evolved and proven over many years. The simple helloWorld projects work, of course, but if you take the next step and dive deeper into the technology trying to fullfil your real world business requirements you will quickly go tits up after hours of straining google.
So at first some specs about the environment
- Java JDK 1.8.0_111
- JBoss EAP 7.0
- JMS Messaging via IBM Websphere MQ 8
- Existing Webservice-specification (WSDL)
- JAXWS Webservice based on pure JEE using JBoss Impl (CXF)
- JMS Endpoints
- keep contract first approach for Webservice
- Properties (f.e. endpoint adresses etc.) should be managed through centrally in JBoss configuration
The following project is using an example WSDL but i will show in detail all relevant configurations.
Please keep in mind that line breaks in your XML and WSDL configuration files can cause strange errors in the code generation or deployment process – if an error occurs double check this issue
The complete project can be found here – so let’s start with some code
Service description – WSDL
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions targetNamespace="http://de.expit.jeews/samples/organization" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://de.expit.jeews/samples/organization" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapjms="http://www.w3.org/2010/soapjms/"> <wsdl:types> ... </wsdl:types> <wsdl:portType name="Organization"> <wsdl:operation name="getContactInfo"> <wsdl:input message="tns:getContactInfo" name="getContactInfo"> </wsdl:input> </wsdl:operation> </wsdl:portType> <wsdl:binding name="JMSSoapBinding" type="tns:Organization"> ... <soapjms:jndiURL></soapjms:jndiURL> <soapjms:jndiInitialContextFactory>org.jboss.as.naming.InitialContextFactory </soapjms:jndiInitialContextFactory> <soapjms:jndiConnectionFactoryName>java:global/jms/MQConnectionFactory</soapjms:jndiConnectionFactoryName> </wsdl:binding> <wsdl:service name="OrganizationService"> <wsdl:port binding="tns:JMSSoapBinding" name="JmsEndpointPort"> <soap:address location="jms:jndi:java:global/jms/tx.q1?sessionTransacted=true" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
The WSDL (just relevant parts shown) defines a simple service with a single Oneway Method called getContactInfo, which is bound the the JmsEndpointPort port using the JMSSoapBinding binding. As stated in the W3C – Soap over JMS specification, we use the soapjms namespace to define the jms endpoint parameters. The spec also consitutes that these params can be specified at different levels, whereas the more specific overwrites the general. The order is
In our example we will use a combination of defining general aspects in the binding and endpoint specific parameters in the URI. Notice that the WSDL just includes JNDI references which are managed through JBoss, because we don’t want to hardcode endpoint information in the service declaration. In detail we configure the following parameters
- soapjms:jndiInitialContextFactory – Java class name of the JNDI context factory which provides the JBoss JNDI interface implementation
- soapjms:jndiConnectionFactoryName – name of the JMS connection factory, also refer to JBoss Setup
- soapjms:jndiURL – URL to the provider, JBoss will take care of providing the JNDI resources, so keep the URL blank
- soap:address location – the JNDI resource i.e. the JMS queue. Notice the prefix jms:jndi this indicates the protocol and that JNDI should be used to resolve the queue. Under the hood this prefix is parsed through CXF transport factory and mapped to the specific destination.
In the next parts we will have a closer look on what needs to be configured at the infrastructure components (JBoss, Websphere MQ) and how the finally service class is coded
- JMS based JAXWS-Webservices using pure JEE stack on JBoss EAP 7 – Tutorial Part II – Infrastructure Setup
- JMS based JAXWS-Webservices using pure JEE stack on JBoss EAP 7 – Tutorial Part III – Java Project Setup
- JMS based JAXWS-Webservices using pure JEE stack on JBoss EAP 7 – Tutorial Part IV – Adding WS-Security
This blog post demonstrates an alternate approach o realize the service using the pure JEE stack with Message Driven Beans.