Q

Difference between acknowledgement and response in JAXM

In JAXM, the synchronous messaging has two options. The receiver can respond with an acknowledgement or response. What is difference between acknowledgement and response? How do I implement it in code?
When a client transmits a message and then blocks until a response is received, the interaction is often referred to as request-response messaging. A Web service implemented as request-response must return a response to every message it receives. When the message transmitted from the client is an update request, the response from the Web service must be an acknowledgement that the update was successfully received and applied.

There are five JAXM interaction categories:
1) Asynchronous Inquiry - This interaction requires a client to transmit a request message, but does not require the client to block for a response. The client can inquire later for the response, as it wishes.
2) Asynchronous Update with Acknowledgement - This interaction requires a client to transmit a request message, but does not require the client to block for a response. The client can inquire later for an acknowledgement that the message was received.
3) Synchronous Update - This interaction requires a client to transmit a request message and block until an acknowledgement is received.
4) Synchronous Inquiry - This interaction requires a client to transmit a request message and block until a response is received.
5) Fire and Forget - This interaction requires a client to transmit a request message, but no response is expected to be returned at all.

Within JAXM, request-response handlers and acknowledgement handlers are defined by a couple of interfaces, javax.xml.messaging.OnewayListener and javax.xml.messaging.ReqRespListener. Both interfaces declare some form of a method called "onMessage". The onMessage method takes a SOAPMessage object in both interfaces, but the return types differ. The JAXMServlet will invoke the onMessage method from its doPost() method passing to it a SOAPMessage object.

A servlet, working within JAXM, should extend JAXMServlet and also implement either the javax.xml.messaging.OnewayListener interface or the javax.xml.messaging.ReqRespListener interface. An illustration of this is as follows:
public class MyServlet extends JAXMServlet 
   implements ReqRespListener 
{ 
   private SOAPMessage createSOAPResponse(SOAPMessage message) 
   { 
      SOAPMessage msg = msgFactory.createMessage(); 
      SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); 
      env.getBody() 
          .addChildElement(env.createName("TheResponse")) 
          .addTextNode("This is the response"); 
   } 

   public SOAPMessage onMessage(SOAPMessage message) 
   { 
      // do message handling here 
      return createSOAPResponse(message); 
   } 
}

This was first published in April 2003

Dig deeper on Java Web Services

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close