Note that there are some explanatory texts on larger screens.

plurals
  1. POAmazon Product Advertising API signed request with Java
    text
    copied!<p>after many hours of tinkering and reading the whole internet several times I just can't figure out how to sign requests for use with the Product Advertising API.</p> <p>So far I managed to generate a client from the provided WSDL file. I used a tutorial by Amazon for this. You can find it here:</p> <p><a href="http://docs.amazonwebservices.com/AWSECommerceService/latest/GSG/index.html?YourDevelopmentEnvironment.html" rel="nofollow noreferrer">Tutorial for generating the web service client</a></p> <p>So far no problems. To test the client I wrote a small piece of code. The code is intended to simply get some information about a product. The product is specified by its ASIN.</p> <p>The code:</p> <pre><code>package client; import com.ECS.client.jax.AWSECommerceService; import com.ECS.client.jax.AWSECommerceServicePortType; import com.ECS.client.jax.ItemLookup; import com.ECS.client.jax.ItemLookupResponse; import com.ECS.client.jax.ItemLookupRequest; public class Client { public static void main(String[] args) { System.out.println("API Test startet"); AWSECommerceService service = new AWSECommerceService(); AWSECommerceServicePortType port = service.getAWSECommerceServicePort(); ItemLookupRequest itemLookup = new ItemLookupRequest(); itemLookup.setIdType("ASIN"); itemLookup.getItemId().add("B000RE216U"); ItemLookup lookup = new ItemLookup(); lookup.setAWSAccessKeyId("&lt;mykeyishere&gt;"); lookup.getRequest().add(itemLookup); ItemLookupResponse response = port.itemLookup(lookup); String r = response.toString(); System.out.println("response: " + r); System.out.println("API Test stopped"); } } </code></pre> <p>As you can see there is no part where I sign the request. I have worked my way through a lot of the classes used and found no methods for signing the request.</p> <p>So, how to sign a request?</p> <p>I actually found something in the documentation: <a href="http://docs.amazonwebservices.com/AWSECommerceService/2009-11-01/DG/" rel="nofollow noreferrer">request authentication</a></p> <p>But they don't use their own API. The proposed solutions are more or less for manual use only. So I looked in the client classes to sort out if I could get the request URL and put all the parts needed for request signing in myself. But there are no such methods.</p> <p>I hope someone can point out what I am doing wrong.</p> <hr> <p>This is what I did to solve the problem. All the credit goes to <a href="https://stackoverflow.com/users/84539/jon">Jon</a> and the guys of the Amazon forums.</p> <p>Before I outline what I did, here is a link to the post which helped me to solve the problem: <a href="http://developer.amazonwebservices.com/connect/message.jspa?messageID=143124" rel="nofollow noreferrer">Forum Post on Amazon forums</a>.</p> <p>I downloaded the awshandlerresolver.java which is linked in the post. Than I modified my own code so it looks like this:</p> <pre><code>package client; import com.ECS.client.jax.AWSECommerceService; import com.ECS.client.jax.AWSECommerceServicePortType; import com.ECS.client.jax.ItemLookup; import com.ECS.client.jax.ItemLookupResponse; import com.ECS.client.jax.ItemLookupRequest; public class Client { public static void main(String[] args) { System.out.println("API Test startet"); AWSECommerceService service = new AWSECommerceService(); service.setHandlerResolver(new AwsHandlerResolver("&lt;Secret Key&gt;")); // important AWSECommerceServicePortType port = service.getAWSECommerceServicePort(); ItemLookupRequest itemLookup = new ItemLookupRequest(); itemLookup.setIdType("ASIN"); itemLookup.getItemId().add("B000RE216U"); ItemLookup lookup = new ItemLookup(); lookup.setAWSAccessKeyId("&lt;Access Key&gt;"); // important lookup.getRequest().add(itemLookup); ItemLookupResponse response = port.itemLookup(lookup); String r = response.toString(); System.out.println("response: " + r); System.out.println("API Test stopped"); } } </code></pre> <p>The println on the end are more or less useless. But it works. I also used the WSDL Jon linked to generate a new webservice client. I just changed the URLs in the tutorial I posted in my question.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload