我遇到outFaultInterceptor故障处理问题。任务是将原始消息附加到故障详细信息,如
public void handleMessage(SoapMessage msg) throws Fault {
RequestData requestData = new RequestData();
//SOAPMessage is anyType in RequestData WSDL type
//HERE I SET THE ORIGINAL MESSAGE
requestData.setSOAPMessage(msg.getExchange().getInMessage());
/////////////////////////////////////////////////////////////
ErrorContext ctx = new ErrorContext();
//(...)
ctx.setRequestData(requestData);
ErrorInfoDetails errorDetails = new ErrorInfoDetails();
errorDetails.setErrorMessage("Custom error message");
errorDetails.setErrorCode("Custom error code");
errorDetails.setErrorID("Custom error ID");
errorDetails.setSeverity(ServerityType.CRITICAL);
errorDetails.setErrorContext(ctx);
ErrorInfo error = new ErrorInfo("Custom fault string", errorDetails);
Fault fault = new Fault(error);
msg.setContent(Exception.class, fault);
}
如果我像上面一样添加它,在回复消息中,RequestData为空。
如果我用
添加它 SAAJStreamWriter messageWriter = (SAAJStreamWriter) msg.getExchange()
.getInMessage().get("org.apache.cxf.staxutils.W3CDOMStreamWriter");
RequestData requestData = new RequestData();
requestData.setSOAPMessage(messageWriter.toString());
它被添加为CDATA。 我很确定在新创建的故障消息和原始消息中存在一些名称空间冲突。是否有一些巧妙的方法或一些实用工具使它们保持一致?