Spring返回自定义soap故障
问题描述:
我使用spring webservices将我的服务作为Web服务公开。 我定义我的SOAP错误元素这样Spring返回自定义soap故障
<xsd:element name="systemFault">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="faultCode" type="xsd:string" nillable="true"/>
<xsd:element name="faultMessage" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
,我在我的WSDL
<wsdl:message name="msgSystemFault">
<wsdl:part name="body" element="cred:SystemFault"/>
</wsdl:message>
利用这一点,然后用这个在操作
<wsdl:operation name="opMyOp">
<wsdl:documentation>
Creating an entity note.
</wsdl:documentation>
<wsdl:input message="tns:msgMyOpRequest"/>
<wsdl:output message="tns:msgMyOpResponse"/>
<wsdl:fault name="fault" message="tns:msgSystemFault"/>
</wsdl:operation>
但是,当我想把这个错误抛到我的端点中,我该怎么做?
答
您需要一个EndpointExceptionResolver,请参见SpringWS手册约handling exceptions。
SpringWS带有一些内置的异常解决方法,您可以在实现自己的时候使用它们作为参考。
这似乎并不处理自定义错误,只是泛型服务器错误。 – skaffman 2010-11-02 14:45:18
为什么?或者,“自定义错误”是什么意思?只要看看SimpleSoapExceptionResolver及其超类的来源:https://fisheye.springsource.org/browse/spring-ws/trunk/core/src/main/java/org/springframework/ws/soap/server/endpoint /SimpleSoapExceptionResolver.java?hb=true - 你可以看到没有什么神奇的,你只需实现EndpointExceptionResolver接口并构建自己的自定义错误。 SpringWS甚至附带了几个抽象类,这些抽象类有助于删除大量样板代码。 – 2010-11-02 15:23:06