Examples of SlingHttpServletRequest


Examples of org.apache.sling.api.SlingHttpServletRequest

    /**
     * {@inheritDoc}
     */
    @Override
    public int doStartTag() throws JspException {
        SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
        if (componentHelper.isEditMode(request)) {
            return EVAL_BODY_BUFFERED;
        } else {
            return SKIP_BODY;
        }
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

    /**
     * {@inheritDoc}
     */
    @Override
    public int doEndTag() throws JspException {
        SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
        Component component = WCMUtils.getComponent(request.getResource());
        if (componentHelper.isEditMode(request)) {
            JspWriter writer = pageContext.getOut();
            String placeholder;

            String bodyContentString = bodyContent != null ? bodyContent.getString() : null;
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

        if (!this.accepts(request, response)) {
            chain.doFilter(request, response);
            return;
        }

        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
        final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;

        final ComponentContext componentContext = WCMUtils.getComponentContext(request);

        if (componentContext == null
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

            return false;
        }

        // Check to make sure the SlingRequest's resource isn't in the suppress list
        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
        for (final String suppressedResourceType : suppressedResourceTypes) {
            if (slingRequest.getResource().isResourceType(suppressedResourceType)) {
                return false;
            }
        }

        return true;
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

    public static SlingHttpServletRequest toSlingHttpServletRequest(
            ServletRequest request) {

        // unwrap to SlingHttpServletRequest, may throw if no
        // SlingHttpServletRequest is wrapped in request
        SlingHttpServletRequest cRequest = unwrap(request);

        // ensure the SlingHttpServletRequest is backed by
        // SlingHttpServletRequestImpl
        RequestData.unwrap(cRequest);
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

            HttpServletResponse servletResponse) throws IOException {

        // setting the Sling request and response
        final RequestData requestData = new RequestData(this, servletRequest,
            servletResponse);
        SlingHttpServletRequest request = requestData.getSlingRequest();
        SlingHttpServletResponse response = requestData.getSlingResponse();

        // request entry log
        if (requestLogger != null) {
            requestLogger.logRequestEntry(request, response);
        }

        Session session = null;
        try {
            // check that we have all required services
            String missing = null;
            if (getResourceResolverFactory() == null) {
                missing = "ResourceResolverFactory";
            } else if (getServletResolver() == null) {
                missing = "ServletResolver";
            } else if (mimeTypeService == null) {
                missing = "MimeTypeService";
            }

            if (missing != null) {
                final String err = missing
                    + " service missing, cannot service requests";
                final int status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
                log.error("{} , sending status {}", err, status);
                sendError(status, err, null, servletRequest, servletResponse);
                return;
            }

            // get JCR Session
            session = (Session) servletRequest.getAttribute(SESSION);
            if (session == null) {
                log.error("service: Cannot handle request: Missing JCR Session");
                sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                    "Missing JCR Session", null, servletRequest, servletResponse);
                return;
            }

            // initialize the request data - resolve resource and servlet
            ResourceResolver resolver = getResourceResolverFactory().getResourceResolver(
                session);
            Resource resource = requestData.initResource(resolver);
            requestData.initServlet(resource);

            Filter[] filters = requestFilterChain.getFilters();
            if (filters != null) {
                FilterChain processor = new RequestSlingFilterChain(this,
                    filters);

                processor.doFilter(request, response);

            } else {

                // no filters, directly call resource level filters and servlet
                processRequest(request, response);

            }

        } catch (ResourceNotFoundException rnfe) {

            // send this exception as a 404 status
            log.info("service: Resource {} not found", rnfe.getResource());

            getErrorHandler().handleError(HttpServletResponse.SC_NOT_FOUND,
                rnfe.getMessage(), request, response);

        } catch (SlingException se) {

            // if we have request data and a non-null active servlet name
            // we assume, that this is the name of the causing servlet
            if (requestData.getActiveServletName() != null) {
                request.setAttribute(ERROR_SERVLET_NAME,
                    requestData.getActiveServletName());
            }

            // send this exception as is (albeit unwrapping and wrapped
            // exception.
            Throwable t = (se.getCause() != null) ? se.getCause() : se;
            log.error("service: Uncaught SlingException", t);
            getErrorHandler().handleError(t, request, response);

        } catch (AccessControlException ace) {

            // SLING-319 if anything goes wrong, send 403/FORBIDDEN
            log.info(
                "service: Authenticated user {} does not have enough rights to executed requested action",
                request.getRemoteUser());
            getErrorHandler().handleError(HttpServletResponse.SC_FORBIDDEN,
                null, request, response);

        } catch (Throwable t) {

            // if we have request data and a non-null active servlet name
            // we assume, that this is the name of the causing servlet
            if (requestData.getActiveServletName() != null) {
                request.setAttribute(ERROR_SERVLET_NAME,
                    requestData.getActiveServletName());
            }

            log.error("service: Uncaught Throwable", t);
            getErrorHandler().handleError(t, request, response);
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

            RequestPathInfo resolvedURL) throws IOException, ServletException {

        checkRecursionLevel(request, resolvedURL.getResourcePath());

        // we need a SlingHttpServletRequest/SlingHttpServletResponse tupel to continue
        SlingHttpServletRequest cRequest = RequestData.toSlingHttpServletRequest(request);
        SlingHttpServletResponse cResponse = RequestData.toSlingHttpServletResponse(response);

        // get the request data (and btw check the correct type)
        RequestData requestData = RequestData.getRequestData(cRequest);
        ContentData contentData = requestData.pushContent(resource, resolvedURL);
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

    }

    private String toRedirect(String basePath, String selectors,
            String extension, String suffix, String queryString,
            String targetPath) {
        SlingHttpServletRequest request = new MockSlingHttpServletRequest(
            basePath, selectors, extension, suffix, queryString);
        return RedirectServlet.toRedirectPath(targetPath, request);
    }
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

         * TODO: I have made some quick fixes in this method for SLING-221 and
         * SLING-222, but haven't had time to do a proper review. This method
         * might deserve a more extensive rewrite.
         */

        SlingHttpServletRequest cRequest = RequestData.unwrap(request);
        RequestData rd = RequestData.getRequestData(cRequest);
        String absPath = getAbsolutePath(cRequest, path);

        // if the response is not an HttpServletResponse, fail gracefully not
        // doing anything
        if (!(sResponse instanceof HttpServletResponse)) {
            log.error("include: Failed to include {}, response has wrong type",
                absPath);
            return;
        }

        final HttpServletResponse response = (HttpServletResponse) sResponse;

        if (resource == null) {

            // the absolute path may have the context path, cut it off
            if (absPath.startsWith(cRequest.getContextPath())) {
                absPath = absPath.substring(cRequest.getContextPath().length());
            }

            // resolve the absolute path in the resource resolver, using
            // only those parts of the path as if it would be request path
            resource = cRequest.getResourceResolver().resolve(absPath);

            // if the resource could not be resolved, fail gracefully
            if (resource == null) {
                log.error(
                    "include: Could not resolve {} to a resource, not including",
                    absPath);
                return;
            }
        }

        // ensure request path info and optional merges
        SlingRequestPathInfo info = new SlingRequestPathInfo(resource, absPath);
        info = info.merge(cRequest.getRequestPathInfo());

        // merge request dispatcher options and resource type overwrite
        if (options != null) {
            info = info.merge(options);

            // ensure overwritten resource type
            String rtOverwrite = options.getForceResourceType();
            if (rtOverwrite != null
                && !rtOverwrite.equals(resource.getResourceType())) {
                resource = new TypeOverwritingResourceWrapper(resource,
                    rtOverwrite);
            }
        }

        cRequest.getRequestProgressTracker().log("Including resource " + info.getResourcePath());
        rd.getSlingMainServlet().includeContent(request, response, resource,
            info);
    }
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

     * @return whether additional evaluations of the body are desired
     */
    public int doEndTag() throws JspException {
        log.debug("IncludeTagHandler.doEndTag");

        final SlingHttpServletRequest request = TagUtil.getRequest(pageContext);

        // set request dispatcher options according to tag attributes. This
        // depends on the implementation, that using a "null" argument
        // has no effect
        final RequestDispatcherOptions opts = new RequestDispatcherOptions();
        opts.setForceResourceType(resourceType);
        opts.setReplaceSelectors(replaceSelectors);
        opts.setAddSelectors(addSelectors);
        opts.setReplaceSuffix(replaceSuffix);

        // ensure the path (if set) is absolute and normalized
        if (path != null) {
            if (!path.startsWith("/")) {
                path = request.getResource().getPath() + "/" + path;
            }
            path = ResourceUtil.normalize(path);
        }

        // check the resource
        if (resource == null) {
            if (path == null) {
                // neither resource nor path is defined, use current resource
                resource = request.getResource();
            } else {
                // check whether the path (would) resolve, else SyntheticRes.
                Resource tmp = request.getResourceResolver().resolve(path);
                if (tmp == null && resourceType != null) {
                    resource = new SyntheticResource(
                        request.getResourceResolver(), path, resourceType);

                    // remove resource type overwrite as synthetic resource
                    // is correctly typed as requested
                    opts.remove(RequestDispatcherOptions.OPT_FORCE_RESOURCE_TYPE);
                }
            }
        }

        try {
            // optionally flush
            if (flush && !(pageContext.getOut() instanceof BodyContent)) {
                // might throw an IOException of course
                pageContext.getOut().flush();
            }

            // create a dispatcher for the resource or path
            RequestDispatcher dispatcher;
            if (resource != null) {
                dispatcher = request.getRequestDispatcher(resource, opts);
            } else {
                dispatcher = request.getRequestDispatcher(path, opts);
            }

            if (dispatcher != null) {
                SlingHttpServletResponse response = new JspSlingHttpServletResponseWrapper(
                    pageContext);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.