Web services 使用Axis2的自定义故障代码
我创建了一个Web服务,并使用Axis2生成所有“骨架”java类。然后,我当然自己实现了服务操作 在实现中,我可以抛出一个MyException,然后由生成的类捕获并转换为AxisFault对象,该对象反过来转换为soap错误(在Axis框架的深处),属性为Web services 使用Axis2的自定义故障代码,web-services,soap,axis2,Web Services,Soap,Axis2,我创建了一个Web服务,并使用Axis2生成所有“骨架”java类。然后,我当然自己实现了服务操作 在实现中,我可以抛出一个MyException,然后由生成的类捕获并转换为AxisFault对象,该对象反过来转换为soap错误(在Axis框架的深处),属性为soapenv:Server 我的问题是我想要一个自定义的动态错误代码,而不是“soapenv:Server” 我试图手动创建AxisFault对象并抛出它,但AxisFault是一个RemoteException,并且我的实现必须实现的生
soapenv:Server
我的问题是我想要一个自定义的动态错误代码,而不是“soapenv:Server”
我试图手动创建AxisFault对象并抛出它,但AxisFault是一个RemoteException,并且我的实现必须实现的生成接口不允许抛出RemoteException
是否有可能在输出上获得某种钩子或过滤器,以便更改故障代码?或者用其他方法来控制故障代码
提前感谢Ulrik描述了自定义故障信息如何显示在详细信息标签下。faultcode是一组固定的值,用于处理SOAP处理中抛出错误的位置 下面是抛出自定义错误消息的示例 WSDL 在WSDL中声明错误,以便生成关联的类:
<wsdl:definitions targetNamespace="http://example"
xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:tns="http://example"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema elementFormDefault="qualified" targetNamespace="http://example"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:tns="http://example" xmlns:intf="http://example"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<element name="withdraw">
<complexType>
<sequence>
<element name="account" type="xsd:string"/>
<element name="amount" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="withdrawResponse">
<complexType>
<sequence>
<element name="balance" type="xsd:int"/>
</sequence>
</complexType>
</element>
<element name="AccountNotExistFault">
<complexType>
<sequence>
<element name="account" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="InsufficientFundFault">
<complexType>
<sequence>
<element name="account" type="xsd:string"/>
<element name="balance" type="xsd:int"/>
<element name="requestedFund" type="xsd:int"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="withdrawRequest">
<wsdl:part element="tns:withdraw" name="parameters"/>
</wsdl:message>
<wsdl:message name="withdrawResponse">
<wsdl:part element="tns:withdrawResponse" name="return"/>
</wsdl:message>
<wsdl:message name="InsufficientFundFaultMessage">
<wsdl:part element="tns:InsufficientFundFault" name="fault"/>
</wsdl:message>
<wsdl:message name="AccountNotExistFaultMessage">
<wsdl:part element="tns:AccountNotExistFault" name="fault"/>
</wsdl:message>
<wsdl:portType name="Bank">
<wsdl:operation name="withdraw">
<wsdl:input message="tns:withdrawRequest" name="withdrawRequest"/>
<wsdl:output message="tns:withdrawResponse" name="withdrawResponse"/>
<wsdl:fault message="tns:AccountNotExistFaultMessage" name="AccountNotExistException"/>
<wsdl:fault message="tns:InsufficientFundFaultMessage" name="InsufficientFundException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BankSoapBinding" type="tns:Bank">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="withdraw">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="withdrawRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="withdrawResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="InsufficientFundException">
<wsdlsoap:fault name="InsufficientFundException" use="literal"/>
</wsdl:fault>
<wsdl:fault name="AccountNotExistException">
<wsdlsoap:fault name="AccountNotExistException" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BankService">
<wsdl:port binding="tns:BankSoapBinding" name="Bank">
<wsdlsoap:address location="http://localhost:8080/bank/services/Bank"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
测试
下面的SOAP消息
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="http://example">
<soapenv:Header/>
<soapenv:Body>
<exam:withdraw>
<exam:account>10</exam:account>
<exam:amount>2000</exam:amount>
</exam:withdraw>
</soapenv:Body>
</soapenv:Envelope>
10
2000
生成以下SOAP故障响应
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>Insufficient funds</faultstring>
<detail>
<ns1:InsufficientFundFault xmlns:ns1="http://example">
<ns1:account>10</ns1:account>
<ns1:balance>1000</ns1:balance>
<ns1:requestedFund>2000</ns1:requestedFund>
</ns1:InsufficientFundFault>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
soapenv:服务器
资金不足
10
1000
2000
Mark,在您的示例中,SOAP faultcode将设置为什么?如果您可以发布一个完整的soap响应,显示一个故障示例,那就太好了。SOAP错误代码是一组固定的值。这是文件,好的。因此,即使我找到了一种方法,我也不应该更改错误代码:)非常感谢!
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server</faultcode>
<faultstring>Insufficient funds</faultstring>
<detail>
<ns1:InsufficientFundFault xmlns:ns1="http://example">
<ns1:account>10</ns1:account>
<ns1:balance>1000</ns1:balance>
<ns1:requestedFund>2000</ns1:requestedFund>
</ns1:InsufficientFundFault>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>