Package org.apache.sling.api

Examples of org.apache.sling.api.SlingHttpServletRequest


    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
            ServletException {
        if (request instanceof SlingHttpServletRequest && response instanceof SlingHttpServletResponse) {
            SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
            SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;

            RequestPathInfo pathInfo = slingRequest.getRequestPathInfo();

            Resource definitionResource = findUrlFilterDefinitionResource(slingRequest.getResource(),
                    slingRequest.getResourceResolver());

            if (definitionResource != null) {
                logger.debug("found url filter definition resource at {}", definitionResource.getPath());
                ValueMap properties = definitionResource.adaptTo(ValueMap.class);
                if (properties != null) {
                    if (checkSelector(pathInfo, properties) && checkSuffix(pathInfo, properties)
                            && checkExtension(pathInfo, properties)) {
                        logger.debug("url filter definition resource at {} passed for request {}.",
                                definitionResource.getPath(), slingRequest.getRequestPathInfo());
                    } else {
                        logger.info("url filter definition resource at {} FAILED for request {}.",
                                definitionResource.getPath(), slingRequest.getRequestPathInfo());
                        slingResponse.sendError(403);
                        return;
                    }
                }
            }
View Full Code Here


        assertNotNull(scriptPath + " must be found", scriptStream);
       
        final String expectedCode = StringUtil.readClassResource(
                getClass(), TEST_RESOURCES_PATH + "/htmlcode" + index + ".expected.html", ENCODING);
        final StringWriter result = new StringWriter();
        final SlingHttpServletRequest request = getMockRequest();
        generator.generateHtml(request, scriptPath, scriptStream, new PrintWriter(result));
        compareLineByLine(expectedCode.toString(), result.toString());
       
        return true;
    }
View Full Code Here

                    (SlingHttpServletResponse) response);
            try {
                chain.doFilter(request, response);
            } finally {
                final long end = System.currentTimeMillis();
                final SlingHttpServletRequest slingReq = (SlingHttpServletRequest) request;

                StringBuilder pw = new StringBuilder(1024);
                pw.append(String.format(":%d:%d:%s:%s:%s:%d%n", start, (end - start), slingReq.getMethod(),
                        slingReq.getRequestURI(), slingRes.getContentType(), slingRes.getStatus()));

                final Iterator<String> entries = slingReq.getRequestProgressTracker().getMessages();
                while (entries.hasNext()) {
                    pw.append('!').append(entries.next());
                }

                BufferedWriter out = this.logFile;
View Full Code Here

                         FilterChain chain)
    throws IOException, ServletException {
        if ( ! (request instanceof SlingHttpServletRequest)) {
            throw new ServletException("Request is not a Apache Sling HTTP request.");
        }
        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
        final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;

        final RewriterResponse rewriterResponse =
                new RewriterResponse(slingRequest, slingResponse, this.pipelineManager);
        boolean errorOccured = true;
View Full Code Here

            throw new ServletException(
                    "response is not an HttpServletResponse: "
                            + sresp.getClass().getName());
        }
        final HttpServletRequest request = (HttpServletRequest) sreq;
        final SlingHttpServletRequest slingRequest =
            (request instanceof SlingHttpServletRequest ? (SlingHttpServletRequest) request : null);
        final HttpServletResponse response = (HttpServletResponse) sresp;
        final String bgParam = sreq.getParameter(bgParamName);
        if (Boolean.valueOf(bgParam)) {
            try {
                final BackgroundRequestExecutionJob job = new BackgroundRequestExecutionJob(
                    slingRequestProcessor, jobStorage, slingRequest, response,
                    new String[] { bgParamName });
                log.debug("{} parameter true, running request in the background ({})",
                        bgParamName, job);
                if (slingRequest != null) {
                    slingRequest.getRequestProgressTracker().log(
                            bgParamName
                            + " parameter true, running request in background ("
                            + job + ")");
                }
                executionEngine.queueForExecution(job);

                // Redirect to the job's status page, using same extension
                // as this request
                String ext = slingRequest.getRequestPathInfo().getExtension();
                if(ext == null) {
                    ext = "";
                } else if(ext.length() > 0) {
                    ext = "." + ext;
                }
View Full Code Here

     * @throws SlingServletException
     * @throws IllegalArgumentException if the Jasper Precompile controller
     *             request parameter has an illegal value.
     */
    public void service(final SlingBindings bindings) {
        final SlingHttpServletRequest request = bindings.getRequest();
        final Object oldValue = request.getAttribute(SlingBindings.class.getName());
        try {
            request.setAttribute(SlingBindings.class.getName(), bindings);
            service(request, bindings.getResponse());
        } catch (SlingException se) {
            // rethrow as is
            throw se;
        } catch (IOException ioe) {
            throw new SlingIOException(ioe);
        } catch (ServletException se) {
            throw new SlingServletException(se);
        } finally {
            request.setAttribute(SlingBindings.class.getName(), oldValue);
        }
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
        AdapterType adapter = null;
        if (adaptable instanceof SlingHttpServletRequest) {
            final SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable;
            if (type == VALUE_MAP_CLASS) {
                adapter = (AdapterType) new ValueMapDecorator(request.getParameterMap());
            } else {
                LOG.warn("Cannot handle adapter {}", type.getName());
            }
        } else {
            LOG.warn("Cannot handle adaptable {}", adaptable.getClass().getName());
View Full Code Here

        if (helper == null) {
            throw new ScriptException("SlingScriptHelper missing from bindings");
        }

        final SlingHttpServletRequest request = helper.getRequest();
        final SlingHttpServletResponse response = helper.getResponse();
        final ServletContext servletContext = null; // only used by Thymeleaf's ServletContextResourceResolver

        final Locale locale = helper.getResponse().getLocale();
        final String scriptName = helper.getScript().getScriptResource().getPath();
View Full Code Here

    public void testGet() throws Exception {
        mockStatic(ResourceDataUtil.class);

        String data = "";

        SlingHttpServletRequest request = mock(SlingHttpServletRequest.class);
        SlingHttpServletResponse response = mock(SlingHttpServletResponse.class);

        when(ResourceDataUtil.getIncludeAsString("/content/world", request,
                response)).thenReturn("hello world");
View Full Code Here

                             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());
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.