SOAP请求中的无效元素

时间:2013-06-06 15:45:27

标签: java eclipse wsdl

我为WSDL文件自动生成了一个我正在处理的项目的解决方案,但由于某种原因,该解决方案似乎无法正确处理WSDL指定的输入。有谁知道我能做些什么来解决它?

给出以下操作:

<wsdl:operation name="createBin">
    <wsdl:input message="impl:createBinRequest" name="createBinRequest"/>
    <wsdl:output message="impl:createBinResponse" name="createBinResponse"/>
</wsdl:operation>
<wsdl:message name="createBinRequest">
    <wsdl:part element="impl:createBin" name="parameters"/>
</wsdl:message>
<element name="createBin">
    <complexType>
        <sequence>
            <element name="request" type="impl:Bin"/>
        </sequence>
    </complexType>
</element>
<complexType name="Bin">
    <sequence>
        <element name="FulfillerID" type="xsd:positiveInteger"/>
        <element name="BinID" nillable="true" type="xsd:positiveInteger"/>
        <element name="ExternalLocationID" type="xsd:string"/>
        <element name="BinType" type="xsd:string"/>
        <element name="BinStatus" type="xsd:string"/>
        <element name="Name" nillable="true" type="xsd:string"/>
    </sequence>
</complexType>

使用此代码实现(由eclipse自动生成):

public PositiveInteger createBin(Bin request) throws RemoteException {
    throw new UnsupportedOperationException();
}

发送此消息时:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://my.api.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <q0:createBin>
            <q0:request>
                <q0:FulfillerID>1234</q0:FulfillerID> 
                <q0:BinID>1234</q0:BinID> 
                <q0:ExternalLocationID>1234</q0:ExternalLocationID> 
                <q0:BinType>Good</q0:BinType> 
                <q0:BinStatus>Bad</q0:BinStatus> 
                <q0:Name>Ugly</q0:Name> 
            </q0:request>
        </q0:createBin>
    </soapenv:Body>
</soapenv:Envelope>

我收到以下错误:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server.userException</faultcode> 
            <faultstring>org.xml.sax.SAXException: Invalid element in com.api.my.Bin - request</faultstring> 
            <detail>
                <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">localhost</ns1:hostname> 
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

我100%确定SOAP消息格式正确,因此我的服务器必须窒息。当我删除参数时,由于某种原因,一切都在游动。

但是,我可以通过删除元素来获得预期的行为:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://my.api.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <q0:createBin>
            <q0:FulfillerID>1234</q0:FulfillerID> 
            <q0:BinID>1234</q0:BinID> 
            <q0:ExternalLocationID>1234</q0:ExternalLocationID> 
            <q0:BinType>Good</q0:BinType> 
            <q0:BinStatus>Bad</q0:BinStatus> 
            <q0:Name>Ugly</q0:Name> 
        </q0:createBin>
    </soapenv:Body>
</soapenv:Envelope>

2 个答案:

答案 0 :(得分:1)

我正在寻找我的大脑,记住我之前看到过的地方,但我确信我已经看到一些看似“无效的SOAP请求”,但由于回复无效而被证明是无效的。

有鉴于此:您是否可以更改生成的createBin(Bin请求)代码以返回PositiveInteger而不是-3?也许如果我们能使te响应有效,你的服务器就会停止抱怨。

祝你好运!

答案 1 :(得分:0)

事实证明,SAX解析器没有解释它看起来应该的请求。即使该方法的参数为request,它也会忽略该参数并期望解析具有request类型com.api.my.Bin字段的元素。通过改变来解决这个问题。

public PositiveInteger createBin(Bin request) throws RemoteException {
    throw new UnsupportedOperationException();
}

使用

public PositiveInteger createBin(CreateBin request) throws RemoteException {
    throw new UnsupportedOperationException();
}

其中

public class CreateBin {
    public Bin request;

    /* ... */
}

虽然为了透明,我确实需要对日食产生的CoreServiceSoapBindingStubCoreServiceSoapBindingSkeleton进行大量调整,以便让因为无效的东西而导致整个事情不被炸毁 - 或-其他