@Test public void testWithoutInit() { int daysToLive = DEFAULT_DAYS_TO_LIVE; long secsToLive = TimeUnit.DAYS.toMillis(daysToLive); long before = System.currentTimeMillis(); before -= before % 1000L; Throwable caught = catchThrowable(() -> { filter.doFilter(request, response, chain); verify(chain).doFilter(request, response); }); long after = System.currentTimeMillis(); after += 1000L - (after % 1000L); verify(response).setHeader("Cache-Control", "max-age=" + secsToLive + ", public"); verify(response).setHeader("Pragma", "cache"); verify(response).setDateHeader(eq("Expires"), anyLong()); assertThat(response.getDateHeader("Expires")).isBetween(before + secsToLive, after + secsToLive); assertThat(caught).isNull(); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("Cache-Control", "max-age=" + cacheTimeToLive + ", public"); httpResponse.setHeader("Pragma", "cache"); httpResponse.setDateHeader("Expires", cacheTimeToLive + System.currentTimeMillis()); chain.doFilter(request, response); }
CachingHttpHeadersFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("Cache-Control", "max-age=" + cacheTimeToLive + ", public"); httpResponse.setHeader("Pragma", "cache"); httpResponse.setDateHeader("Expires", cacheTimeToLive + System.currentTimeMillis()); chain.doFilter(request, response); } }
CachingHttpHeadersFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("Cache-Control", "max-age=" + cacheTimeToLive + ", public"); httpResponse.setHeader("Pragma", "cache"); httpResponse.setDateHeader("Expires", cacheTimeToLive + System.currentTimeMillis()); chain.doFilter(request, response); } CachingHttpHeadersFilter(JHipsterProperties jHipsterProperties); }
CachingHttpHeadersFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("Cache-Control", "max-age=" + cacheTimeToLive + ", public"); httpResponse.setHeader("Pragma", "cache"); httpResponse.setDateHeader("Expires", cacheTimeToLive + System.currentTimeMillis()); chain.doFilter(request, response); } CachingHttpHeadersFilter(JHipsterProperties jHipsterProperties); @Override void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
CachingHttpHeadersFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setHeader("Cache-Control", "max-age=" + cacheTimeToLive + ", public"); httpResponse.setHeader("Pragma", "cache"); httpResponse.setDateHeader("Expires", cacheTimeToLive + System.currentTimeMillis()); chain.doFilter(request, response); } CachingHttpHeadersFilter(JHipsterProperties jHipsterProperties); @Override void init(FilterConfig filterConfig); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); static final int DEFAULT_DAYS_TO_LIVE; static final long DEFAULT_SECONDS_TO_LIVE; }