Pages

Saturday, June 9, 2012

Accessing Request and Response from Stub using Axis

Hi All,

This is for people working on Web Services and SOA field.
Coming right away to the point, while invoking an operation of a Web-Service (SOAP based), if we need to get the Request and Response including Header and Body, that is, whole SOAP-Envelope we can follow the following approach:

String response= stub._getServiceClient().getLastOperationContext().getMessageContext("Out").getEnvelope().toString();

String request= stub._getServiceClient().getLastOperationContext().getMessageContext("In").getEnvelope().toString(); 

This means we can create a Stub at our Service Implementation level and after calling the Service(Note : If using the above before Service then the Message Context will be Null) we can use the above command to get the request and response.

This is useful for those who want to analyze the SOAP-Envelope. Here SOAP-Envelope includes <....>soap header apart from Custom Header if any.(soap body is obvious). Here <..>header contains UsernamePassword or generally some security related info.

We can also specifically get Body( .getBody()) and Header (.getHeader()).

Hope this will be useful for some needy.