Reputation: 86915
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?
Upvotes: 1
Views: 884
Reputation: 14607
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.
Upvotes: 2
Reputation: 10034
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">
Upvotes: 2