Java SOAP请求中的元素无效
我为正在处理的项目从WSDL文件自动生成了一个解决方案,但由于某些原因,该解决方案似乎无法正确处理WSDL指定的输入。有人知道我能做些什么来修复它吗 鉴于以下操作:Java SOAP请求中的元素无效,java,eclipse,wsdl,Java,Eclipse,Wsdl,我为正在处理的项目从WSDL文件自动生成了一个解决方案,但由于某些原因,该解决方案似乎无法正确处理WSDL指定的输入。有人知道我能做些什么来修复它吗 鉴于以下操作: <wsdl:operation name="createBin"> <wsdl:input message="impl:createBinRequest" name="createBinRequest"/> <wsdl:output message="impl:createBinResp
<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>
发送此消息时:
<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>
1234
1234
1234
好
坏的
丑陋的
我得到以下错误:
<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>
soapenv:Server.userException
org.xml.sax.SAXException:com.api.my.Bin中的元素无效-请求
本地主机
我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>
1234
1234
1234
好
坏的
丑陋的
我在大脑中搜索,想记住我以前在哪里看到过这一点,但我肯定我看到过一些看似“无效的SOAP请求”,它们最终被证明是无效的,因为响应是无效的
在这种情况下:您是否可以更改生成的createBin(Bin请求)代码以返回一个PositiveInteger
,而不是-3
?也许如果我们能使te响应有效,您的服务器将停止抱怨
祝你好运 事实证明SAX解析器并没有解释它看起来应该解释的请求。即使该方法的参数是
request
,它也会忽略该参数,并希望解析具有request
字段类型com.api.my.Bin
的元素。这个问题是通过改变来解决的
public PositiveInteger createBin(Bin request) throws RemoteException {
throw new UnsupportedOperationException();
}
与
在哪里
不过,为了透明起见,我确实需要对eclipse生成的
CoreServiceSoapBindingStub
和CoreServiceSoapBindingSkeleton
做很多调整,以使整个过程不会因为无效的东西或其他东西而崩溃。感谢您的帮助,我为问题添加了更多细节,但是我忘了提到我发送了一个“格式不正确”的请求,并得到了一个-3值的响应(尽管这很奇怪)。让createBin
方法抛出一个未指定的异常,如UnsupportedOperationException
,可能会导致一个“未指定”的soap错误。你期待什么?说我疯了,但我期待的是不支持操作异常
,而不是SAXException
。
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;
/* ... */
}