Skip to main content
Published: December 10 2009, 9:18:00 PMUpdated: August 11 2022, 1:58:42 PM

Exception-based payload logging using the eBay JAVA SDK

Summary

   With the eBay Java SDK, you can enable exception-based payload logging and only log API SOAP requests and responses based on pre-registered API error codes, SDK exceptions and /or HTTP Status .


Detailed Description


   The sample project below illustrates on how to set all three exception filters in JAVA SDK.

import com.ebay.sdk.*;
import com.ebay.sdk.call.GeteBayDetailsCall;
import com.ebay.sdk.logging.CallMetrics;
import com.ebay.soap.eBLBaseComponents.*;

public class GeteBayDetailsExceptionLogging {

    private static ApiContext apiContext;
    private static ApiLogging logging ;
    private CallRetry callretry;
    private static String TOKEN = "";
    private static String APISERVERURL = "https://api.sandbox.ebay.com/wsapi";

      GeteBayDetailsExceptionLogging() {
       
           apiContext = new ApiContext();     
           logging = new ApiLogging();
           // Retry object
           callretry = new CallRetry();
           callretry.setMaximumRetries(3);
           callretry.setDelayTime(1000);


           // assign the Api error code of interest 
           String [] apiErrorCodes = new  String[]{
                "10007",
                "931"
           };
          callretry.setTriggerApiErrorCodes(apiErrorCodes);
        

           // assign the Exception classes of interest to Class array object
           java.lang.Class[] tcs = new java.lang.Class[]{
                 java.net.SocketTimeoutException.class,
                 com.ebay.sdk.SdkSoapException.class   
           };
           callretry.setTriggerExceptions(tcs);

          // assign Http Status Codes

          int[] httpErrorCode = { 502};


          com.ebay.sdk.ExceptionFilter excfilter = new com.ebay.sdk.ExceptionFilter();  
          excfilter.setTriggerApiErrorCodes(apiErrorCodes);
          excfilter.setTriggerExceptions(tcs);
          excfilter.setTriggerHTTPErrorCodes(httpErrorCode);

          // register Exception filter 
          logging.setMessageLoggingFilter(excfilter);
          logging.setLogExceptions(true);
          apiContext.setApiLogging(logging); 
    }

    public static void main(String[] args) {
        
          GeteBayDetailsExceptionLogging  gbdel= new GeteBayDetailsExceptionLogging ();
       
          ApiCredential cred = new ApiCredential();
          apiContext.setApiCredential(cred);
          //set api call credential
          apiContext.getApiCredential().seteBayToken(TOKEN);
  
          apiContext.setApiServerUrl(APISERVERURL);


          GeteBayDetailsCall api = new GeteBayDetailsCall(gbdel.apiContext);
          try {
                api.geteBayDetails();
          } catch (Throwable e) {         //  handle the exception here   }

     }}

 

 

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