1 16 17 package org.springframework.web.filter; 18 19 import java.io.IOException ; 20 21 import javax.servlet.FilterChain ; 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 import org.springframework.context.i18n.LocaleContextHolder; 27 import org.springframework.web.context.request.RequestContextHolder; 28 import org.springframework.web.context.request.ServletRequestAttributes; 29 30 50 public class RequestContextFilter extends OncePerRequestFilter { 51 52 protected void doFilterInternal( 53 HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 54 throws ServletException , IOException { 55 56 ServletRequestAttributes attributes = new ServletRequestAttributes(request); 57 LocaleContextHolder.setLocale(request.getLocale()); 58 RequestContextHolder.setRequestAttributes(attributes); 59 if (logger.isDebugEnabled()) { 60 logger.debug("Bound request context to thread: " + request); 61 } 62 try { 63 filterChain.doFilter(request, response); 64 } 65 finally { 66 RequestContextHolder.setRequestAttributes(null); 67 LocaleContextHolder.setLocale(null); 68 attributes.requestCompleted(); 69 if (logger.isDebugEnabled()) { 70 logger.debug("Cleared thread-bound request context: " + request); 71 } 72 } 73 } 74 75 } 76 | Popular Tags |