Package org.apache.sling.api

Examples of org.apache.sling.api.SlingHttpServletRequest


     */
    public void service(ServletRequest req, ServletResponse res)
            throws ServletException, IOException {

        try {
            SlingHttpServletRequest request = (SlingHttpServletRequest) req;
            SlingHttpServletResponse response = (SlingHttpServletResponse) res;

            service(request, response);

        } catch (ClassCastException cce) {
View Full Code Here


                || !(servletResponse instanceof SlingHttpServletResponse)) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest;
        final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse;

        /**
         * Fail fast and early!
         *
         * Must be:
         *  - HTTP POST Request
         *  - Have Forms Sling Suffix
         *    - At this point, 99% of includes will be passed over
         *  - Must contain Form Resource Query Parameter
         */

        if (!StringUtils.equals("POST", slingRequest.getMethod())
                || !formsRouter.hasValidSuffix(slingRequest)) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        final String formResource = this.getParameter(slingRequest, FormHelper.FORM_RESOURCE_INPUT);
        if (formResource == null || slingRequest.getResourceResolver().resolve(formResource) == null) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        String formSelector = formsRouter.getFormSelector(slingRequest);
        if (formSelector == null) {
            formSelector = FormHelper.DEFAULT_FORM_SELECTOR;
        }

        final RequestDispatcherOptions options = new RequestDispatcherOptions();

        options.setReplaceSelectors(formSelector);
        options.setReplaceSuffix(slingRequest.getRequestPathInfo().getSuffix());

        if (log.isDebugEnabled()) {
            log.debug("Form Filter; Internal forward to path: {} ", formResource);
            log.debug("Form Filter; Internal forward w/ replace selectors: {} ", options.getReplaceSelectors());
            log.debug("Form Filter; Internal forward w/ suffix: {} ", options.getReplaceSuffix());
        }

        slingRequest.getRequestDispatcher(formResource, options).forward(slingRequest, slingResponse);
    }
View Full Code Here

                || !(servletResponse instanceof SlingHttpServletResponse)) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest;
        final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse;

        /**
         * Fail fast and early!
         *
         * Must be:
         *  - HTTP GET Request
         *  - Have Forms Sling Suffix
         *    - At this point, 99% of includes will be passed over
         *  - Must contain Form Selector Query Parameter
         *  - Include is not a product of a previous forward by this Filter
         */

        if (!StringUtils.equals("GET", slingRequest.getMethod())
                || !formsRouter.hasValidSuffix(slingRequest)) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        /* Ensure there is a valid form selector as part of Query Params */
        final String formSelector = formsRouter.getFormSelector(slingRequest);
        if (formSelector == null) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        /* Ensure this is not a product of a previous forward; This is to be absolutely sure we are not hitting an
         * infinite loop condition */
        if (slingRequest.getAttribute(REQUEST_ATTR_PREVIOUSLY_PROCESSED) != null) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }

        final RequestDispatcherOptions options = new RequestDispatcherOptions();

        options.setReplaceSelectors(formSelector);
        options.setReplaceSuffix(slingRequest.getRequestPathInfo().getSuffix());

        if (log.isDebugEnabled()) {
            log.debug("POST-Redirect-GET Form Filter; Internal forward to resource: {} ",
                    slingRequest.getResource());
            log.debug("POST-Redirect-GET Form Filter; Internal forward to path: {} ",
                    slingRequest.getResource().getPath());
            log.debug("POST-Redirect-GET Filter; Internal forward w/ replace selectors: {} ",
                    options.getReplaceSelectors());
            log.debug("POST-Redirect-GET Filter; Internal forward w/ suffix: {} ",
                    options.getReplaceSuffix());
        }

        // Avoid accidental infinite loops with API consumers doing their own Fws and Includes
        slingRequest.setAttribute(REQUEST_ATTR_PREVIOUSLY_PROCESSED, Boolean.TRUE);
        slingRequest.getRequestDispatcher(slingRequest.getResource(), options).forward(slingRequest, slingResponse);
    }
View Full Code Here

     * @param adaptable a SlingHttpServletRequest
     * @return the ComponentContext if the adaptable was a SlingHttpServletRequest, or null otherwise
     */
    private ComponentContext getComponentContext(Object adaptable) {
        if (adaptable instanceof SlingHttpServletRequest) {
            SlingHttpServletRequest request = ((SlingHttpServletRequest) adaptable);

            return WCMUtils.getComponentContext(request);
        }
        // ComponentContext is not reachable from Resource

View Full Code Here

    private Design getResourceDesign(Object adaptable) {
        Page resourcePage = getResourcePage(adaptable);
        Designer designer = getDesigner(adaptable);

        if (adaptable instanceof SlingHttpServletRequest) {
            SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable;

            if (resourcePage != null && designer != null) {
                String resourceDesignKey = COM_DAY_CQ_WCM_TAGS_DEFINE_OBJECTS_TAG + resourcePage.getPath();
                Object cachedResourceDesign = request.getAttribute(resourceDesignKey);

                if (cachedResourceDesign != null) {
                    return (Design) cachedResourceDesign;
                } else {
                    Design resourceDesign = designer.getDesign(resourcePage);
                    request.setAttribute(resourceDesignKey, resourceDesign);

                    return resourceDesign;
                }
            }
        }
View Full Code Here

     * @param adaptable a SlingHttpServletRequest
     * @return a XSSAPI object configured for the current request, or null otherwise
     */
    private XSSAPI getXssApi(Object adaptable) {
        if (adaptable instanceof SlingHttpServletRequest) {
            SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable;

            return request.adaptTo(XSSAPI.class);
        }
        // otherwise will fetch generic XSSAPI from OSGiServiceInjector

        return null;
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    public int doEndTag() throws JspException {
        final SlingHttpServletRequest request = TagUtil.getRequest(pageContext);
        final SlingBindings bindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
        final DesignHtmlLibraryManager manager = bindings.getSling().getService(DesignHtmlLibraryManager.class);
        if (manager != null) {
            try {
                if (js && css) {
                    manager.writeIncludes(request, getDesign(), region, pageContext.getOut());
View Full Code Here

            || req.getAttribute(ATTR_REQUEST_CONTENT) != null) {
            chain.doFilter(req, res);
            return;
        }

        SlingHttpServletRequest request = (SlingHttpServletRequest) req;
        SlingHttpServletResponse response = (SlingHttpServletResponse) res;

        // check for compress header
        String enc = request.getHeader("Accept-Encoding");
        if (enc == null || enc.length() == 0) {
            // assume identity, no wrapping
            chain.doFilter(request, response);
            return;
        }
View Full Code Here

    private WeightedResource createLocationResource(
            final Resource scriptResource, final String method,
            final String selectorString, final String extension) {

        final SlingHttpServletRequest request = new MockSlingHttpServletRequest(
            "", selectorString, extension, null, null) {
            @Override
            public String getMethod() {
                return method;
            }
View Full Code Here

        }
    }

    public void service(ServletRequest req, ServletResponse res) {

        SlingHttpServletRequest request = (SlingHttpServletRequest) req;

        try {
            // prepare the properties for the script
            SlingBindings props = new SlingBindings();
            props.setRequest((SlingHttpServletRequest) req);
            props.setResponse((SlingHttpServletResponse) res);
            props.setFlush(true);

            res.setCharacterEncoding("UTF-8");
            // try to set content type
            final String contentType = request.getResponseContentType();
            if ( contentType != null ) {
                res.setContentType(contentType);
            } else {
                logger.warn("No response content type defined for request {}.", request.getRequestURI());
            }

            // evaluate the script now using the ScriptEngine
            eval(props);
View Full Code Here

TOP

Related Classes of org.apache.sling.api.SlingHttpServletRequest

Copyright © 2018 www.massapicom. 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.