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.
Can someone tell me what I'm doing wrong?
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