Skip to main content
Published: June 18 2007, 6:57:00 AMUpdated: November 28 2020, 3:48:48 PM

How do I log my JAVA SOAP request and response?

Summary

   When make a SOAP request  via Apache Axis generated eBay SOAP APIs and stubs, you can use org.apache.axis.Message  and org.apache.commons.logging.Log   APIs to log SOAP request and response messages. 


 Detailed Description

   To use the sample, you need to use Apache Axis wsdj2java tool to generate Java code stubs against eBay API WSDL .  

     Here are the Axis Client Handler LogMessages and getLog methods that use XMLUtils to convert a given SOAP message to Java String object and print the message out with org.apache.commons.logging.Log  API.

    The complete source code can be downloaded below.

  private static org.apache.commons.logging.Log apiLog = LogFactory.getLog(ClientCredentialHandler.class);
  private static  Message req ;

 public static void getLog(){ 
        LogMessage("Request", req.getMessageContext().getRequestMessage());
        LogMessage("Response",req.getMessageContext().getResponseMessage());
 }
 private static void LogMessage(String msgName, org.apache.axis.Message msg) {
        try {
            if (msg ==null ){           
                return;
            }else {
                String s = XMLUtils.DocumentToString(
                        msg.getSOAPEnvelope().getAsDocument());            
                String hs = java.text.MessageFormat.format("{0} Message: Length={1}",
                        new Object[] {msgName, new Integer(s.length())}
                );         
                System.out.println("LogMessage : " + hs);
                apiLog.info(hs);
                apiLog.info(s);
            }
        } catch(Exception e) {
            e.printStackTrace();
            apiLog.info("ClientCredentialHandler: failed to log SOAP message.");
        }
    }
   


 Version Info

The code example above was based on the versions specified below:

API Schema Version515

How well did this answer your question?
Answers others found helpful