0

I've created a Search-Request to the amazon product API but it's response is empty. Can you give me a hint what's wrong with my code?

Code:

String awsAccessKeyID = "<AWS-KEY>";
String test = "<ASSOCIATE-TAG>"; 

AWSECommerceService service = new AWSECommerceService();
service.setHandlerResolver(new AwsHandlerResolver("<SECRET-KEY>"));

AWSECommerceServicePortType port = service.getAWSECommerceServicePort();

ItemSearch ItemSearch = new ItemSearch();

ItemSearch.setAWSAccessKeyId(awsAccessKeyID);
ItemSearch.setAssociateTag(test);

ItemSearchRequest SearchRequest = new ItemSearchRequest();

java.util.List<ItemSearchRequest> list = ItemSearch.getRequest();

list.add(SearchRequest);

SearchRequest.setSearchIndex("All");


SearchRequest.setKeywords("nas");

ItemSearch.getRequest().add(SearchRequest);
ItemSearch.setMarketplaceDomain("https://ecs.amazonaws.de/onca/xml?Service=AWSECommerceService");


SearchRequest.getResponseGroup().add("Large");

Holder<OperationRequest> operationrequest = new Holder<OperationRequest>();

Holder<java.util.List<Items>> items = new Holder<java.util.List<Items>>();

port.itemSearch(ItemSearch.getMarketplaceDomain(), ItemSearch.getAWSAccessKeyId(), ItemSearch.getAssociateTag(), ItemSearch.getXMLEscaping(), "True", ItemSearch.getShared(), ItemSearch.getRequest(), operationrequest, items);

java.util.List<Items> result = items.value;
System.out.println(result);

The ResultSet is still empty but no errors occured....

4

1 回答 1

2

我发现了我犯的错误。

我创建了没有亚马逊 wsdl 所需的 JAXB 绑定条件的源。您需要一个包含以下限制的 binding.xml 文件

<jaxws:bindings wsdlLocation="http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
  <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>

在 pom.xml 中,我为构建过程创建了以下部分

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.10</version>
    <executions>
<execution>
        <goals>
            <goal>wsimport</goal>
        </goals>
        <configuration>
            <wsdlUrls>
                <wsdlUrl>http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl</wsdlUrl>
            </wsdlUrls>
            <sourceDestDir>target/generated-sources/apt</sourceDestDir>
            <bindingFiles>
                <bindingFile>../../conf/binding.xml</bindingFile>
            </bindingFiles>
        </configuration>
        <id>wsimport-generate-AWSECommerceService</id>
        <phase>generate-sources</phase>
    </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>javax.xml</groupId>
            <artifactId>webservices-api</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>
</plugin>

在重新创建资源后,我将请求更改为以下内容:

String awsAccessKeyID = "<AWS-ACCESS-KEY>";
String test = "<ASSOCIATE-TAG>"; 

AWSECommerceService service = new AWSECommerceService();
service.setHandlerResolver(new AwsHandlerResolver("<SECRET-KEY>"));

AWSECommerceServicePortType port = service.getAWSECommerceServicePort();

ItemSearchRequest itemRequest = new ItemSearchRequest();

// Fill in the request object:
itemRequest.setSearchIndex("Electronics");
itemRequest.setKeywords("NAS");
itemRequest.getResponseGroup().add("ItemAttributes");
itemRequest.setItemPage(BigInteger.valueOf(1L));


ItemSearch ItemElement = new ItemSearch();
ItemElement.setAWSAccessKeyId(awsAccessKeyID);
ItemElement.setAssociateTag(test);
ItemElement.getRequest().add(itemRequest);

ItemSearchResponse response = port.itemSearch(ItemElement);

for (Items itemList : response.getItems()) {
    for (Item itemObj : itemList.getItem()) {
        System.out.println(itemObj.getItemAttributes().getBrand());
        System.out.println(itemObj.getItemAttributes().getEAN());
    }
}
于 2012-09-25T08:25:22.530 回答