Amazon Product Advertising API request with Java

1.7k Views Asked by At

Hi My code for the same is

// Initialize Web Service
            HandlerResolver handlerResolver=new AwsHandlerResolver(credentials.getAWSSecretKey());
            AWSECommerceService service = new AWSECommerceService();
            service.setHandlerResolver(handlerResolver); 
            // Create Web Service Connection
            AWSECommerceServicePortType port = service.getAWSECommerceServicePort();

            // Add Parameters for the Item Lookup
            ItemLookupRequest itemLookup = new ItemLookupRequest();
            itemLookup.setIdType("ASIN");
            itemLookup.getItemId().add("B000RE216U");

            // Wrap Request in Lookup Body 
            ItemLookup lookup = new ItemLookup();
            lookup.setAWSAccessKeyId(credentials.getAWSAccessKeyId());
            lookup.getRequest().add(itemLookup);

            ItemLookupResponse response = port.itemLookup(lookup);

            System.out.println("response: " + response.toString());

I keep getting the error cannot convert from Void to AWSECommerceService in the beginning. I have the AWSHandlerResolver file and codec jar installed and configured.

Error Message:

Exception in thread "main" javax.xml.ws.WebServiceException: {http://webservices.amazon.com/AWSECommerceService/2010-11-01}AWSECommerceService is not a valid service. Valid services are: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}AWSECommerceService
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:223)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
    at javax.xml.ws.Service.<init>(Service.java:77)
    at com.ECS.client.jax.AWSECommerceService.<init>(AWSECommerceService.java:46) 

I have been searching online. I might have to change target namespace for AWSECommerceService. But cannot find how. Please help me

1

There are 1 best solutions below

3
On

You are using the wrong namespace (actually, the wrong version of WS) for your Webservice client and its port.

Go to AWSECommerceService and AWSECommerceServicePortType classes and replace all namespaces which look like http://webservices.amazon.com/AWSECommerceService/2010-11-01 with http://webservices.amazon.com/AWSECommerceService/2013-08-01.