[英]CXF fault interceptor - Logging soap fault message as shown in soap clients
I am using apache CXF(spring boot) for developing my soap server.我正在使用 apache CXF(spring boot) 来开发我的肥皂服务器。 Here I need to log the fault message in my soap Fault interceptor, exactly in the way it is shown in any soap client(ex: Soap UI).
在这里,我需要在我的soap故障拦截器中记录故障消息,完全按照它在任何soap客户端中显示的方式(例如:Soap UI)。 How can I log the same output in my fault interceptor ?
如何在故障拦截器中记录相同的输出? now it is just showing exception details
现在它只是显示异常详细信息
Input输入
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<sayHello xmlns="http://service.sample.com/">
<GreetingsRequest xmlns="">test</GreetingsRequest>
</sayHello>
</Body>
</Envelope>
Output (shown in soap client)输出(在soap客户端中显示)
UserNotfound Exception is a custom exception thrown in the code UserNotfound Exception 是代码中抛出的自定义异常
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
<detail>
<ns1:UserNotFoundException xmlns:ns1="http://service.sample.com/">
<user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://service.sample.com/" xsi:type="ns2:user">
<userId>U-123</userId>
<username>TestUser</username>
</user>
</ns1:UserNotFoundException>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
My custom interceptor code我的自定义拦截器代码
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.Phase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CustomSoapFaultInterceptor extends AbstractSoapInterceptor{
private static final Logger logger = LoggerFactory.getLogger(CustomSoapFaultInterceptor.class);
public CustomSoapFaultInterceptor() {
super(Phase.PRE_STREAM);
}
@Override
public void handleMessage(SoapMessage soapMessage) throws Fault {
Fault fault = (Fault) soapMessage.getContent(Exception.class);
Throwable faultCause = fault.getCause();
String faultMessage = fault.toString();
logger.error("Test Error",fault);
}
}
You can use the integrated logging facilities: https://cxf.apache.org/docs/message-logging.html您可以使用集成的日志记录工具: https : //cxf.apache.org/docs/message-logging.html
The code is available on GitHub in case you need to extend it: https://github.com/apache/cxf/blob/master/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java代码在 GitHub 上可用,以防您需要扩展它: https : //github.com/apache/cxf/blob/master/rt/features/logging/src/main/java/org/apache/cxf/ext/日志记录/LoggingFeature.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.