@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); }
@Override public final void renderOtherForm(final Form form, final String path, final String formSelector, final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException, ServletException { final RequestDispatcherOptions options = new RequestDispatcherOptions(); if (StringUtils.isNotBlank(formSelector)) { options.setReplaceSelectors(formSelector); } this.forwardAsGet(form, path, request, response, options); }
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 public final void forwardAsGet(final Form form, final Page page, final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(""); options.setForceResourceType(CQ_PAGE_RESOURCE_TYPE); this.forwardAsGet(form, page, request, response, options); }
@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); }
final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(formSelector); options.setReplaceSuffix(slingRequest.getRequestPathInfo().getSuffix()); log.debug("Form Filter; Internal forward w/ replace selectors: {} ", options.getReplaceSelectors()); log.debug("Form Filter; Internal forward w/ suffix: {} ", options.getReplaceSuffix());
final RequestDispatcherOptions opts = new RequestDispatcherOptions(); opts.setForceResourceType(resourceType); opts.setReplaceSelectors(replaceSelectors); opts.setAddSelectors(addSelectors); opts.setReplaceSuffix(replaceSuffix); opts.remove(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE);
private RequestDispatcherOptions handleDispatcherOptions(SlingHttpServletRequest request, Set<String> selectors, Map<String, Object> options, RuntimeObjectModel runtimeObjectModel) { RequestDispatcherOptions requestDispatcherOptions = new RequestDispatcherOptions(); if (selectors.isEmpty()) { selectors.addAll(Arrays.asList(request.getRequestPathInfo().getSelectors())); requestDispatcherOptions.setAddSelectors(getSelectorString(selectors)); requestDispatcherOptions.setReplaceSelectors(""); if (options.containsKey(OPTION_SELECTORS)) { Object selectorsObject = getAndRemoveOption(options, OPTION_SELECTORS); selectors.clear(); addSelectors(selectors, selectorsObject, runtimeObjectModel); requestDispatcherOptions.setAddSelectors(getSelectorString(selectors)); requestDispatcherOptions.setReplaceSelectors(""); requestDispatcherOptions.setAddSelectors(getSelectorString(selectors)); requestDispatcherOptions.setReplaceSelectors(""); requestDispatcherOptions.setReplaceSelectors(""); } else { requestDispatcherOptions.setAddSelectors(getSelectorString(selectors)); requestDispatcherOptions.setReplaceSelectors(""); String resourceType = runtimeObjectModel.toString(getAndRemoveOption(options, OPTION_RESOURCE_TYPE)); if (StringUtils.isNotEmpty(resourceType)) { requestDispatcherOptions.setForceResourceType(resourceType);
RequestDispatcherOptions rdo = new RequestDispatcherOptions(); rdo.setReplaceSuffix(""); rdo.setReplaceSelectors("");
@Override public final void forwardAsGet(final Form form, final Resource resource, final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { final RequestDispatcherOptions options = new RequestDispatcherOptions(); this.forwardAsGet(form, resource, request, response, options); }
setForceResourceType(options.trim()); } else { final StringTokenizer tk = new StringTokenizer(options, ","); int equals = entry.indexOf('='); if (equals > 0 && equals < entry.length() - 1) { put(entry.substring(0, equals).trim(), entry.substring( equals + 1).trim());
@Override public final void forwardAsGet(final Form form, final Page page, final SlingHttpServletRequest request, final SlingHttpServletResponse response, final RequestDispatcherOptions options) throws ServletException, IOException { options.setForceResourceType(CQ_PAGE_RESOURCE_TYPE); final String path = page.getPath() + FormHelper.EXTENSION; this.forwardAsGet(form, path, request, response, options); }
private void includeResource(SlingHttpServletRequest request, final Bindings bindings, PrintWriter out, Resource includeRes, RequestDispatcherOptions requestDispatcherOptions) { if (includeRes == null) { throw new SightlyException("Resource cannot be null"); } else { if (request.getResource().getPath().equals(includeRes.getPath())) { String requestSelectorString = request.getRequestPathInfo().getSelectorString(); String requestDispatcherAddSelectors = requestDispatcherOptions.getAddSelectors(); if ( (requestSelectorString == null ? requestDispatcherAddSelectors == null : requestSelectorString.equals(requestDispatcherAddSelectors)) && StringUtils.EMPTY.equals(requestDispatcherOptions.getReplaceSelectors()) && (requestDispatcherOptions.getForceResourceType() == null || requestDispatcherOptions.getForceResourceType().equals(request.getResource().getResourceType())) ) { LOGGER.warn("Will not include resource {} since this will lead to a {} exception.", includeRes.getPath(), "org.apache.sling.api.request.RecursionTooDeepException"); return; } } SlingHttpServletResponse customResponse = new PrintWriterResponseWrapper(out, BindingsUtils.getResponse(bindings)); RequestDispatcher dispatcher = request.getRequestDispatcher(includeRes, requestDispatcherOptions); try { if (dispatcher != null) { dispatcher.include(request, customResponse); } else { throw new SightlyException("Failed to include resource " + includeRes.getPath()); } } catch (Exception e) { throw new SightlyException("Failed to include resource " + includeRes.getPath(), e); } } }
private void includeResource(SlingHttpServletRequest request, final Bindings bindings, PrintWriter out, String path, RequestDispatcherOptions requestDispatcherOptions) { if (StringUtils.isEmpty(path)) { throw new SightlyException("Resource path cannot be empty"); } else { Resource includeRes = request.getResourceResolver().resolve(path); if (ResourceUtil.isNonExistingResource(includeRes)) { String resourceType = request.getResource().getResourceType(); if (requestDispatcherOptions.containsKey(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE)) { resourceType = requestDispatcherOptions.getForceResourceType(); } includeRes = new SyntheticResource(request.getResourceResolver(), path, resourceType); } includeResource(request, bindings, out, includeRes, requestDispatcherOptions); } }
final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(formSelector); options.setReplaceSuffix(slingRequest.getRequestPathInfo().getSuffix()); log.debug("Form Filter; Internal forward w/ replace selectors: {} ", options.getReplaceSelectors()); log.debug("Form Filter; Internal forward w/ suffix: {} ", options.getReplaceSuffix());
@Override public final void forwardAsGet(final Form form, final Page page, final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(""); options.setForceResourceType(CQ_PAGE_RESOURCE_TYPE); this.forwardAsGet(form, page, request, response, options); }
@Override public final void forwardAsGet(final Form form, final Resource resource, final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { final RequestDispatcherOptions options = new RequestDispatcherOptions(); this.forwardAsGet(form, resource, request, response, options); }
@Override public final void forwardAsGet(final Form form, final Page page, final SlingHttpServletRequest request, final SlingHttpServletResponse response, final RequestDispatcherOptions options) throws ServletException, IOException { options.setForceResourceType(CQ_PAGE_RESOURCE_TYPE); final String path = page.getPath() + FormHelper.EXTENSION; this.forwardAsGet(form, path, request, response, options); }
@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); }
/** * Delegates request through to the target resource type * * @param request * @param response */ private void delegate(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException { final RequestDispatcherOptions options = new RequestDispatcherOptions(); if(this.isCyclic(request, targetResourceType)) { log.error("Delegation Servlet creating a cycle for Target Resource Type: {}", targetResourceType); throw new ServletException("Cyclic delegation detected for " + targetResourceType); } if(StringUtils.isNotBlank(targetResourceType)) { log.debug("Delegating Request resource type with: {}", targetResourceType); options.setForceResourceType(targetResourceType); } else { log.warn("Delegating Servlet's \"Target Resource Type\" is blank or null"); } try { this.setDelegationHistory(request, targetResourceType); request.getRequestDispatcher(request.getResource(), options).forward(request, response); } catch (ServletException e) { log.error("Could not properly re-route request to delegate resource type: {}", targetResourceType); } catch (IOException e) { log.error("Could not properly re-route request to delegate resource type: {}", targetResourceType); } }