de.digitalcollections.commons.springmvc.interceptors.RequestProcessingTimeInterceptor Maven / Gradle / Ivy
package de.digitalcollections.commons.springmvc.interceptors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
@ControllerAdvice
/**
* Usage: register it as interceptor in your Spring config and add it as ControllerAdvice to Spring context, e.g. by
* instantiating it through ComponentScan:
*
* @ComponentScan(basePackages = {
* "de.digitalcollections.commons.springmvc.interceptors"
* })
* ...
* public class SpringConfigWeb extends WebMvcConfigurerAdapter {
* ...
* @Override public void addInterceptors(InterceptorRegistry registry) {
* RequestProcessingTimeInterceptor requestProcessingTimeInterceptor = new RequestProcessingTimeInterceptor();
* registry.addInterceptor(requestProcessingTimeInterceptor);
* }
* ...
* }
*
*/
public class RequestProcessingTimeInterceptor extends HandlerInterceptorAdapter implements ResponseBodyAdvice