Home

 

Asynchronous message exchange client

By default, asynchronous client invocations do not have asynchronous behavior of the message exchange pattern on the wire. The programming model is asynchronous; however, the exchange of request or response messages with the server is not asynchronous. IBM has provided a feature that goes beyond the JAX-WS specification to provide the asynchronous message exchange support.

In the asynchronous message exchange case, the client listens on a separate HTTP channel to receive the response messages from a service-initiated HTTP channel. The client uses WS-Addressing to provide the ReplyTo endpoint reference (EPR) value to the service. The service initiates a connection to the ReplyTo EPR to send a response.To use an asynchronous message exchange, the com.ibm.websphere.webservices.use.async.mep property must be set on the client request context with a boolean value of true. When this property is enabled, the messages exchanged between the client and server are different from messages exchanged synchronously.

To create an asynchronous message exchange client, do the following steps:

Create the BankCallbackMEPClient class in the itso.rad75.bank.test package and copy/paste the code from C:\7672code\webservice\thinclient (Example | 8-18).

Example 18-18 BankCallbackMEPClient

package itso.rad75.bank.test;
import itso.rad75.bank.model.simple.BankPortProxy;
import java.util.concurrent.Future;
import javax.xml.ws.BindingProvider;
public class BankCallbackMEPClient {
	
	public static void main(String[] args) throws Exception {
		BankPortProxy proxy = new BankPortProxy();
		//proxy._getDescriptor().setEndpoint
				("http://localhost:11487/RAD75WebServiceWeb/BankService");
		// setup the property for asynchronous message exchange
		BindingProvider bp = (BindingProvider)
										proxy._getDescriptor().getProxy();
		bp.getRequestContext().put
			("com.ibm.websphere.webservices.use.async.mep", Boolean.TRUE);
		// Set up the callback handler.
		RetrieveCustomerCallbackHandler callbackHandler = 
									new RetrieveCustomerCallbackHandler();
		// Make the Web service call.
		Future<?> response = proxy.retrieveCustomerNameAsync
											("111-11-1111", callbackHandler);
		System.out.println("Wait 5 seconds.");
		// Give the callback handler a chance to be called. 
		Thread.sleep(5000);
		System.out.println("Customer's full name is " 
									+ callbackHandler.getResponse() + ".");
		System.out.println("RetrieveCustomerName async end.");
		}
}

Right-click BankCallbackMEPClient.java and select Run As Æ Java Application. The output is written to the console:

[WAShttpAsyncResponseListener] listening on port 4070

Wait 5 seconds.

Customer's full name is Mr. Henry Cui.

RetrieveCustomerName async end.

Notice the new line in the WebSphere Application Server Console:

[...] 00000090 WSChannelFram A CHFW0019I: The Transport Channel

Service has started chain HttpOutboundChain:9.48.61.46:4070.

If you are interested to see the SOAP request message, you can activate the comment line:

proxy._getDescriptor().setEndpoint

("http://localhost:11487/RAD75WebServiceWeb/BankService");

Note that the port 11487 must match the port of the TCP/IP Monitor.

Run the application again. The SOAP request is shown in Example | 8-19.

Example 18-19 SOAP request for asynchronous message exchange

<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
	<wsa:To>http://localhost:11487/RAD75WebServiceWeb/BankService</wsa:To>
	<wsa:ReplyTo>
	 | lt;wsa:Address>http://9.48.61.46:4597/axis2/services/BankService.BankPort
	 | lt;/wsa:Address>
	</wsa:ReplyTo>
	<wsa:MessageID>urn:uuid:57A98210F9B1DA90111228429634645</wsa:MessageID>
	<wsa:Action>urn:getCustomerFullName</wsa:Action>
</soapenv:Header>
<soapenv:Body>
	<ns2:RetrieveCustomerName
					xmlns:ns2="http://simple.model.bank.rad75.itso/">
		<ssn>111-11-1111</ssn>
	</ns2:RetrieveCustomerName>
</soapenv:Body>
</soapenv:Envelope>

Because the client listens on a separate HTTP channel to receive the response messages from a service-initiated HTTP channel, the TCP/IP Monitor is not able to capture the SOAP response.
ibm.com/redbooks