@Test public void testFilterNoopWcmmode() throws IOException, ServletException { request.setResource(context.resourceResolver().resolve("/content/product-page")); MockRequestPathInfo pathInfo = (MockRequestPathInfo) request.getRequestPathInfo(); pathInfo.setSelectorString("productId1"); request.setAttribute(WCMMode.class.getName(), WCMMode.EDIT); filter.doFilter(request, null, chain); Mockito.verify(requestDispatcherFactory, Mockito.times(0)).getRequestDispatcher(any(Resource.class), any()); Mockito.verify(chain).doFilter(request, null); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; String selector = slingRequest.getRequestPathInfo().getSelectorString(); if (selector == null) { chain.doFilter(request, response); return; } WCMMode wcmMode = WCMMode.fromRequest(request); if (!WCMMode.DISABLED.equals(wcmMode)) { chain.doFilter(request, response); return; } Resource page = slingRequest.getResource(); LOGGER.debug("Checking sub-pages for {}", slingRequest.getRequestURI()); Resource subPage = UrlProviderImpl.toSpecificPage(page, selector); if (subPage != null) { RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(subPage); dispatcher.forward(slingRequest, response); return; } chain.doFilter(request, response); }
SpecificPageFilterFactory implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; String selector = slingRequest.getRequestPathInfo().getSelectorString(); if (selector == null) { chain.doFilter(request, response); return; } WCMMode wcmMode = WCMMode.fromRequest(request); if (!WCMMode.DISABLED.equals(wcmMode)) { chain.doFilter(request, response); return; } Resource page = slingRequest.getResource(); LOGGER.debug("Checking sub-pages for {}", slingRequest.getRequestURI()); Resource subPage = UrlProviderImpl.toSpecificPage(page, selector); if (subPage != null) { RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(subPage); dispatcher.forward(slingRequest, response); return; } chain.doFilter(request, response); } }
SpecificPageFilterFactory implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; String selector = slingRequest.getRequestPathInfo().getSelectorString(); if (selector == null) { chain.doFilter(request, response); return; } WCMMode wcmMode = WCMMode.fromRequest(request); if (!WCMMode.DISABLED.equals(wcmMode)) { chain.doFilter(request, response); return; } Resource page = slingRequest.getResource(); LOGGER.debug("Checking sub-pages for {}", slingRequest.getRequestURI()); Resource subPage = UrlProviderImpl.toSpecificPage(page, selector); if (subPage != null) { RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(subPage); dispatcher.forward(slingRequest, response); return; } chain.doFilter(request, response); }  }
SpecificPageFilterFactory implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; String selector = slingRequest.getRequestPathInfo().getSelectorString(); if (selector == null) { chain.doFilter(request, response); return; } WCMMode wcmMode = WCMMode.fromRequest(request); if (!WCMMode.DISABLED.equals(wcmMode)) { chain.doFilter(request, response); return; } Resource page = slingRequest.getResource(); LOGGER.debug("Checking sub-pages for {}", slingRequest.getRequestURI()); Resource subPage = UrlProviderImpl.toSpecificPage(page, selector); if (subPage != null) { RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(subPage); dispatcher.forward(slingRequest, response); return; } chain.doFilter(request, response); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy(); }
SpecificPageFilterFactory implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; String selector = slingRequest.getRequestPathInfo().getSelectorString(); if (selector == null) { chain.doFilter(request, response); return; } WCMMode wcmMode = WCMMode.fromRequest(request); if (!WCMMode.DISABLED.equals(wcmMode)) { chain.doFilter(request, response); return; } Resource page = slingRequest.getResource(); LOGGER.debug("Checking sub-pages for {}", slingRequest.getRequestURI()); Resource subPage = UrlProviderImpl.toSpecificPage(page, selector); if (subPage != null) { RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(subPage); dispatcher.forward(slingRequest, response); return; } chain.doFilter(request, response); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }