Package net.solarnetwork.web.support
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 -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.client.ClientHttpResponseintercept(org.springframework.http.HttpRequest request, byte[] body, org.springframework.http.client.ClientHttpRequestExecution execution) static org.springframework.http.client.ClientHttpRequestFactoryGet a client request factory with logging support if either request or response logging is enabled.static org.springframework.http.client.ClientHttpRequestFactoryrequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory) Wrap a client request factory with logging support if either request or response logging is enabled.static booleansupportsLogging(org.springframework.http.client.ClientHttpRequestFactory reqFactory) Test if aClientHttpRequestFactorysupports logging with this interceptor.
-
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_LOGorRES_LOGhave TRACE level logging enabled, and if so return aBufferingClientHttpRequestFactorysuitable for logging. Otherwise the defaultSimpleClientHttpRequestFactoryis 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_LOGorRES_LOGhave TRACE level logging enabled, and if so return aBufferingClientHttpRequestFactorysuitable for logging. OtherwiserequestFactoryis 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 aClientHttpRequestFactorysupports 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:
interceptin interfaceorg.springframework.http.client.ClientHttpRequestInterceptor- Throws:
IOException
-