@Test public void passThroughLocalPath() throws Exception { final String requestUri = localPaths[0]; final HttpServletRequest req = mock(HttpServletRequest.class); when(req.getRequestURI()).thenReturn(requestUri); when(req.getContextPath()).thenReturn(""); final ServletResponse response = mock(ServletResponse.class); final FilterChain chain = mock(FilterChain.class); filter.doFilter(req, response, chain); verify(req, atLeastOnce()).getRequestURI(); verify(chain).doFilter(req, response); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpRequest = (HttpServletRequest) request; if (isUriInLocalPaths(httpRequest)) { LOGGER.debug("Passing through request for {}", httpRequest.getRequestURI()); chain.doFilter(request, response); } else { if (isUriInCheckPaths(httpRequest)) { try { if (!spaceChecker.isSpaceAvailable()) { ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } catch (DiskSpaceCheckerException e) { LOGGER.error("Exception thrown by DiskSpaceChecker", e); ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } if (!response.isCommitted()) { RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(getProxyPath(httpRequest)); dispatcher.forward(request, response); } } }
DiskSpaceFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpRequest = (HttpServletRequest) request; if (isUriInLocalPaths(httpRequest)) { LOGGER.debug("Passing through request for {}", httpRequest.getRequestURI()); chain.doFilter(request, response); } else { if (isUriInCheckPaths(httpRequest)) { try { if (!spaceChecker.isSpaceAvailable()) { ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } catch (DiskSpaceCheckerException e) { LOGGER.error("Exception thrown by DiskSpaceChecker", e); ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } if (!response.isCommitted()) { RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(getProxyPath(httpRequest)); dispatcher.forward(request, response); } } } }
DiskSpaceFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpRequest = (HttpServletRequest) request; if (isUriInLocalPaths(httpRequest)) { LOGGER.debug("Passing through request for {}", httpRequest.getRequestURI()); chain.doFilter(request, response); } else { if (isUriInCheckPaths(httpRequest)) { try { if (!spaceChecker.isSpaceAvailable()) { ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } catch (DiskSpaceCheckerException e) { LOGGER.error("Exception thrown by DiskSpaceChecker", e); ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } if (!response.isCommitted()) { RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(getProxyPath(httpRequest)); dispatcher.forward(request, response); } } } DiskSpaceFilter(DiskSpaceChecker spaceChecker, ProxyConfiguration proxyConfiguration, String... localPaths); }
DiskSpaceFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpRequest = (HttpServletRequest) request; if (isUriInLocalPaths(httpRequest)) { LOGGER.debug("Passing through request for {}", httpRequest.getRequestURI()); chain.doFilter(request, response); } else { if (isUriInCheckPaths(httpRequest)) { try { if (!spaceChecker.isSpaceAvailable()) { ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } catch (DiskSpaceCheckerException e) { LOGGER.error("Exception thrown by DiskSpaceChecker", e); ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } if (!response.isCommitted()) { RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(getProxyPath(httpRequest)); dispatcher.forward(request, response); } } } DiskSpaceFilter(DiskSpaceChecker spaceChecker, ProxyConfiguration proxyConfiguration, String... localPaths); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response,
						 FilterChain chain); @Override void destroy(); }
DiskSpaceFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest httpRequest = (HttpServletRequest) request; if (isUriInLocalPaths(httpRequest)) { LOGGER.debug("Passing through request for {}", httpRequest.getRequestURI()); chain.doFilter(request, response); } else { if (isUriInCheckPaths(httpRequest)) { try { if (!spaceChecker.isSpaceAvailable()) { ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } catch (DiskSpaceCheckerException e) { LOGGER.error("Exception thrown by DiskSpaceChecker", e); ((HttpServletResponse) response).sendError(proxyConfiguration.getErrorStatus()); } } if (!response.isCommitted()) { RequestDispatcher dispatcher = httpRequest.getRequestDispatcher(getProxyPath(httpRequest)); dispatcher.forward(request, response); } } } DiskSpaceFilter(DiskSpaceChecker spaceChecker, ProxyConfiguration proxyConfiguration, String... localPaths); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response,
						 FilterChain chain); @Override void destroy();  }