gpt4 book ai didi

java - 如何拦截 CXF web 服务日志记录?

转载 作者:行者123 更新时间:2023-11-29 03:27:39 25 4
gpt4 key购买 nike

如何拦截 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com