How to print SOAP message contents when using Apache Axis
Asked Answered
C

3

12

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.

Custom answered 3/12, 2013 at 11:22 Comment(1)
developervisits.wordpress.com/2017/06/20/…Quintana
O
22

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.

Orchidectomy answered 10/4, 2014 at 10:30 Comment(5)
_call is an object of what type?Tonl
It's the type org.apache.axis.client.Call.Orchidectomy
How do I access to that call?Unmarked
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.Geologize
@Tonl the object _call is located most of the time inside BindingStub.java file if you generates the Objects with Apache Axis.Altorilievo
C
7

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();
}
Cinereous answered 23/5, 2017 at 18:53 Comment(1)
This is simple, yet a very important addition to the accepted answer.Geologize
T
1

Use an axis2handler and try to log the messages.

  msgcontext.getEnvelope().getBody()
Torticollis answered 3/12, 2013 at 12:20 Comment(1)
That is the axis2 configuration file.Torticollis

© 2022 - 2024 — McMap. All rights reserved.