For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Product
Category
Language
Format
SDK
Sort by
Direction

Log JAVA SOAP request and response message

  • Answer ID 1088
  • Published 06/18/2007 06:57 AM
  • Updated 10/20/2013 06:41 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=1088
Product
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
File Attachments

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter