Spring WS管理Custom FAult

时间:2012-01-10 10:36:31

标签: spring-ws

我正在使用食谱处理我的自定义肥皂故障: http://www.stevideter.com/2009/02/18/of-exceptionresolvers-and-xmlbeans/

将(使用身份转换 - 无XSLT)XML转换为soap故障详细信息的代码部分是:

protected void customizeFault(MessageContext messageContext, Object endpoint, Exception ex, SoapFault soapFault) {
  Transformer trn = null;
  Result result = null;
  SoapFaultDetail faultDetail = null;
  try {
    trn = TransformerFactory.newInstance().newTransformer();
    faultDetail = soapFault.addFaultDetail();

    // detail contains org.apache.xmlbeans marshalled xml
    StreamSource detail = ...
    result = faultDetail.getResult();
    trn.transform(detail, result); 
  ...
}

当我使用SoapUI测试输出时,我收到架构验证错误,因为响应是:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
      <faultcode>SOAP-ENV:Server</faultcode>
      <faultstring xml:lang="en">it.fault.InputFault</faultstring>
      <detail>
        <inputFault xmlns="http://fault.my.it">
          <code>ERR-INPUT 003</code>
          <message>Dati in input non completi</message>
        </inputFault>
      </detail>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我的XSD没有elementFormDefault所以它是unqualified,响应应如下所示:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
  <SOAP-ENV:Body>
    <SOAP-ENV:Fault>
      <faultcode>SOAP-ENV:Server</faultcode>
      <faultstring xml:lang="en">it.fault.InputFault</faultstring>
      <detail>
        <inputFault xmlns="http://fault.my.it">
          <code xmlns="">ERR-INPUT 003</code>
          <message xmlns="">Dati in input non completi</message>
        </inputFault>
      </detail>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

结果应与xmlnbeans marshalled对象相同,并且应包含xmlns=""

有人可以帮我理解为什么转换会删除xmlns声明吗?

感谢。

1 个答案:

答案 0 :(得分:1)

所以......感谢Grzegorz Grzybek,我发现xalan.jar,如果你在Jboss 4.2的“endorsed”目录中使用它并且使用java 1.5进行编译,那么效果不是很好。解决方案是下载xalan-2.7.1.jar并使用xalan sostituite,所有应该工作得很好,让xmlns =“”进入SoapREsponse,如:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
  <SOAP-ENV:Fault>
     <faultcode>SOAP-ENV:Server</faultcode>
     <faultstring xml:lang="en">it.my.fault.InputFault</faultstring>
     <detail>
        <inputFault xmlns="http://my.it/version-1-0-0">
           <codice xmlns="">ERR-INPUT 003</codice>
           <messaggio xmlns="">Dati in input non completi</messaggio>
        </inputFault>
     </detail>
    </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>