How to print SOAP message contents when using Apache Axis

26,006

Solution 1

You probably don't need this answer anymore, but stays here for anyone else that ends right up here with the same problem.

The easiest way to retrieve both the request and the response is to get them from the call you are making. In the axis generated stub, after invoking a call do this:

String requestXML = _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
String responseXML = _call.getMessageContext().getResponseMessage().getSOAPPartAsString();

Hope it helps. It helped me when I needed to print the request too.

Solution 2

I was having trouble figuring this out as well. The problem for me was my _call.invoke() was failing. I was able to surround this in a try-catch clause and still get the request message for debugging:

Example:

try{
    _call.invoke();
catch(Exception e){
    _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
}

Solution 3

Use an axis2handler and try to log the messages.

  msgcontext.getEnvelope().getBody()
Share:
26,006
R11G
Author by

R11G

Updated on July 05, 2022

Comments

  • R11G
    R11G almost 2 years

    I am using Apache Axis for web service automation.

    I am preparing SOAP requests via Axis and hitting the web service further. What I am looking for is how to print the SOAP request content which is getting compiled and hitting the webservice.

    I found that log4j can help but I am struggling how to use it.

  • Ratha
    Ratha over 10 years
    That is the axis2 configuration file.
  • Eric
    Eric over 8 years
    _call is an object of what type?
  • Paulo Rodrigues
    Paulo Rodrigues over 8 years
    It's the type org.apache.axis.client.Call.
  • Roberto Rodriguez
    Roberto Rodriguez over 7 years
    How do I access to that call?
  • Abhishek Singh
    Abhishek Singh about 6 years
    This is simple, yet a very important addition to the accepted answer.
  • Abhishek Singh
    Abhishek Singh about 6 years
    As mentioned in the answer given by Brian, if your call is failing in invoke itself, wrap that in a try catch block and get the message.
  • Jairo Martínez
    Jairo Martínez over 4 years
    @Eric the object _call is located most of the time inside BindingStub.java file if you generates the Objects with Apache Axis.