Amazon Product Advertising API signed request with Java

后端 未结 4 565
清酒与你
清酒与你 2020-12-25 08:16

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.

So

相关标签:
4条回答
  • 2020-12-25 08:35

    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
    0 讨论(0)
  • 2020-12-25 08:36

    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());
        }
    }
    }
    
    0 讨论(0)
  • 2020-12-25 08:52

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

    0 讨论(0)
  • 2020-12-25 09:00

    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

    0 讨论(0)
提交回复
热议问题