@Override public RequestDispatcher getRequestDispatcher(String path, RequestDispatcherOptions options) { return getSlingRequest().getRequestDispatcher(path, options); }
@Override public RequestDispatcher getRequestDispatcher(Resource resource, RequestDispatcherOptions options) { return getSlingRequest().getRequestDispatcher(resource, options); }
@Override public RequestDispatcher getRequestDispatcher(Resource resource) { return getSlingRequest().getRequestDispatcher(resource); }
@SlingServlet(metatype = true, resourceTypes = {"/apps/sling/servlet/errorhandler"}, extensions = {"404"}) public class ErrorServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setStatus(HttpServletResponse.SC_NOT_FOUND); RequestDispatcher dispatcher = request.getRequestDispatcher("myPath"); dispatcher.include(request,response); } }
final RequestDispatcher requestDispatcher = request.getRequestDispatcher( resource.getPath() + "." + EXTENSION_HTML);
/** * Return AssetList component HTML in the response. * * @param request The Sling HTTP servlet request. * @param response The Sling HTTP servlet response. */ @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource resource = request.getResourceResolver().getResource(ASSET_LIST_COMPONENT_PATH); request.getRequestDispatcher(resource).include(request, response); } }
@Override public final void forwardAsGet(final Form form, final String path, final SlingHttpServletRequest request, final SlingHttpServletResponse response, final RequestDispatcherOptions options) throws ServletException, IOException { this.setRequestAttrForm(request, form); final SlingHttpServletRequest syntheticRequest = new SyntheticSlingHttpServletGetRequest(request); if (log.isDebugEnabled()) { log.debug("Forwarding as GET to path: {} ", path); log.debug("Forwarding as GET w/ replace selectors: {} ", options.getReplaceSelectors()); log.debug("Forwarding as GET w/ add selectors: {} ", options.getAddSelectors()); log.debug("Forwarding as GET w/ suffix: {} ", options.getReplaceSuffix()); log.debug("Forwarding as GET w/ forced resourceType: {} ", options.getForceResourceType()); } request.getRequestDispatcher(path, options).forward(syntheticRequest, response); }
@Override public final void forwardAsGet(final Form form, final String path, final SlingHttpServletRequest request, final SlingHttpServletResponse response, final RequestDispatcherOptions options) throws ServletException, IOException { this.setRequestAttrForm(request, form); final SlingHttpServletRequest syntheticRequest = new SyntheticSlingHttpServletGetRequest(request); if (log.isDebugEnabled()) { log.debug("Forwarding as GET to path: {} ", path); log.debug("Forwarding as GET w/ replace selectors: {} ", options.getReplaceSelectors()); log.debug("Forwarding as GET w/ add selectors: {} ", options.getAddSelectors()); log.debug("Forwarding as GET w/ suffix: {} ", options.getReplaceSuffix()); log.debug("Forwarding as GET w/ forced resourceType: {} ", options.getForceResourceType()); } request.getRequestDispatcher(path, options).forward(syntheticRequest, response); }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { final String resourceType = getResourceTypeFromSuffix(request); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setForceResourceType(resourceType); final RequestDispatcher dispatcher = request.getRequestDispatcher(request.getResource(), options); dispatcher.forward(request, response); }
public static String getIncludeAsString(final String path, final SlingHttpServletRequest slingRequest, final SlingHttpServletResponse slingResponse) { StringWriterResponse responseWrapper = null; try { responseWrapper = new StringWriterResponse(slingResponse); final RequestDispatcher requestDispatcher = slingRequest.getRequestDispatcher(path); requestDispatcher.include(slingRequest, responseWrapper); return StringUtils.stripToNull(responseWrapper.getString()); } catch (Exception ex) { log.error("Error creating the String representation for: " + path, ex); } finally { if (responseWrapper != null) { responseWrapper.clearWriter(); } } return null; }
public static String getIncludeAsString(final String path, final SlingHttpServletRequest slingRequest, final SlingHttpServletResponse slingResponse) { StringWriterResponse responseWrapper = null; try { responseWrapper = new StringWriterResponse(slingResponse); final RequestDispatcher requestDispatcher = slingRequest.getRequestDispatcher(path); requestDispatcher.include(slingRequest, responseWrapper); return StringUtils.stripToNull(responseWrapper.getString()); } catch (Exception ex) { log.error("Error creating the String representation for: {} -- {}", path, ex); } finally { if (responseWrapper != null) { responseWrapper.clearWriter(); } } return null; }
@Override public void includeUsingGET(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final String path) { if (cache == null || errorImagesEnabled && this.isImageRequest(request)) { final RequestDispatcher dispatcher = request.getRequestDispatcher(path); if (dispatcher != null) { try { dispatcher.include(new GetRequest(request), response); } catch (Exception e) { log.debug("Exception swallowed while including error page", e); } } } else { final String responseData = cache.get(path, new GetRequest(request), response); try { response.getWriter().write(responseData); } catch (Exception e) { log.info("Exception swallowed while including error page", e); } } }
public void includeUsingGET(final SlingHttpServletRequest request, final SlingHttpServletResponse response, final String path) { if (cache == null || errorImagesEnabled && this.isImageRequest(request)) { final RequestDispatcher dispatcher = request.getRequestDispatcher(path); if (dispatcher != null) { try { dispatcher.include(new GetRequest(request), response); } catch (Exception e) { log.debug("Exception swallowed while including error page", e); } } } else { final String responseData = cache.get(path, new GetRequest(request), response); try { response.getWriter().write(responseData); } catch (Exception e) { log.info("Exception swallowed while including error page", e); } } }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource contentResource = request.getResourceResolver().getResource(request.getResource(), JcrConstants.JCR_CONTENT); if (contentResource == null) { log.error("No content for page {}", request.getResource()); response.sendError(HttpServletResponse.SC_NOT_FOUND, "no content"); return; } RequestDispatcher requestDispatcher = request.getRequestDispatcher(contentResource); if (requestDispatcher != null) { requestDispatcher.include(request, response); } else { log.error("Failed to get request dispatcher for content of {}", request.getResource()); throw new ServletException("No Content"); } } }
public boolean dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException, RepositoryException { if (request.getAttribute(VANITY_DISPATCH_CHECK_ATTR) != null) { log.trace("Processing a previously vanity dispatched request. Skipping..."); return false; } request.setAttribute(VANITY_DISPATCH_CHECK_ATTR, true); final String requestURI = request.getRequestURI(); final RequestPathInfo mappedPathInfo = new PathInfo(request.getResourceResolver(), requestURI); final String candidateVanity = mappedPathInfo.getResourcePath(); final String pathScope = StringUtils.removeEnd(requestURI, candidateVanity); log.debug("Candidate vanity URL to check and dispatch: [ {} ]", candidateVanity); // Check if... // 1) the candidateVanity and the requestURI are the same; If they are it means the request has already // gone through resource resolution and failed so there is no sense in sending it through again. // 2) the candidate is in at least 1 sling:vanityPath under /content if (!StringUtils.equals(candidateVanity, requestURI) && isVanityPath(pathScope, candidateVanity, request)) { log.debug("Forwarding request to vanity resource [ {} ]", candidateVanity); final RequestDispatcher requestDispatcher = request.getRequestDispatcher(candidateVanity); requestDispatcher.forward(new ExtensionlessRequestWrapper(request), response); return true; } return false; }
private void doInclude() { Resource handlerContent = handler.getChild(JcrConstants.JCR_CONTENT); if (handlerContent != null) { log.debug("Including handler {}", handlerContent); RequestDispatcherOptions rdo = new RequestDispatcherOptions(); rdo.setReplaceSelectors(""); rdo.setReplaceSuffix(""); rdo.setForceResourceType(handlerContent.getResourceType()); final RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(handlerContent, rdo); if (dispatcher != null) { try { dispatcher.include(new GetRequest(slingRequest), slingResponse); } catch (Exception e) { log.debug("Exception swallowed while including error page", e); } } else { log.warn("Failed to get request dispatcher for handler {}", handler.getPath()); } } else { log.warn("Error hander {} content is null", handler); } }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); if (!this.accepts(request)) { response.setStatus(SlingHttpServletResponse.SC_NOT_FOUND); response.getWriter().write("{}"); } /* Servlet accepts this request */ RequestUtil.setRequestAttribute(request, REQ_ATTR, true); final String namespace = URLDecoder.decode(PathInfoUtil.getSelector(request, NAME_PROPERTY_SELECTOR_INDEX), "UTF-8"); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(AEM_CQ_INCLUDE_SELECTORS); final BufferingResponse bufferingResponse = new BufferingResponse(response); request.getRequestDispatcher(request.getResource(), options).forward(request, bufferingResponse); Gson gson = new Gson(); final JsonObject json = gson.toJsonTree(bufferingResponse.getContents()).getAsJsonObject(); final PropertyNamespaceUpdater propertyNamespaceUpdater = new PropertyNamespaceUpdater(namespace); propertyNamespaceUpdater.accept(json); response.getWriter().write(json.toString()); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; final String resourceType = getResourceTypeFromSuffix(slingRequest); final Configuration config = configurationWhiteboard.getConfiguration(slingRequest, resourceType); if (config == null || !config.hasIncludeSelector(slingRequest) || !ResourceUtil.isSyntheticResource(slingRequest.getResource())) { chain.doFilter(request, response); return; } final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setForceResourceType(resourceType); final RequestDispatcher dispatcher = slingRequest.getRequestDispatcher(slingRequest.getResource(), options); dispatcher.forward(request, response); }
private static String doRender(Resource resource, String requestMethod, String requestExtension, SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { SynthesizedSlingHttpServletRequest synthesizedRequest = new SynthesizedSlingHttpServletRequest(request) .setMethod(requestMethod) .setExtension(requestExtension) .setResource(resource); RequestDispatcherOptions rdo = new RequestDispatcherOptions(); IncludeOptions.getOptions(synthesizedRequest, true).setDecorationTagName(""); // @ROCK SOLID MAGIC .. remove decoration <div> by setting it to "" empty string StringResponseWrapper responseWrapper = new StringResponseWrapper(response); RequestDispatcher requestDispatcher = request.getRequestDispatcher(resource, rdo); requestDispatcher.include(synthesizedRequest, responseWrapper); return responseWrapper.getString(); }
private static String doRender(Resource resource, String requestMethod, String requestExtension, SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { SynthesizedSlingHttpServletRequest synthesizedRequest = new SynthesizedSlingHttpServletRequest(request) .setMethod(requestMethod) .setExtension(requestExtension) .setResource(resource); RequestDispatcherOptions rdo = new RequestDispatcherOptions(); IncludeOptions.getOptions(synthesizedRequest, true).setDecorationTagName(""); // @ROCK SOLID MAGIC .. remove decoration <div> by setting it to "" empty string StringResponseWrapper responseWrapper = new StringResponseWrapper(response); RequestDispatcher requestDispatcher = request.getRequestDispatcher(resource, rdo); requestDispatcher.include(synthesizedRequest, responseWrapper); return responseWrapper.getString(); }