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

Exception-based logging using eBay JAVA SDK

  • Answer ID 1518
  • Published 12/10/2009 08:18 PM
  • Updated 10/20/2013 06:41 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=1518

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   }

     }}

 

Version Info

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

Java SDK Version javasdk v639 Full release

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter