Class LoggingHttpRequestInterceptor

java.lang.Object
net.solarnetwork.web.support.LoggingHttpRequestInterceptor
All Implemented Interfaces:
org.springframework.http.client.ClientHttpRequestInterceptor

public class LoggingHttpRequestInterceptor extends Object implements org.springframework.http.client.ClientHttpRequestInterceptor
A client HTTP interceptor for logging the full details of each request.

Request messages are logged at TRACE level under the net.solarnetwork.http.REQ logger; responses under net.solarnetwork.http.RES.

Version:
1.1
Author:
matt
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.client.ClientHttpResponse
    intercept(org.springframework.http.HttpRequest request, byte[] body, org.springframework.http.client.ClientHttpRequestExecution execution)
     
    static org.springframework.http.client.ClientHttpRequestFactory
    Get a client request factory with logging support if either request or response logging is enabled.
    static org.springframework.http.client.ClientHttpRequestFactory
    requestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
    Wrap a client request factory with logging support if either request or response logging is enabled.
    static boolean
    supportsLogging(org.springframework.http.client.ClientHttpRequestFactory reqFactory)
    Test if a ClientHttpRequestFactory supports logging with this interceptor.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LoggingHttpRequestInterceptor

      public LoggingHttpRequestInterceptor()
  • Method Details

    • requestFactory

      public static org.springframework.http.client.ClientHttpRequestFactory requestFactory()
      Get a client request factory with logging support if either request or response logging is enabled.

      This method will check if either REQ_LOG or RES_LOG have TRACE level logging enabled, and if so return a BufferingClientHttpRequestFactory suitable for logging. Otherwise the default SimpleClientHttpRequestFactory is returned.

      Returns:
      a new request factory
    • requestFactory

      public static org.springframework.http.client.ClientHttpRequestFactory requestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
      Wrap a client request factory with logging support if either request or response logging is enabled.

      This method will check if either REQ_LOG or RES_LOG have TRACE level logging enabled, and if so return a BufferingClientHttpRequestFactory suitable for logging. Otherwise requestFactory is returned directly.

      Parameters:
      requestFactory - request factory to possibly wrap
      Returns:
      the request factory
      Since:
      1.1
    • supportsLogging

      public static boolean supportsLogging(org.springframework.http.client.ClientHttpRequestFactory reqFactory)
      Test if a ClientHttpRequestFactory supports logging with this interceptor.
      Parameters:
      reqFactory - the request factory to test
      Returns:
      true if the factory is a BufferingClientHttpRequestFactory
    • 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