如何拦截 CXF 日志记录以在日志记录期间划掉一些数字(基本上是银行 + 信用卡信息)。
我将以下内容用于 log4j 自动日志记录:
Client client = ClientProxy.getClient(port);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
我需要更改什么才能适应 soap xml 请求并在记录之前删除一些值?
最佳答案
您可以使用自定义日志拦截器来处理消息。
public class CustLogInInterceptor extends AbstractSoapInterceptor {
public CustLogInInterceptor() {
super(Phase.RECEIVE);
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
HttpServletRequest httpRequest = (HttpServletRequest) message.get ( AbstractHTTPDestination.HTTP_REQUEST );
LoggerUtil.setLog(CustLogInInterceptor.class , LogConstants.DEBUG, "Request From the address : " + httpRequest.getRemoteAddr ( ) );
try
{
//Handle you custom code add log it
LoggerUtil.setLog(CustLogInInterceptor.class , LogConstants.DEBUG, "Log here" );
}
catch ( Exception ex )
{
ex.printStackTrace ( );
}
}
}
您的 CXF 配置如下所示
<jaxws:endpoint>
<jaxws:inInterceptors>
<ref bean="custInterceptor"/>
</jaxws:inInterceptors>
</jaxws:endpoint>
<bean id="custInterceptor" class="com.kp.CustLogInInterceptor">
关于java - 如何拦截 CXF web 服务日志记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20214046/