【问题标题】:Soap Fault Details custom exceptionSoap 故障详细信息自定义异常
【发布时间】:2015-01-26 20:49:22
【问题描述】:

在迁移到 Spring WS 并使用 wsdl 中的 JAXB 生成 Soap 消息中使用的对象的过程中。我在尝试将自定义异常放入 Soap 故障消息的详细信息字段时遇到问题。以下是现有的故障信息是如何返回的(详细嵌入FooException)。

<env:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <env:Header/>
   <env:Body>
      <env:Fault>
         <faultcode>env:Server</faultcode>
         <faultstring>Service specific exception: com.test.FooException: Invalid authentication credentials. Please try again.</faultstring>
         <detail>
            <n1:FooException xsi:type="n1:FooException" xmlns:n1="java:com.test">
               <errorCode xsi:type="xsd:int">101</errorCode>
               <errorReason xsi:type="xsd:string">InvalidUserCredentials:Invalid authentication credentials. Please try again</errorReason>
            </n1:FooException>
         </detail>
      </env:Fault>
   </env:Body>
</env:Envelope>

我在 spring config xml 文件中设置了一个客户 exceptionResolver bean 标识符。

   <bean id="exceptionResolver" class="com.test.FacadeExceptionHandler">
         <property name="order" value="1"></property>
         <property name="defaultFault" value="SERVER"/> 
         <property name="exceptionMappings"> 
             <value> com.test.FooException=SERVER,FaultMsg </value> 
         </property>
    </bean>

我创建了 FacadeExceptionHandler 并且它正在被调用,但我无法弄清楚如何将 FooException 放入故障消息的详细信息部分。

任何帮助将不胜感激!!!

提前感谢您的帮助!

【问题讨论】:

  • 向我们展示FooException的实现

标签: spring web-services exception soap jaxb


【解决方案1】:

我想你几乎明白了,在你的FacadeExceptionHandler 中,你必须重写customizeFault 方法(doc),然后添加错误的详细信息(你有你的异常作为参数)。

Soap Fault 消息的所有这些自定义详细信息处理都在此条目中进行了详细说明:http://www.stevideter.com/2009/02/18/of-exceptionresolvers-and-xmlbeans/

【讨论】:

    【解决方案2】:

    你不能返回 SOAP 客户端错误,因为在 Spring WS 中 SoapFault 中的嵌套元素深度如此之深,SoapFaultSoapFaultDetail 列表,其中有 SoapFaultDetailElement 列表但 SoapFaultDetailElement 只是详细消息细绳。所以在 Spring WS 中,SOAP 错误细节的最大深度是 一个

    <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Client</faultcode>
         <faultstring>Сообщение не соответствуют схеме сервиса СМЭВ.</faultstring>
         <detail>
            <InvalidContent xmlns="urn://x-artefacts-smev-gov-ru/services/message-exchange/types/faults/1.1">cvc-complex-type.2.4.a: Invalid content was found starting with element 'ns:SenderProvidedRequestData1'. One of '{"urn://x-artefacts-smev-gov-ru/services/message-exchange/types/1.1":SenderProvidedRequestData}' is expected.</InvalidContent>
            <InvalidContent xmlns="urn://x-artefacts-smev-gov-ru/services/message-exchange/types/faults/1.1">cvc-complex-type.2.3: Element 'ns:CallerInformationSystemSignature' cannot have character [children], because the type's content type is element-only.</InvalidContent>
            <InvalidContent xmlns="urn://x-artefacts-smev-gov-ru/services/message-exchange/types/faults/1.1">cvc-complex-type.2.4.b: The content of element 'ns:CallerInformationSystemSignature' is not complete. One of '{WC["http://www.w3.org/2000/09/xmldsig#"]}' is expected.</InvalidContent>
         </detail>
      </SOAP-ENV:Fault>
    

    【讨论】: