Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache CXF LoggingInInterceptor is deprecated - what to use instead?

I am using Apache CXF with Spring Boot with the help of cxf-spring-boot-starter-jaxws plugin of version 3.2.7.

My intention is to customize the LoggingInterceptors but when I created the below class:

public class CustomLoggingInInterceptor extends org.apache.cxf.interceptor.LoggingInInterceptor {}

but my IDE strikes out the LoggingInInterceptor complaining it's deprecated with the explanation

use logging module rt/features/logging instead

So how should one go about customizing the logging interceptor using this module ?

like image 636
alegria Avatar asked Mar 04 '19 19:03

alegria


People also ask

What is LoggingInInterceptor?

@Deprecated public class LoggingInInterceptor extends AbstractLoggingInterceptor. A simple logging handler which outputs the bytes of the message to the Logger.

What is Apache CXF used for?

Apache CXF™ is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI.


2 Answers

Basically 4 things are needed to update from the old to the new cxf logging (rt/features/logging).

First, Set the logging feature:

final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setFeatures(Collections.singletonList(new CustomLoggingFeature()));

You don't need anymore the interceptors (in case you used them, delete them):

factory.getInInterceptors().add(new CustomMaskedLoggingInInterceptor()); factory.getOutInterceptors().add(new CustomMaskedLoggingOutInterceptor());

Second, create your LoggingFeature:

public class CustomLoggingFeature extends org.apache.cxf.ext.logging.LoggingFeature {
    public CustomLoggingFeature() {
        super();
        this.setSender(new CustomEventLogSender());
    }
}

Third, create your EventLogSender:

public class CustomEventLogSender extends Slf4jVerboseEventSender {
    @Override
    protected String getLogMessage(LogEvent event) {
        String logMessage = super.getLogMessage(event);
        return CustomMasker.mask(logMessage);
    }
}

Fourth, create a CustomMasker class where you have your own string manipulation logic to mask the desired information.

Let me know if it worked!

like image 150
RichArt Avatar answered Oct 12 '22 03:10

RichArt


What this message is telling you, is to use the Apache CXF Advanced logging feature module.

Its dependency is (latest version)

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-features-logging</artifactId>
    <version>3.3.0</version>
    <scope>test</scope>
</dependency>

Inside you'll find a comparable org.apache.cxf.ext.logging.LoggingInInterceptor (link)


I'm not a CXF user, however I suppose you'll have to interact with a JaxWsProxyFactoryBean.
Remember you need to use the same version for all the CXF modules.

After getting an hold on it, you can do

factory.getInInterceptors().add(new MyCustomInterceptor());
like image 44
LppEdd Avatar answered Oct 12 '22 04:10

LppEdd