2010-11-02 56 views
3

我使用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> 

但是,當我想把這個錯誤拋到我的端點中,我該怎麼做?

回答

2

您需要一個EndpointExceptionResolver,請參見SpringWS手冊約handling exceptions

SpringWS帶有一些內置的異常解決方法,您可以在實現自己的時候使用它們作爲參考。

+3

這似乎並不處理自定義錯誤,只是泛型服務器錯誤。 – skaffman 2010-11-02 14:45:18

+0

爲什麼?或者,「自定義錯誤」是什麼意思?只要看看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