I am using Apache CXF and developing a web service and I don't want to return soap fault. If some kind of exception happens inside of the WebMethods i want to catch it inside a interceptor and return OK.
In case of error web service returns something like this but, i don't want to return something like this.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>soap:Receiver</soap:Value>
</soap:Code>
<soap:Reason>
<soap:Text xml:lang="en">Fault occurred while processing.</soap:Text>
</soap:Reason>
</soap:Fault>
</soap:Body>
</soap:Envelope>
i want to edit the response above and return something like below.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
ws-address- ws-security
<soap:Body>
<Response>
Ok!
</Response>
</soap:Body>
</soap:Envelope>
I added an out fault interceptor and i can catch the exception inside of it. But if i delete the exception from soap message the web service returns nothing. I can't add new object inside of it.
public class SoapInterceptor extends AbstractSoapInterceptor {
public SoapInterceptor() {
super(Phase.PRE_STREAM);
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
Fault fault = (Fault) message.getContent(Exception.class);
message.removeContent(Exception.class);
message.setContent(BaseResponse.class, new BaseResponse(ResultCode.SUCCESS));
}}