protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final Locale locale = localeResolver.resolveLocale(request); LocaleContextHolder.setLocale(locale); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); try { super.service( new HttpServletRequestWrapper(request) { @Override public Locale getLocale() { return locale; } }, response); } finally { if (!locale.equals(LocaleContextHolder.getLocale())) { if (logger.isDebugEnabled()) { logger.debug("locale changed, updating locale resolver"); } localeResolver.setLocale(request, response, LocaleContextHolder.getLocale()); } LocaleContextHolder.resetLocaleContext(); RequestContextHolder.resetRequestAttributes(); } }
/** * Get and stores in the servlet the application bean's name in the Spring's context. It's * expected to be configured as a the servlet <code>init-param</code> named * applicationBeanName. If no param is found, the default is "application". * * @see AbstractApplicationServlet#init(ServletConfig) */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); String name = config.getInitParameter("applicationBeanName"); this.name = name == null ? DEFAULT_APP_BEAN_NAME : name; }
@SuppressWarnings("unchecked") @Override public void init(ServletConfig servletConfig) throws ServletException { if (logger.isDebugEnabled()) { logger.debug("init()"); } super.init(servletConfig); applicationBean = servletConfig.getInitParameter("applicationBean"); if (applicationBean == null) { throw new ServletException("ApplicationBean not specified in servlet parameters"); } applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext()); applicationClass = (Class<? extends Application>) applicationContext.getType(applicationBean); initLocaleResolver(applicationContext); }