Examples of SlingHttpServletRequest


Examples of org.apache.sling.api.SlingHttpServletRequest

        }
        Class<?> requestedClass = (Class<?>) type;

        // validate input
        if (adaptable instanceof SlingHttpServletRequest) {
            SlingHttpServletRequest request = (SlingHttpServletRequest) adaptable;
            if (requestedClass.equals(ResourceResolver.class)) {
                return request.getResourceResolver();
            }
            if (requestedClass.equals(Resource.class) && element.isAnnotationPresent(SlingObject.class)) {
                return request.getResource();
            }
            if (requestedClass.equals(SlingHttpServletRequest.class) || requestedClass.equals(HttpServletRequest.class)) {
                return request;
            }
            if (requestedClass.equals(SlingHttpServletResponse.class)
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

        assertEquals(resourceResolver, result);
    }

    @Test
    public void testFromRequest() {
        SlingHttpServletRequest request = mock(SlingHttpServletRequest.class);
        ResourceResolver resourceResolver = mock(ResourceResolver.class);
        when(request.getResourceResolver()).thenReturn(resourceResolver);

        Object result = injector.getValue(request, "resourceResolver", null, null, null);
        assertEquals(resourceResolver, result);
    }
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

    @Test
    public void testRequestOSGiModelField() throws Exception {
        ServiceInterface service = mock(ServiceInterface.class);

        SlingHttpServletRequest request = mock(SlingHttpServletRequest.class);
        when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);

        when(helper.getServices(ServiceInterface.class, null)).thenReturn(new ServiceInterface[] { service });

        RequestOSGiModel model = factory.getAdapter(request, RequestOSGiModel.class);
        assertNotNull(model);
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

        assertEquals(byPropertyValueResource2, model.getByDerefProperty2());
    }

    @Test
    public void testPathInjectionWithNonResourceAdaptable() {
        SlingHttpServletRequest nonResourceAdaptable = mock(SlingHttpServletRequest.class);
        ResourcePathModel model = factory.getAdapter(nonResourceAdaptable, ResourcePathModel.class);
        // should be null because mandatory fields could not be injected
        assertNull(model);
    }
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

        assertNull(model);
    }

    @Test
    public void testOptionalPathInjectionWithNonResourceAdaptable() {
        SlingHttpServletRequest nonResourceAdaptable = mock(SlingHttpServletRequest.class);
        ResourcePathAllOptionalModel model = factory.getAdapter(nonResourceAdaptable, ResourcePathAllOptionalModel.class);
        // should not be null because resource paths fields are optional
        assertNotNull(model);
        // but the field itself are null
        assertNull(model.getFromPath());
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

     * Creates a new sling script helper instance using
     * {@link #DEFAULT_RESOURCERESOLVER_TYPE} for the resource resolver.
     * @return Sling script helper instance
     */
    public static SlingScriptHelper newSlingScriptHelper() {
        SlingHttpServletRequest request = new MockSlingHttpServletRequest(newResourceResolver());
        SlingHttpServletResponse response = new MockSlingHttpServletResponse();
        BundleContext bundleContext = MockOsgi.newBundleContext();
        return newSlingScriptHelper(request, response, bundleContext);
    }
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("AbstractDispatcherTagHandler.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 DispatcherSyntheticResource(
                        request.getResourceResolver(), path, resourceType);

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

        try {
            // 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

Examples of org.apache.sling.api.SlingHttpServletRequest

    try {
      final JspServletWrapper errorJsp = getJspWrapper(scriptName, slingBindings);
      errorJsp.service(slingBindings);

            // The error page could be inside an include.
          final SlingHttpServletRequest request = slingBindings.getRequest();
            final Throwable t = (Throwable)request.getAttribute("javax.servlet.jsp.jspException");

          final Object newException = request
                    .getAttribute("javax.servlet.error.exception");

            // t==null means the attribute was not set.
            if ((newException != null) && (newException == t)) {
                request.removeAttribute("javax.servlet.error.exception");
            }

            // now clear the error code - to prevent double handling.
            request.removeAttribute("javax.servlet.error.status_code");
            request.removeAttribute("javax.servlet.error.request_uri");
            request.removeAttribute("javax.servlet.error.status_code");
            request.removeAttribute("javax.servlet.jsp.jspException");
    } finally {
            jspfh.decUsage();
      io.resetRequestResourceResolver(oldResolver);
    }
     }
View Full Code Here

Examples of org.apache.sling.api.SlingHttpServletRequest

                will(returnValue(set));

            }
        });

        final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
        context.checking(new Expectations() {
            {
                Vector names = new Vector();
                names.add("./param");
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);
        RequestProgressTracker requestProgressTracker = cRequest.getRequestProgressTracker();

        // 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;
        }

        if (resource == null) {
            String timerName = "resolveIncludedResource(" + absPath + ")";
            requestProgressTracker.startTimer(timerName);

            // 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",
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.