@Test public void testReferer_invalidContext() throws IOException { when(request.getHeader(HttpHeaders.REFERER)).thenReturn("/invalid/path"); servlet.doGet(request, response); verify(response).sendError(HttpServletResponse.SC_NOT_FOUND, "The path of the edited page cannot be determined"); }
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { if (WCMMode.DISABLED == WCMMode.fromRequest(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The request not permitted"); return; } Page page = getRefererPage(request); if (page == null) { LOGGER.warn("The path of the edited page cannot be determined"); response.sendError(HttpServletResponse.SC_NOT_FOUND, "The path of the edited page cannot be determined"); return; } Map<String, String> params = new UrlProvider.ParamsBuilder() .id(request.getParameter((UrlProvider.ID_PARAM))) .sku(request.getParameter(UrlProvider.SKU_PARAM)) .variantSku(request.getParameter(UrlProvider.VARIANT_SKU_PARAM)) .urlKey(request.getParameter(UrlProvider.URL_KEY_PARAM)) .urlPath(request.getParameter(UrlProvider.URL_PATH_PARAM)) .variantUrlKey(request.getParameter(UrlProvider.VARIANT_URL_KEY_PARAM)) .map(); String previewSelector = request.getRequestPathInfo().getSelectors()[0]; String url = PREVIEW_PRODUCT.equals(previewSelector) ? urlProvider.toProductUrl(request, page, params) : urlProvider.toCategoryUrl(request, page, params); response.sendRedirect(url); }
PreviewServlet extends SlingSafeMethodsServlet { protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { if (WCMMode.DISABLED == WCMMode.fromRequest(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The request not permitted"); return; } Page page = getRefererPage(request); if (page == null) { LOGGER.warn("The path of the edited page cannot be determined"); response.sendError(HttpServletResponse.SC_NOT_FOUND, "The path of the edited page cannot be determined"); return; } Map<String, String> params = new UrlProvider.ParamsBuilder() .id(request.getParameter((UrlProvider.ID_PARAM))) .sku(request.getParameter(UrlProvider.SKU_PARAM)) .variantSku(request.getParameter(UrlProvider.VARIANT_SKU_PARAM)) .urlKey(request.getParameter(UrlProvider.URL_KEY_PARAM)) .urlPath(request.getParameter(UrlProvider.URL_PATH_PARAM)) .variantUrlKey(request.getParameter(UrlProvider.VARIANT_URL_KEY_PARAM)) .map(); String previewSelector = request.getRequestPathInfo().getSelectors()[0]; String url = PREVIEW_PRODUCT.equals(previewSelector) ? urlProvider.toProductUrl(request, page, params) : urlProvider.toCategoryUrl(request, page, params); response.sendRedirect(url); } }
PreviewServlet extends SlingSafeMethodsServlet { protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { if (WCMMode.DISABLED == WCMMode.fromRequest(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The request not permitted"); return; } Page page = getRefererPage(request); if (page == null) { LOGGER.warn("The path of the edited page cannot be determined"); response.sendError(HttpServletResponse.SC_NOT_FOUND, "The path of the edited page cannot be determined"); return; } Map<String, String> params = new UrlProvider.ParamsBuilder() .id(request.getParameter((UrlProvider.ID_PARAM))) .sku(request.getParameter(UrlProvider.SKU_PARAM)) .variantSku(request.getParameter(UrlProvider.VARIANT_SKU_PARAM)) .urlKey(request.getParameter(UrlProvider.URL_KEY_PARAM)) .urlPath(request.getParameter(UrlProvider.URL_PATH_PARAM)) .variantUrlKey(request.getParameter(UrlProvider.VARIANT_URL_KEY_PARAM)) .map(); String previewSelector = request.getRequestPathInfo().getSelectors()[0]; String url = PREVIEW_PRODUCT.equals(previewSelector) ? urlProvider.toProductUrl(request, page, params) : urlProvider.toCategoryUrl(request, page, params); response.sendRedirect(url); }  }
PreviewServlet extends SlingSafeMethodsServlet { protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { if (WCMMode.DISABLED == WCMMode.fromRequest(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The request not permitted"); return; } Page page = getRefererPage(request); if (page == null) { LOGGER.warn("The path of the edited page cannot be determined"); response.sendError(HttpServletResponse.SC_NOT_FOUND, "The path of the edited page cannot be determined"); return; } Map<String, String> params = new UrlProvider.ParamsBuilder() .id(request.getParameter((UrlProvider.ID_PARAM))) .sku(request.getParameter(UrlProvider.SKU_PARAM)) .variantSku(request.getParameter(UrlProvider.VARIANT_SKU_PARAM)) .urlKey(request.getParameter(UrlProvider.URL_KEY_PARAM)) .urlPath(request.getParameter(UrlProvider.URL_PATH_PARAM)) .variantUrlKey(request.getParameter(UrlProvider.VARIANT_URL_KEY_PARAM)) .map(); String previewSelector = request.getRequestPathInfo().getSelectors()[0]; String url = PREVIEW_PRODUCT.equals(previewSelector) ? urlProvider.toProductUrl(request, page, params) : urlProvider.toCategoryUrl(request, page, params); response.sendRedirect(url); }   }
PreviewServlet extends SlingSafeMethodsServlet { protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { if (WCMMode.DISABLED == WCMMode.fromRequest(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The request not permitted"); return; } Page page = getRefererPage(request); if (page == null) { LOGGER.warn("The path of the edited page cannot be determined"); response.sendError(HttpServletResponse.SC_NOT_FOUND, "The path of the edited page cannot be determined"); return; } Map<String, String> params = new UrlProvider.ParamsBuilder() .id(request.getParameter((UrlProvider.ID_PARAM))) .sku(request.getParameter(UrlProvider.SKU_PARAM)) .variantSku(request.getParameter(UrlProvider.VARIANT_SKU_PARAM)) .urlKey(request.getParameter(UrlProvider.URL_KEY_PARAM)) .urlPath(request.getParameter(UrlProvider.URL_PATH_PARAM)) .variantUrlKey(request.getParameter(UrlProvider.VARIANT_URL_KEY_PARAM)) .map(); String previewSelector = request.getRequestPathInfo().getSelectors()[0]; String url = PREVIEW_PRODUCT.equals(previewSelector) ? urlProvider.toProductUrl(request, page, params) : urlProvider.toCategoryUrl(request, page, params); response.sendRedirect(url); }    }