0

I'm trying to use the Ebay trading API using JAX-WS. (yes, i know there's an SDK for the trading API webservice, but I'm trying to avoid using it, since the other Ebay APIs don't have an SDK. Doesn't make sense for me to code half my program using an SDK)

https://go.developer.ebay.com/api-documentation

First, I created JAX-WS stubs using wsimport, then I created the jar file. I was following this documentation: http://java.boot.by/ocewsd6-guide/ch06.html

I'm trying to call the GetSessionID function. The documentation is here: http://developer.ebay.com/Devzone/XML/docs/Reference/eBay/GetSessionID.html

I was able to get this far:
ebay.apis.eblbasecomponents.EBayAPIInterfaceService eais = new ebay.apis.eblbasecomponents.EBayAPIInterfaceService();

        ebay.apis.eblbasecomponents.EBayAPIInterface eport= eais.getEBayAPI();

        //here, need to build a request
        ebay.apis.eblbasecomponents.GetSessionIDRequestType gsr = new GetSessionIDRequestType();
        gsr.setRuName(runame);

        //http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/twbs_cookiejaxws.html
        // Set up the Map that will contain the request headers.
        Map<String, Object> req_ctx = ((BindingProvider)eport).getRequestContext();
        req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://api.ebay.com/ws/api.dll");

//        req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://api.ebay.com/wsapi");

        Map<String, List<String>> headers = new HashMap<String, List<String>>();
        headers.put("runame", Collections.singletonList("BLAHBLAH"));
        headers.put("X-EBAY-API-COMPATIBILITY-LEVEL", Collections.singletonList("907"));
        headers.put("X-EBAY-API-DEV-NAME", Collections.singletonList("BLAHBLAH"));
        headers.put("X-EBAY-API-APP-NAME", Collections.singletonList("BLAHBLAH"));
        headers.put("X-EBAY-API-CERT-NAME", Collections.singletonList("BLAHBLAH"));
        headers.put("X-EBAY-API-CALL-NAME", Collections.singletonList("GetSessionID"));
        headers.put("X-EBAY-API-SITEID", Collections.singletonList("US"));
        headers.put("Content-Type", Collections.singletonList("text/xml"));


        req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);


        GetSessionIDResponseType gsResponse = eport.getSessionID(gsr);

But then, I get the error below.

  1. Can someone tell me what I'm doing wrong?

  2. Better yet, can anyone generate sample code to call this API?

Error:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:363)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: com.sun.xml.internal.ws.protocol.soap.MessageCreationException: Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {urn:ebay:apis:eBLBaseComponents}GetSessionIDResponse
    at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:304)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:268)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:217)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:130)
    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:124)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:1121)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:1035)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:1004)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:862)
    at com.sun.xml.internal.ws.client.Stub.process(Stub.java:448)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:178)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
    at com.sun.proxy.$Proxy35.getSessionID(Unknown Source)
    at Ebluna.main(Ebluna.java:101)
    ... 11 more
Caused by: com.sun.xml.internal.ws.streaming.XMLStreamReaderException: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {urn:ebay:apis:eBLBaseComponents}GetSessionIDResponse
    at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.verifyTag(XMLStreamReaderUtil.java:261)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:205)
    at com.oracle.webservices.internal.impl.encoding.StreamDecoderImpl.decode(StreamDecoderImpl.java:49)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:234)
    at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:151)
    at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:299)
    ... 26 more
Exception running application Ebluna
Cray
  • 2,774
  • 7
  • 22
  • 32
NL3294
  • 984
  • 1
  • 10
  • 27

1 Answers1

1

The caused-by exception is a big clue. Because you're using a JAX-WS client created from a WSDL, the runtime is expecting a SOAP xml response with a root xml element of <Envelope> but is instead getting a <GetSessionIDResponse> as root element in the HTTP response.

Per the eBay trading API docs, they have a plain xml-over-http endpoint and a SOAP-over-http endpoint url. Since you're using SOAP, you need to use only the SOAP endpoint URL; your code is actually specifying both endpoints (luckily last one wins and you're actually using the right one - but you don't need to set the endpoint twice): https://api.ebay.com/wsapi

I believe the reason you may be getting a non-SOAP response may be because of the HTTP headers you are passing. The docs say these are only for use with the non-SOAP endpoint; yet you are using the SOAP endpoint and passing them anyways. For the SOAP interface you're supposed to pass these params as URL query string parameters on the endpoint URL.

For example:

Example: Specifying Routing Information in the Request URL
// Define the endpoint (e.g., the Sandbox Gateway URI)      
String endpoint = "https://api.sandbox.ebay.com/wsapi";
// Define the query string parameters.
String queryString = "?callname=AddItem"
                                        + "&siteid=0"
                                        + "&appid=myappid"
                                        + "&version=349";
                                        + "&Routing=new";

String requestURL  = endpoint + queryString;
EBayAPIInterfaceServiceLocator  sl = new EBayAPIInterfaceServiceLocator();
EBayAPIInterface       privBinding = sl.geteBayAPI(new URL(requestURL));
((EBayAPISoapBindingStub)privBinding).setTimeout(60000);
Scott Heaberlin
  • 3,364
  • 1
  • 23
  • 22
  • Ok, so we use Soap instead of the XML syntax. How do I set the header? For the GetSessionID call, it says that we need requester credentials. http://developer.ebay.com/Devzone/XML/docs/Reference/eBay/GetSessionID.html I see documentation on setting query strings via the query string, and POST header. But the SOAP envelope header, I'm not sure of. http://developer.ebay.com/DevZone/guides/ebayfeatures/Basics/Call-StandardCallData.html#AuthenticatingwithaFullKeysetandSessionI – NL3294 Mar 14 '15 at 20:18
  • There are JAX-WS APIs for updating the soap Header: http://stackoverflow.com/questions/10654608/add-soap-header-object-using-pure-jax-ws – Scott Heaberlin Mar 14 '15 at 20:39
  • That's it. Thank you. I was new to JAX-WS, so I got confused with the XML versus SOAP versions of the web service. When you told me that it was the SOAP version, I got on the right track. And that other link worked for me. – NL3294 Mar 17 '15 at 07:03