Is it possible to send "False" response from Interceptors in Apache CXF and Spring SOAP WS?

294 Views Asked by At

Consumer for one of my SOAP web service is unable to read SOAP Faults(Schema Validations) and hence he wants us to send "Ok = false" response instead with failing schema validation message.

I am not sure if we in any way can customize interceptors to generate a false response instead of SOAP Faults.

I am using interceptors for generating faults as of today as shown below

@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)

As of today I am getting a fault like below

<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>

While I want something like below:

    <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>

Please help.

1

There are 1 best solutions below

4
On

With an interceptor is possible to customize the response, but I do not recommend to return a message that is not present in the WSDL, which is the contract between client and server.

Instead it would raise that the answers had error codes instead of generating soap faults. In this way your client will also be able to generate automatically the code for his programming language.

Each message have the status (ok), the error details, and the usual response if the status is correct

<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>