连接Amazon AWSECommerceService时无效的SOAP消息

时间:2013-10-03 20:36:09

标签: java web-services cxf amazon

我尝试连接到Amazon AWSECommerceService。我使用CXF生成了客户端类并提供了WSDL,但是我收到错误“操作itemLookup对此端点无效”。

一些调查让我想到了这一点: 生成的SOAP消息如下:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:itemLookup
            xmlns:ns1="http://_2011_08_01.awsecommerceservice.webservices.amazon.com/">
            <ItemLookup
                xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
                <AssociateTag>pkd</AssociateTag>
                <Request>
                    <IdType>ISBN</IdType>
                    <ItemId>0321534468</ItemId>
                    <SearchIndex>Books</SearchIndex>
                </Request>
            </ItemLookup>
        </ns1:itemLookup>
    </soap:Body>
</soap:Envelope>

但应该是:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
            <ItemLookup
                xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
                <AssociateTag>pkd</AssociateTag>
                <Request>
                    <IdType>ISBN</IdType>
                    <ItemId>0321534468</ItemId>
                    <SearchIndex>Books</SearchIndex>
                </Request>
            </ItemLookup>
    </soap:Body>
</soap:Envelope>

看起来有一个意外的标签

<ns1:itemLookup
                xmlns:ns1="http://_2011_08_01.awsecommerceservice.webservices.amazon.com/">

第二个示例在使用SoapUI时效果很好。 出了什么问题?运行wsdl2java maven插件我错过了什么?

如果问题很愚蠢,请原谅我。我是webservices和SOAP的新手。

当我添加注释时:

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

我收到了消息:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:itemLookup
            xmlns:ns1="http://_2011_08_01.awsecommerceservice.webservices.amazon.com/">
            <ns2:ItemLookup
                xmlns:ns2="http://_2011_08_01.awsecommerceservice.webservices.amazon.com/"
                xmlns:ns3="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
                <AssociateTag>pkd</AssociateTag>
                <Shared>
                    <IdType>ISBN</IdType>
                    <ItemId>0321534468</ItemId>
                    <SearchIndex>Books</SearchIndex>
                </Shared>
            </ns2:ItemLookup>
        </ns1:itemLookup>
    </soap:Body>
</soap:Envelope>

这些命名空间对我来说很奇怪。

2 个答案:

答案 0 :(得分:0)

在ItemLookup.java文件所在的包中,验证是否存在package-info.java,如果没有,则创建一个。在package-info类中,您的代码看起来像

@javax.xml.bind.annotation.XmlSchema(namespace = "hhttp://_2011_08_01.awsecommerceservice.webservices.amazon.com/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns = {
    @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://_2011_08_01.awsecommerceservice.webservices.amazon.com/", prefix = "ns1")
})
package your.package;

因此,请尝试删除名称空间uri

Opps错误地解释了你的问题。这是解决方案

添加注释

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

致你的班级

答案 1 :(得分:0)

好的,我找到了解决方案。我不知道为什么会这样做,但问题在于我创建服务的方式:

ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(AWSECommerceServicePortType.class);
factory.setAddress("https://soap.amazon.com/onca/soap?Service=AWSECommerceService");
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
AWSECommerceServicePortType ss = (AWSECommerceServicePortType) factory.create();

但当我把它改为:

AWSECommerceServicePortType ss = new AWSECommerceService().getAWSECommerceServicePort();        
Client client = ClientProxy.getClient(ss);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());

它奏效了。感谢@SRT_KP愿意提供帮助。