Class LoggingInterceptor

java.lang.Object
sk.antons.sbutils.http.LoggingInterceptor
All Implemented Interfaces:
org.springframework.http.client.ClientHttpRequestInterceptor

public class LoggingInterceptor extends Object implements org.springframework.http.client.ClientHttpRequestInterceptor
ClientHttpRequestInterceptor implementation. It logs http requests and responses and allows you to define where and how it will be printed.
Author:
antons
  • Method Details

    • instance

      public static LoggingInterceptor instance()
    • requestHeaders

      public LoggingInterceptor requestHeaders(Function<org.springframework.http.HttpHeaders,String> value)
      Method for converting HttpHeaders to string
      Parameters:
      value - method
      Returns:
      this
    • responseHeaders

      public LoggingInterceptor responseHeaders(Function<org.springframework.http.HttpHeaders,String> value)
      Method for converting HttpHeaders to string
      Parameters:
      value - method
      Returns:
      this
    • requestBody

      public LoggingInterceptor requestBody(Function<InputStream,String> value)
      Method for converting Body content to string
      Parameters:
      value - method
      Returns:
      this
    • responseBody

      public LoggingInterceptor responseBody(Function<InputStream,String> value)
      Method for converting Body content to string
      Parameters:
      value - method
      Returns:
      this
    • logger

      public LoggingInterceptor logger(Consumer<String> value)
      Method for logging message about request and response
      Parameters:
      value - method
      Returns:
      this
    • loggerEnabled

      public LoggingInterceptor loggerEnabled(BooleanSupplier value)
      Method for controlling if logging is enabled
      Parameters:
      value - method
      Returns:
      this
    • addToTemplate

      public void addToTemplate(org.springframework.web.client.RestTemplate template)
      Add this interceptor to RestTemplate instance
      Parameters:
      template -
    • intercept

      public org.springframework.http.client.ClientHttpResponse intercept(org.springframework.http.HttpRequest request, byte[] body, org.springframework.http.client.ClientHttpRequestExecution execution) throws IOException
      Specified by:
      intercept in interface org.springframework.http.client.ClientHttpRequestInterceptor
      Throws:
      IOException