Łukasz Łukasz - 1 year ago 85
Java Question

Ignoring HTTP response for web service one-way operation

I am developing a jax-ws webservice that pushes messages asynchronously to the subscribed consumers using one-way operation.

Unfortunatelly with each notification, server awaits a HTTP202 response confirmation which blocks the thread for a fraction of a second. This is affecting the performance of the system and I am looking for a way around this.

Is there any way to execute a web-service one-way call and ignore the HTTP response status?

Answer Source

Ok, so after spending a lot of time on this I have found two solutions:

1) Using Apache HTTPComponents, which provide AsyncHTTPClient with nice API allowing us to build a HTTP response from the scratch.

2) More web-service oriented solution based on Apache CXF platform (which includes the HTTPClient implementation) - first we need to set the global Bus property:

Bus bus = BusFactory.getDefaultBus();
bus.setProperty(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);

Then, we use custom interceptor to set the message exchange property to asynchronous:

final class SkipWaitInterceptor extends AbstractSoapInterceptor {

    SkipWaitInterceptor() {

    public void handleMessage(final SoapMessage message) throws Fault {


Finally, we register the interceptor on our asynchronous Endpoint

org.apache.cxf.endpoint.Client client =
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
cxfEndpoint.getOutInterceptors().add(new SkipWaitInterceptor());

That's all, one-way operation responses no longer block the communication.