Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

AXIS2 Asynchronous non-blocking innovation techniques

1) Do a Non-Blocking Invocation Source: http://axis.apache.org/axis2/java/core/docs/adv-userguide.html The stubs also include a method that allows you to do a non-blocking innovation. For each method in the Service, there will be a method start<method-name>. These methods accept a callback object, which would be called when the response is received. Sample code that does an asynchronous interaction is given below.

try { org.apache.axis2.userguide.Axis2SampleDocLitServiceStub stub = new org.apache.axis2.userguide.Axis2SampleDocLitServiceStub(null, "http://localhost:8080/axis2/services/Axis2SampleDocLitService"); //implementing the callback online org.apache.axis2.userguide.Axis2SampleDocLitServiceCallbackHandler callback = new org.apache.axis2.userguide.Axis2SampleDocLitServiceCallbackHandler() { public void receiveResultechoString( org.apache.axis2.userguide.xsd.EchoStringReturnDocument resDoc) { System.out.println(resDoc.getEchoStringReturn()); } }; org.apache.axis2.userguide.xsd.EchoStringParamDocument reqDoc = org.apache.axis2.userguide.xsd.EchoStringParamDocument.Factory.newInstance( ); reqDoc.setEchoStringParam("Axis2 Echo"); stub.startechoString(reqDoc, callback); } catch (java.rmi.RemoteException e) { e.printStackTrace(); }

Even though the above code does a non-blocking invocation at the client API, the transport connection may still operate in a blocking fashion. For example, a single HTTP connection can be used to create a Web Service request and to get the response when a blocking invocation happens at the transport level. To perform a "true" non-blocking invocation in which two separate transport connections are used for the request and the response, please add the following code segment after creating the stub. It will force Axis2 to use two transport connections for the request and the response while the client uses a Callback to process the response.

stub._getServiceClient().engageModule(new QName("addressing")); stub._getServiceClient().getOptions().setUseSeparateListener(true);

Once those options are set, Axis2 client does the following: 1. Starts a new Transport Listener(Server) at the client side. 2. Sets the address of the Transport Listener, as the ReplyTo WS-Addressing Header of the request message 3. According to the WS-Addressing rules, the Server will process the request message and send the response back to the ReplyTo address. 4. Client accepts the response, processes it and invokes the callback with the response parameters.

2) In-Out, asynchronous HTTP as one-way transport Source : http://onjava.com/pub/a/onjava/2005/07/27/axis2.html?page=4 OMElement payload = .... Call call = new Call(); call.setTo( new EndpointReference(AddressingConstants.WSA_TO, "HTTP://...)); call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true); Callback callback = new Callback() { public void onComplete(AsyncResult result) { .... } public void reportError(Exception e) { ... } }; call.engageModule(new Qname("addressing")); call.invokeNonBlocking(operationName.getLocalPart(), method, callback);

In this case, the SOAP messages travel through two HTTP connections, addressing is mandatory, and the presence of the ReplyTo header instructs the server to send the response in a separate channel. The client does not block, and when the response message arrives, the callback is invoked.

You might also like