6

This is probably an easy question for anyone with any moderate expertise with web services using Apache Axis.

I have a web service client that was generated by wsdl2java in Axis 1.4. I am writing unit tests that need to access the actual SOAP message itself, and do a comparison to the client side java classes which are generated by Axis. (don't ask)

How can I retrieve the actual SOAP message from a response from the service?

From what I can gather from searching around is that I have to get the MessageContext. I have tried something along these lines...

MessageContext mc = MessageContext.getCurrentContext(); String message = mc.getCurrentMessage().getSOAPPartAsString();

But mc is null in this case....

Any help is appreciated!

rshepherd
  • 1,396
  • 3
  • 12
  • 21

2 Answers2

5

This is how it's done.

http://users.skynet.be/pascalbotte/rcx-ws-doc/jaxrpchandler.htm

rshepherd
  • 1,396
  • 3
  • 12
  • 21
  • 2
    Could you please expand the answer? In addition to possible link rot in the future (yay, 6 years!), the page at the link has a lot of code and it's not immediately apparent "how it's done". So a quick summary here with the relevant code snippet only (not an entire wall of code) will be very helpful! – ADTC Apr 22 '15 at 03:37
  • The link is broken, can you update the answer? – stefan-dan Jun 03 '21 at 10:29
3

When _call object is filled calling the line below gives it.

String request=_call.getMessageContext().getRequestMessage() .getSOAPPart().getEnvelope().toString();

For response use the below one

_call.getMessageContext().getResponseMessage() .getSOAPPart().getEnvelope().toString()

Call is a org.apache.axis.client.Call as you know.

Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83