eBay大中华区API开发者平台 开发者专区

搜 索
首页>API开发者平台>技术文档>Java SDK下的EndItem例程

技术文档

问题
Java SDK下的EndItem例程
解答
0
人觉得答案有帮助)

详细描述

EndItem例程在eBay的Java SDK框架下构建。例程中包含了两段java源代码以及一个属性文件,它可以作为一个独立的应用程序,以命令行方式运行,也可以被导入到Java IDE中,构建脚本和执行的步骤可以参见这篇知识库文章: Use Java SDK framework to execute your first Java Call

请注意:EndItem 的请求者必须是提供这一商品的卖家。 

/*
 * AppEndItem.java
 *
 */
import com.ebay.sdk.*;
import com.ebay.sdk.call.*;
import com.ebay.soap.eBLBaseComponents.*;
import com.ebay.sdk.util.eBayUtil;
import com.ebay.sdk.helper.ConsoleUtil;
import java.util.*;

 

/**
 *
 * @author zhuyang
 */
public class AppEndItem {
   
    private String configFile= "request_header_param.properties";
    private ApiContext _apiContext;
    private ApiCall _apiCall;
    private static String itemId = "110009870039";
   
    AppEndItem(){
        RequestHeaderParam requestHeaderParam = new  RequestHeaderParam();
        _apiContext = requestHeaderParam.createContext(configFile);
        _apiCall  = new com.ebay.sdk.ApiCall(_apiContext);
    }
   
    //Main method
    public static void main(String[] args) {
        AppEndItem thisapp = new AppEndItem();
        ApiLogging logging = new ApiLogging();
        thisapp._apiContext.setApiLogging(logging);
        EndItemCall request = new EndItemCall(thisapp._apiContext);
       
        // Retry
        CallRetry callretry = new CallRetry();
        callretry.setMaximumRetries(3);
        callretry.setDelayTime(1000);
       
        org.apache.axis.types.Token [] apiErrorCodes =  new org.apache.axis.types.Token[]{
            new org.apache.axis.types.Token("502"),
        };
        callretry.setTriggerApiErrorCodes(apiErrorCodes);
       
        java.lang.Class[] tcs = new java.lang.Class[]{
            java.net.SocketTimeoutException.class,
            org.apache.axis.AxisFault.class
        };
        callretry.setTriggerExceptions(tcs);
        request.setCallRetry(callretry);
        try {
            //execute the request and assign the returned eBay time to the Calendar object
           
            ItemIDType itemID = new ItemIDType(itemId);
            request.setItemID(itemID);
            request.setEndingReason(EndReasonCodeType.LostOrBroken);
            Calendar localtime =request.endItem();
            if (localtime !=null){
            String rightnow = localtime.getTime().toString();
            System.out.println("The item is ended in LocalTime :" + rightnow);
           
            TimeZone tz = TimeZone.getTimeZone("GMT");
            java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
            fmt.setTimeZone(tz);
            fmt.setCalendar(localtime);
           
            Date date = localtime.getTime();
            String timeStr = fmt.format(date);
            System.out.println("the item is end in GMT time " +timeStr );
            }     
        }catch (Exception e) {
            if ( e instanceof SdkSoapException ) {
                SdkSoapException sdkSoapExe = (SdkSoapException)e;
                ErrorType error = sdkSoapExe.getErrorType();
                System.out.println("error code: " +error.getErrorCode()+ ", error shot message :"
                        + error.getShortMessage());
            }
            if (e instanceof ApiException ){
                ApiException apiExe = (ApiException)e;
                ErrorType[] errs = apiExe.getErrors();
                for (int i=0; i<errs.length; i++){
                    ErrorType error = errs[i];
                    System.out.println("error code " +error.getErrorCode()+ "error shot message"
                            + error.getShortMessage());
                }
            }  
        }
    }
}


===============

 


/*
 * RequestHeaderParam.java
 *
 * Created on March 13, 2006, 5:32 PM
 * @author zhuyang
 */

 

import com.ebay.sdk.*;
import com.ebay.soap.eBLBaseComponents.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class RequestHeaderParam {
    public RequestHeaderParam(){
    }
    public ApiContext createContext(String file){
        //Load the properties file into a Properties object
       Properties config = new Properties();
       try {
  config.load(new FileInputStream( file));
 } catch (IOException e) {
   System.out.println("config.properties file is missing from the current working directory.");
   return null;
 }      
        ApiContext context = new ApiContext();
        ApiCredential credential= context.getApiCredential();
        credential.seteBayToken(config.getProperty("token") );
       
        // add ApiCredential to ApiContext  
        String siteList = config.getProperty("apiServer");
        context.setApiServerUrl(siteList);
        return(context);
    }
}

属性文件
===============

# request_header_param.properties
# api sandbox apiServer URL
apiServer=https://api.sandbox.ebay.com/wsapi
# site for the api request route to
siteid=US
# Api Version
version=485
# application keys
devid=
appid=
cert=
# the requester's Auth & Auth token
token=
# the requester's userId
userid=


版本信息

例程基于下列的具体版本:

API Schema Version 483
Java SDK Version javasdk v483.0 Point release

Additional Resource

 


答案对您有帮助吗?

是,对我很有帮助
否,没解决我的问题