使用spring消息解析器获取soap fault内容

时间:2014-05-26 16:43:02

标签: spring-integration spring-ws

我使用spring集成和SOAP来集成外部系统。我在

中添加了SoapFaultMessageResolver
      <int-ws:outbound-gateway id="mnpOutboundGateway"
                           request-channel="mnpWSRequestChannel"
                           reply-channel="mnpWSResponseChannel"
                           marshaller="mnpMarshaller"
                           unmarshaller="mnpMarshaller"
                           destination-provider="mnpUriProvider"
                           fault-message-resolver="mnpFaultResolver"
                           message-factory="mnpMessageFactory"/>

  <bean name="mnpFaultResolver" class="com.iquest.play.integration.mnp.MnpSoapFaultResolver">

现在我已经覆盖了 @Override public void resolveFault(WebServiceMessage message) throws IOException {...

问题是,如何获取Soap Message内容(原因,错误代码)?

1 个答案:

答案 0 :(得分:3)

尝试从现有解决方案的来源SoapFaultMessageResolver开始:

SoapMessage soapMessage = (SoapMessage) message;
throw new SoapFaultClientException(soapMessage);

进一步说明SoapFaultClientException的源代码(部分):

SoapBody body = faultMessage.getSoapBody();
soapFault = body != null ? body.getFault() : null;
...
public QName getFaultCode() {
     return soapFault != null ? soapFault.getFaultCode() : null;
}
...

public String getFaultStringOrReason() {
     return soapFault != null ? soapFault.getFaultStringOrReason() : null;
}

从问题的角度来看,我认为这已经足够了。