
com.github.bingoohuang.springrest.boot.interceptor.ThreadLocalInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-rest-boot Show documentation
Show all versions of spring-rest-boot Show documentation
convenient spring rest server on spring boot
package com.github.bingoohuang.springrest.boot.interceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ThreadLocalInterceptor extends HandlerInterceptorAdapter {
static ThreadLocal httpServletRequestTl = new ThreadLocal();
static ThreadLocal httpServletResponseTl = new ThreadLocal();
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
httpServletRequestTl.set(request);
httpServletResponseTl.set(response);
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
httpServletRequestTl.remove();
httpServletResponseTl.remove();
}
public static HttpServletResponse getResponse() {
return httpServletResponseTl.get();
}
public static HttpServletRequest getRequest() {
return httpServletRequestTl.get();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy