Amazon Product Advertising API signed request with Java

半腔热情 提交于 2019-11-30 00:24:39

Try this afer you create the service

service.setHandlerResolver(new AwsHandlerResolver(my_AWS_SECRET_KEY));

You'll need this class and this jar file to add as a reference to your project as AwsHandlerResolver uses Base64 encoding.

You'll need to rename the AwsHandlerResolver file to the name of the class as the file name is all lower case.

I think the rest of the code you have is fine.

The WSDL is http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl

This discussion and the related Amazon post helped me get the client working. That being said, I felt that the solution could be improved with regards to the following:

  1. Setting WebService handlers in code is discouraged. A XML configuration file and a corresponding @HandlerChain annotation are recommended.
  2. A SOAPHandler is not required in this case, LogicalHandler would do just fine. A SOAPHandler has more reach than a LogicalHandler and when it comes to code, more access is not always good.
  3. Stuffing the signature generation, addition of a Node and printing the request in one handler seems like a little too much. These could be separated out for separation of responsibility and ease of testing. One approach would be to add the Node using a XSLT transformation so that the handler could remain oblivious of the transformation logic. Another handler could then be chained which just prints the request. Example
waqar

i did this in spring it's working fine.

package com.bookbub.application;


import com.ECS.client.jax.*;
import com.ECS.client.jax.ItemSearch;

import javax.xml.ws.Holder;
import java.math.BigInteger;
import java.util.List;

public class TestClient {

private static final String AWS_ACCESS_KEY_ID = "AI*****2Y7Z****DIHQ";
private static final String AWS_SECRET_KEY = "lIm*****dJuiy***YA+g/vnj/Ix*****Oeu";
private static final String ASSOCIATE_TAG = "****-**";

public static void main(String[] args) {
    TestClient ist = new TestClient();
    ist.runSearch();
}

public void runSearch()
{
    AWSECommerceService service = new AWSECommerceService();
    service.setHandlerResolver(new AwsHandlerResolver(AWS_SECRET_KEY));
    AWSECommerceServicePortType port = service.getAWSECommerceServicePort();

    ItemSearchRequest request = new ItemSearchRequest();
    request.setSearchIndex("Books");
    request.setKeywords("java web services up and running oreilly");

    ItemSearch search = new ItemSearch();
    search.getRequest().add(request);
    search.setAWSAccessKeyId(AWS_ACCESS_KEY_ID);

    Holder<OperationRequest> operation_request =null;
    Holder<List<Items>> items = new Holder<List<Items>>();

    port.itemSearch(
            search.getMarketplaceDomain(),
            search.getAWSAccessKeyId(),
            search.getAssociateTag(),
            search.getXMLEscaping(),
            search.getValidate(),
            search.getShared(),
            search.getRequest(),
            operation_request,
            items);

    java.util.List<Items> result = items.value;
    BigInteger totalPages = result.get(0).getTotalResults();
    System.out.println(totalPages);

    for (int i = 0; i < result.get(0).getItem().size(); ++i)
    {   Item myItem = result.get(0).getItem().get(i);
        System.out.print(myItem.getASIN());
        System.out.print(", ");
        System.out.println(myItem.getDetailPageURL());
        System.out.print(", ");
        System.out.println(myItem.getSmallImage() == null ? "" : myItem.getSmallImage().getURL());
    }
}
}
user3221678

You could achieve the same monetization outcomes with the IntentBrite API as well

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!