WebClient logging without deprecated method tcpClient.bootstrap()

Viewed 3800

I'm trying do some logging in my middleware application, where I want to log request and response of backend system. I would like to use Netty (because we have implemented difficult SslContext).

I'm trying to learn it by this tutorial: https://www.baeldung.com/spring-log-webclient-calls (chapter 4.2. Logging with Netty HttpClient).

For better looking logs, there is part of code:

HttpClient httpClient = HttpClient
  .create()
  .tcpConfiguration(
    tc -> tc.bootstrap(
      b -> BootstrapHandlers.updateLogSupport(b, new CustomLogger(HttpClient.class))))
  .build()

but bootstrap(...) method is deprecated. What can I use instead?

1 Answers

If you need CustomLogger for request/response (as per comment above) then you can do the following:

CustomLogger customLogger = new CustomLogger(HttpClient.class);         
HttpClient httpClient = HttpClient
                .create()
                .doOnRequest((request, connection) -> {
                    connection.addHandlerFirst(customLogger);
                });
Related