Skip to main content
Published: June 10 2009, 10:20:00 AMUpdated: November 28 2020, 1:45:46 PM

Summary  

   This sample project illustrates on how to use JAVA JAX-WS framework to execute GeteBayOfficialTime Trading SOAP request.   For using this sample you must have got your Sandbox or Production key set that includes three IDs (DevID, AppID, and CertID) and an eBay User Token.  
  

   Attached to this article is the zipped project.


 Detailed Description 

    SOFTWARE REQUIREMENTS

      1. JAXWS2.1.5 or higher

         - set the JWSDP_HOME system variable to point to the JAXWS2.1.5 installation directory.

      2. JDK 1.5 or higher

 

    INSTRUCTIONS

           1. Download and unzip the attachched project file : Trading_JAX-WS_SOAP_Client.zip

           2. Build Trading API SOAP Stub

      > ant -f  ${Trading_JAXWS_Client_HOME}/codeGen.xml

           3. Build and run the Trading GeteBayOfficialTime API request

    -  edit ${Trading_JAXWS_Client_HOME}/samples/AppGeteBayOfficialTime/src/ebay/dts/AppGeteBayOfficialTime.java and specify  m_TOKEN, m_APPID and m_TRADING_API_URL properties.

    - build  and run the AppGeteBayOfficialTime  project:

          > ant -f  ${Trading_JAXWS_Client_HOME}/AppGeteBayOfficialTime/build.xml

 

    MAIN CODE

/*
* © 2009-2013 eBay Inc., All Rights Reserved
* Licensed under CDDL 1.0 -  http://opensource.org/licenses/cddl1.php
*/

import ebay.apis.eblbasecomponents.* ;
import java.util.*; 
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.ws.*;

/**
*
* @author zhuyang
*/
public class AppGeteBayOfficialTime {

    /**
     * @param args the command line arguments
     */
     static String m_TOKEN = "YOUR USER TOKEN";
     static String m_APPID = "YOUR APPID";
     static String m_TRADING_API_URL = "https://api.sandbox.ebay.com/wsapi";
      static String m_siteId = "0";
     static String m_version = "825"; 

     public static void main(String[] args) {
         System.out.println("Starting  AppGeteBayOfficialTime.main ....");
         BindingProvider bp=null;
         String callName = "GeteBayOfficialTime";
        try {
               // Call Web Service Operation 
            EBayAPIInterfaceService service = new EBayAPIInterfaceService(); 
            EBayAPIInterface port = service.getEBayAPI();
            bp = (BindingProvider) port;

            Map requestProperties = bp.getRequestContext();
            String endpoint = m_TRADING_API_URL +
                    "?callname=" + callName +
                    "&siteid=" + m_siteId +
                    "&appid=" + m_APPID +
                    "&version=" + m_version;
            // set server http address
            requestProperties.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);

            // set http headers
            Map<String, List<String>> httpHeaders = new HashMap<String, List<String>>();
            httpHeaders.put("Accept-Encoding", Collections.singletonList("gzip"));
            requestProperties.put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);

            //set RequesterCredentials SOAP Header
            // <RequesterCredentials soapenv:mustUnderstand="0" xmlns="urn:ebay:apis:eBLBaseComponents">
            // 1. create CustomeSecurityHeaderType object
            CustomSecurityHeaderType auth = new CustomSecurityHeaderType();
            // 2. specify eBayAuthToken 
            auth.setEBayAuthToken(m_TOKEN);
            // 3. register the CustomeSecurityHeaderType object into javax.xml.ws.Holder object 
            Holder holder = new Holder<CustomSecurityHeaderType>(auth);

            // create eBay API request object
            GeteBayOfficialTimeRequestType request = new GeteBayOfficialTimeRequestType();
            // set a property for the API object
            geteBayOfficialTimeRequest.setVersion(m_version); 
            
           GeteBayOfficialTimeResponseType result = port.geteBayOfficialTime(request, holder);


           XMLGregorianCalendar xmlCal=       result.getTimestamp();
           java.util.Calendar timestamp =xmlCal.toGregorianCalendar();
           String timeStr = convertToGMTString(timestamp);
           System.out.println("eBay official time in GMT: " +timeStr);

           System.out.println("Finishing  AppGeteBayOfficialTime.main ....");

        } catch (Exception ex) {
            
            //  handle custom exceptions here
            //  ex.printStackTrace();
        }

    }
}

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