是否可以发送" False" Apache CXF和Spring SOAP WS中拦截器的响应?

时间:2016-12-28 13:36:05

标签: spring soap cxf interceptor spring-ws

我的一个SOAP Web服务的使用者无法读取SOAP错误(模式验证),因此他希望我们发送" Ok = false"而是使用失败的架构验证消息进行响应。

我不确定我们是否可以通过任何方式自定义拦截器来生成错误响应,而不是SOAP错误。

我现在使用拦截器来产生故障,如下所示

@org.apache.cxf.interceptor.InInterceptors(interceptors = {"com.xxx.piano.services.interceptors.RequestParserInterceptor",
    "com.xxx.piano.services.interceptors.RequestInterceptor"})
@SchemaValidation(type = SchemaValidation.SchemaValidationType.IN)
@org.apache.cxf.interceptor.OutFaultInterceptors(classes =  RequestParsingValidator.class)

截至今天,我遇到了如下错误

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
  <soap:Fault>
     <faultcode>soap:Server</faultcode>
     <faultstring>[City is empty !] </faultstring>
  </soap:Fault>
 </soap:Body>
</soap:Envelope>

虽然我想要以下内容:

    <ns3:XXXServiceTypeResponse>
        <OK>false</OK>
        <Error>
            <Message>Duplicate Product Individual Identifier.</Message>
            <TechnicalDescription>Postal Code Missing</TechnicalDescription>
            <ErrorCode>E0022</ErrorCode>
        </Error>
        <ns3:ResponseID>01202662-0010-0001-0001-4617844469</ns3:ResponseID>
    </ns3:XXXServiceTypeResponse>

请帮忙。

1 个答案:

答案 0 :(得分:0)

使用拦截器可以自定义响应,但我不建议返回WSDL中不存在的消息,即客户端和服务器之间的合同。

相反,它会提出答案有错误代码而不是生成肥皂错误。通过这种方式,您的客户端也可以自动生成其编程语言的代码。

每条消息都有状态(ok),错误详细信息以及状态正确时的常规响应

<ns3:XXXServiceTypeResponse>
      <OK>false</OK>
      <Error>
          <Message>Duplicate Product Individual Identifier.</Message>
          <TechnicalDescription>Postal Code Missing</TechnicalDescription>
          <ErrorCode>E0022</ErrorCode>
      </Error>
      <ns3:ResponseID>01202662-0010-0001-0001-4617844469</ns3:ResponseID>
      <ns3:ResponseIfOk />
  </ns3:XXXServiceTypeResponse>
相关问题