SoapFault details are not populated in Apache Camel Cxf

52 Views Asked by At

I have a route as below, even I tried replacing try-catch with onException() clause and setting handled to true in below route:

    from("direct:create-soap-request")
        .process(exchange -> {
            // creating GetAliases soap request
            GetAliases soapRequest = requestConverter.createRequestObject(exchange);
            exchange.getMessage().setBody(soapRequest);
        })
        // setting SOAP Operation in header
        .setHeader(CxfConstants.OPERATION_NAME, constant("getAliases"))
        .doTry()
        // Invoking the SOAP service
            .to("cxf:bean:coreWebServiceAdapter")
            .to("direct:map-soap-response-nppAliases")
        .doCatch(FaultDetail_Exception.class)
        .process("throwIntegrationServiceException"); // this is the processor where exception object is captured.

Issue is that when ever a SOAP FAULT is responded by server, sample xml below, the exception object is created with an empty soapFaultDetails. The error message is getting populated fine on exception object. Attaching screenshot of the variable instance.

<soap:Envelope
   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:soap_enc="http://schemas.xmlsoap.org/soap/encoding/">
 <soap:Body>
<soap:Fault>
    <faultcode>soap:Server</faultcode>
    <faultstring>Exception: abcd12345: Please enter a valid phone number</faultstring>
    <detail>
        <cor:faultDetail
            xmlns:cor="http://abc/123/2012/04/">
            <requestId>abcd12345</requestId>
            <errorCode>Random_Code</errorCode>
            <errorMessage>Please enter a valid phone number</errorMessage>
        </cor:faultDetail>
    </detail>
</soap:Fault>

</soap:Body> </soap:Envelope> `

enter image description here

I am not sure what am missing here. The message is being casted to exception object generated from the wsdl. I have cross checked the namespace of the response and it matches fine.

Code of my processor below :

@Override
public void process(final Exchange exchange) throws Exception {


    FaultDetail_Exception exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, FaultDetail_Exception.class);
    // business logic below

}
1

There are 1 best solutions below

0
Valath On

The issue is sorted now, it appears to be an invalid xml wrt namespace from server. Pasting the correct xml below :

<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap_enc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Exception: abcd12345: Please enter a valid phone number</faultstring>
<detail>
    <cor:faultDetail
        xmlns:cor="http://abc/123/2012/04/">
        <cor:requestId>abcd12345</cor:requestId>
        <cor:errorCode>Random_Code</cor:errorCode>
        <cor:errorMessage>Please enter a valid phone number</cor:errorMessage>
    </cor:faultDetail>
</detail>
</soap:Fault>