我正在使用Apache CXF并正在开发Web服务,并且我不希望返回任何错误。如果WebMethods内部发生某种异常,我想在拦截器中捕获它并返回OK。
如果发生错误,Web服务将返回类似的内容,但是,我不想返回类似的内容。
<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>
我想编辑上面的响应并返回类似下面的内容。
<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>
我添加了一个断层故障拦截器,我可以在其中捕获异常。但是,如果我从肥皂消息中删除异常,则Web服务将不返回任何内容。我无法在其中添加新对象。
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));
}}