2013-11-26 74 views
1

如何在日志记录过程中拦截CXF日志记录以清除一些数字(基本上是银行+信用卡信息)。如何拦截CXF web服务日志记录?

我使用log4j的自动记录如下:

Client client = ClientProxy.getClient(port); 
    client.getInInterceptors().add(new LoggingInInterceptor()); 
    client.getOutInterceptors().add(new LoggingOutInterceptor()); 

我将不得不改变,以便能适应SOAP XML请求,并删除一些值记录才?

+0

以下是过滤的完整实现:​​https://github.com/greenbird/xml-formatter-components/tree/master/cxf – ThomasRS

回答

2

您可以使用自定义日志拦截器来处理邮件。

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"> 
2

的CXF日志记录拦截器有一个方法:

protected String transform(String originalLogString) { 
    return originalLogString; 
} 

可重写做任何形式的混淆或某事其他可能需要的。只需创建子类并重写该方法即可。