Java SOAP - 产品广告API - 响应空

时间:2012-09-23 14:23:21

标签: java soap amazon amazon-product-api

我已经为亚马逊产品API创建了一个搜索请求,但它的回复是空的。 你能给我一个暗示我的代码有什么问题吗?

代码:

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);

ResultSet仍为空,但没有发生错误......

1 个答案:

答案 0 :(得分:2)

我发现了我犯的错误。

我创建了没有amazon 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中,我为build-process

创建了以下部分
<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());
    }
}