GWTLocaleHeaderFilter implements Filter { @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { final CharResponseWrapper wrappedResponse = getWrapper((HttpServletResponse) response); chain.doFilter(request, wrappedResponse); final String output; final Locale locale = getLocale(request); final String injectedScript = "<meta name=\"gwt:property\" content=\"locale=" + locale.toString() + "\">"; final Document document = Jsoup.parse(wrappedResponse.toString()); document.head().append(injectedScript); output = document.html(); final byte[] outputBytes = output.getBytes("UTF-8"); response.setContentLength(outputBytes.length); response.getWriter().print(output); }  @Override void init(final FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(final ServletRequest request,
                         final ServletResponse response,
                         final FilterChain chain);  }
@Test public void testLocaleWithLanguageParameter() throws IOException, ServletException { final GWTLocaleHeaderFilter localeHeaderFilter = getFilter(); final Writer sw = new StringWriter(); final HttpServletRequest req = mock(HttpServletRequest.class); final HttpServletResponse resp = mock(HttpServletResponse.class); final FilterChain chain = mock(FilterChain.class); when(req.getParameter("locale")).thenReturn("ja"); when(resp.getWriter()).thenReturn(new PrintWriter(sw)); localeHeaderFilter.doFilter(req, resp, chain); assertEquals(new Scanner(getClass().getResourceAsStream("/expected-2-sample.html"), "UTF-8").useDelimiter("\\A").next(), sw.toString()); }
@Test public void testLocaleWithLanguageAndCountryParameter() throws IOException, ServletException { final GWTLocaleHeaderFilter localeHeaderFilter = getFilter(); final Writer sw = new StringWriter(); final HttpServletRequest req = mock(HttpServletRequest.class); final HttpServletResponse resp = mock(HttpServletResponse.class); final FilterChain chain = mock(FilterChain.class); when(req.getParameter("locale")).thenReturn("ja_JP"); when(resp.getWriter()).thenReturn(new PrintWriter(sw)); localeHeaderFilter.doFilter(req, resp, chain); assertEquals(new Scanner(getClass().getResourceAsStream("/expected-3-sample.html"), "UTF-8").useDelimiter("\\A").next(), sw.toString()); }