Invoke an Asynchronous Web Service from Java (using only Java SE, no Java EE container)

A recent article ( 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)

Lees verder