+

Search Tips   |   Advanced Search


Invoking a WSDL-based Web service through the WSIF API >

WSIFOperation - Asynchronous interactions reference


The Web Services Invocation Framework (WSIF) supports 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.

Asynchronous operation is supported by the WSIF providers for SOAP over JMS and native JMS.

The WSIFPort class uses the supportsAsync method to test if asynchronous operation is supported.

An asynchronous operation is initiated with the WSIFOperation interface executeRequestResponseAsync method. This method lets a Remote Procedure Call (RPC) method be invoked asynchronously. The method returns before the operation is completed, and the thread of execution continues.

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

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)

executeRequestResponseAsync(WSIFMessage input, WSIFResponseHandler handler)

This method takes an input message and a WSIFResponseHandler handler. The handler is invoked on another thread when the operation completes. When using this method the client listener calls the fireAsyncResponse method, which then calls the WSIFResponseHandler interface executeAsyncResponse method.

See about the WSIFResponseHandler interface (/wsi/org/apache/wsif/WSIFResponseHandler.html), see the generated API information for additional APIs.

executeRequestResponseAsync(WSIFMessage input)

This method only takes an input message, and does not use a response handler. The client listener processes the response by calling the WSIFOperation interface processAsyncResponse method. This process updates the WSIFMessage output and fault messages with the result of the request.

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

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

In a managed container a default correlation service is defined in the default Java Naming and Directory Interface (JNDI) namespace using the name: java:comp/wsif/WSIFCorrelationService. If this correlation service is not available, then WSIF uses the WSIFDefaultCorrelationService.

See about the WSIFCorrelationService interface (/wsi/org/apache/wsif/WSIFCorrelationService.html) see the generated API information for additional APIs.

This is the correlator ID:

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

The client must implement its own response message listener or message data base so that it can recognize the arrival of response messages. This client implementation manages the correlation of the response message to the request and call of one of the asynchronous response processing methods. As an example of the requirement for a client listener, the following code fragment shows what can 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 );
}




 

Related


WSIFOperation - Context
WSIFOperation - Synchronous and asynchronous timeouts reference
Generated API information for additional APIs
Linking a WSIF service to a JMS-provided service
WSIFOperation interface