WSIFOperation - Asynchronous interactions reference

WSIF allows asynchronous operation. In this mode of operation, the client puts the request message as part of one transaction, and carries on with the thread of execution. The response message is then handled by a different thread, with a separate transaction. The SOAP/JMS and Native JMS providers are the only WSIF providers that currently support asynchronous operation.

The WSIFPort has method supportsAsync to test if asynchronous operation is supported.

An asynchronous operation is initiated with the WSIFOperation method executeRequestResponseAsync. This method is designed to let an RPC method be invoked asynchronously. The method returns before the operation has completed, and the thread of execution continues.

The response to the asynchronous request is processed by one of the WSIFOperation methods fireAsyncResponse or processAsyncResponse.

To initiate the request, there are two forms of the executeRequestResponseAsync method:

public WSIFCorrelationId executeRequestResponseAsync (WSIFMessage input, WSIFResponseHandler handler)

and

public WSIFCorrelationId executeRequestResponseAsync (WSIFMessage input)

The first of these takes an input message and a WSIFResponseHandler. The WSIFResponseHandler is invoked on another thread when the operation completes. When using this method the client listener would call the fireAsyncResponse method which will call the WSIFResponseHandler executeAsyncResponse method.

Here is the Javadoc for the WSIFResponseHandler interface.

The other form of executeRequestResponseAsync that only takes a WSIFMessage input message does not use a response handler, and the client listener should process the response by calling the WSIFOperation method processAsyncResponse. This will update the WSIFMessage output and fault messages with the result of the request.

WSIF supports correlation between the request and response in the asynchronous request-response case. When the request is sent, the WSIFOperation is serialized into the WSIFCorrelationService. The executeRequestResponseAsync methods returns a WSIFCorrelationId object which identifies the serialized WSIFOperation. The client listener can use this to match a response to a particular request.

The correlation service is located with the getCorrelationService() method of the WSIFCorrelationServiceLocator class in the org.apache.wsif.utils package.

In a managed container a default correlation service is defined in the default JNDI namespace using the name: java:comp/wsif/WSIFCorrelationService . If this is not available, then WSIF will use the WSIFDefaultCorrelationService.

Here is the Javadoc for the WSIFCorrelationService interface.

and this is the correlator id:

 public interface WSIFCorrelator extends Serializable {
    public String getCorrelationId();
 }

The client must implement their own response message "listener" or MDB in order to recognize the arrival of response messages themselves. This would manage the correlation of the response message to the request and call of one of the asynchronous response processing methods. As an example of the type of thing required of a client listener, the following code fragment shows what could be in the onMessage method of a JMS listener:

public void onMessage(Message msg) {
     WSIFCorrelationService cs = WSIFCorrelationServiceLocator.getCorrelationService();
           WSIFCorrelationId cid = new JmsCorrelationId( msg.getJMSCorrelationID() );
           WSIFOperation op = cs.get( cid );
           op.fireAsyncResponse( msg );
}