Ganesh Gudghe
Ganesh Gudghe

Reputation: 1387

Apache CXF 3.2 How to read SOAP fault message

I am trying to read SOAP fault message from CXF interceptor but i could not extract, i captured response from Fidler

Following is the response from fidler

--uuid:0674d395-99e7-44d8-966c-1f1d387f4234
Content-Id: <rootpart*[email protected]>
Content-Type: application/xop+xml;charset=UTF-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope" xmlns=""><faultcode>S:Server</faultcode><faultstring>Upload Failed!</faultstring></S:Fault></S:Body></S:Envelope>

--uuid:0674d395-99e7-44d8-966c-1f1d387f4234--

following is my code

Added FaultInterceptor to client

client.getInFaultInterceptors().add(faultInterceptor);

public class FlexFaultResponseInterceptor extends AbstractSoapInterceptor {

    public FlexFaultResponseInterceptor() {
        super(Phase.RECEIVE);
    }

    @Override
    public void handleMessage(SoapMessage message) throws Fault {
        Message InFaultMessage = message.getExchange().getInFaultMessage();
        Message OutFaultMessage = message.getExchange().getOutFaultMessage();
    }
}

Upvotes: 0

Views: 1139

Answers (1)

Ganesh Gudghe
Ganesh Gudghe

Reputation: 1387

I resolved my issue by adding the following code into InInterceptor

@Override
    public void handleMessage(SoapMessage message) throws Fault {
            CachedOutputStream out = message.getContent(CachedOutputStream.class);
            byte[] originalMessage = IOUtils.toByteArray( out.getInputStream() );
            String fault=new String(originalMessage)
    }

Upvotes: 0

Related Questions