简体   繁体   中英

How to intercept CXF webservice logging?

How can I intercept CXF logging to cross out some digits during logging (banking + credit card information basically).

I use the following for log4j automated logging:

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

What would I have to change so that can adapt soap xml requests and delete some values before they are logged?

You can do it using custom log interceptor, where you can process the message.

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 ( );
        }



    }

}

Your CXF configuration would look like something like below

<jaxws:endpoint>

    <jaxws:inInterceptors>
           <ref bean="custInterceptor"/>
        </jaxws:inInterceptors>

</jaxws:endpoint>

<bean id="custInterceptor" class="com.kp.CustLogInInterceptor">

The CXF logging interceptors have a method:

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

that can be overridden to do any sort of obfuscation or something else that may be required. Just create subclasses and override that method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM