I do not use the SOAP API, but your Bounty requirements did not state that he should use SOAP only for what you wanted to call Amazon and get the results. So, I will publish this working example using the REST API, which will at least fulfill your stated requirements:
I need a working code code that gets to the amazon server and returns the results
To fulfill the signature requirements you need to download the following:
http://associates-amazon.s3.amazonaws.com/signed-requests/samples/amazon-product-advt-api-sample-java-query.zip
Unzip it and take the com.amazon.advertising.api.sample.SignedRequestsHelper.java file and put it directly into your project. This code is used to sign the request.
You will also need to download the Apache Commons Codec 1.3 from the following and add it to your class path, that is, add it to your project library. Please note that this is the only version of the codec that will work with the above class ( SignedRequestsHelper )
http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.3.zip
Now you can copy and paste the following to replace your.pkg.here with the correct package name and replace the SECRET and KEY properties:
package your.pkg.here; import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringWriter; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { private static final String SECRET_KEY = "<YOUR_SECRET_KEY>"; private static final String AWS_KEY = "<YOUR_KEY>"; public static void main(String[] args) { SignedRequestsHelper helper = SignedRequestsHelper.getInstance("ecs.amazonaws.com", AWS_KEY, SECRET_KEY); Map<String, String> params = new HashMap<String, String>(); params.put("Service", "AWSECommerceService"); params.put("Version", "2009-03-31"); params.put("Operation", "ItemLookup"); params.put("ItemId", "1451648537"); params.put("ResponseGroup", "Large"); String url = helper.sign(params); try { Document response = getResponse(url); printResponse(response); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } private static Document getResponse(String url) throws ParserConfigurationException, IOException, SAXException { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(url); return doc; } private static void printResponse(Document doc) throws TransformerException, FileNotFoundException { Transformer trans = TransformerFactory.newInstance().newTransformer(); Properties props = new Properties(); props.put(OutputKeys.INDENT, "yes"); trans.setOutputProperties(props); StreamResult res = new StreamResult(new StringWriter()); DOMSource src = new DOMSource(doc); trans.transform(src, res); String toString = res.getWriter().toString(); System.out.println(toString); } }
As you can see, this is much easier to configure and use than in the SOAP API. Unless you have a specific requirement for using the SOAP API, I would highly recommend using the REST API instead.
One of the drawbacks of using the REST API is that the results are not decoupled into objects for you. This could be fixed by creating the necessary classes based on wsdl.