Testing asynchronous web services is somewhat special compared to testing synchronous services because in addition to the request message to be sent to the exposed service endpoint, SoapUI also needs to make a callback service available and it has to set the appropriate WS-Addressing headers in the request headers to direct the asynchronous service to the callback service.
SoapUI has a Mock Service facility. This allows us to publish a web service – based on a port type in a WSDL document and published at a port and end point of our choosing. The callback interface is only one way: it receives the response message from the asynchronous service and that is the end of the story. In SoapUI, we can check all messages received by the Mock Service, so we will know if and when the asynchronous service delivered the response. Here is how to do it:
A recent article (http://blog.soasuitehandbook.org/implement-an-asynchronous-web-service-using-jax-ws-in-jdeveloper/) described how to publish an Asynchronous Web Service from Java (using JAX-WS). It also showed how such a Web Service can be tested using SoapUI. A crucial aspect in the interaction with the Asynchronous Web Service is the use of WS-Addressing headers to communicate the callback address (where the response can be sent) and the message id (for the correlation of that response to whatever thread or session invoked the web service).
This article describes how we can invoke an asynchronous Web Service from ‘plain Java’. In this case too, we have to set the WS-Addressing headers. We also have to expose the callback service – and we will do so without the use of a Java EE container. Finally we have to find a way to correlate the callback response – received by a random thread in the JVM – to the thread that made the original call.
The implementation is done in these steps:
Create a JAX-WS Web Service client / proxy to invoke the one way (request) operation on the asynchronous interface
Create a JAX-WS Web Service based on the callback interface specified in the WSDL document for the asynchronous service
Edit the Web Service client to make it publish the callback service (outside of a Java EE container) add a self-chose port and path (using the Endpoint class)
Edit the Web Service client to set the required WS-Addressing headers in the call of the Asynchronous Web Service to direct in calling back
Modify the Callback Service implementation to make the response available to the calling thread – using the message id for correlation
Modify the Web Service client to poll the Callback Service implementation class for the response (note: here we could have used an observer pattern for a more elegant implementation)
This article discusses how to implement an asynchronous web service in Java EE. The Java application will expose a one way operation that will process the request and send a response message to a callback Web Service interface that is indicated in the request header through WS Addressing properties (messageID, replyToAddress). The Asynchronous Web Service is subsequently deployed and invoked from SoapUI.
The article starts with nothing but a simple WSDL file that defines the two portTypes: one way call and the [one way] call back:
The main steps are:
Generate the JAX-WS Client & Proxy for the ThoughtfulGreeterCallback portType (to invoke the callback service in order to send the response)
Generate the JAX-WS Web Service for the ThoughtfulGreeter portType (to implement the one way web service)
Edit the generated code for the ThoughtfulGreeter portType in order to create the response and invoke the callback interface – used on WS-Addressing details in the request
When the implementation is thus complete, we create a new project in SoapUI. In this project, we will create a test request to invoke the ThoughtfulGreeter service. We will also create a MockService in SoapUI to act as the callback interface ThoughfulGreeterCallback. In the request from SoapUI to the ThoughtfulGreeter service, we will specify WS-Addressing properties that refer to the MockService.
Finally, when we have SoapUI make the call to the ThoughtfulGreeter service, we will receive a call (back) to the MockService, containing the response.