Search in sources :

Example 1 with SlingHttpServletRequestImpl

use of org.apache.sling.engine.impl.SlingHttpServletRequestImpl in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingWrappedSlingRequest.

/**
     * Unwrapping a wrapped sling request should return the first-level request
     * wrapped by the sling request.
     */
@Test
public void testUnwrappingWrappedSlingRequest() {
    final HttpServletRequest req = context.mock(HttpServletRequest.class);
    context.checking(new Expectations() {

        {
            allowing(req).getServletPath();
            will(returnValue("/"));
            allowing(req).getPathInfo();
            will(returnValue("/test"));
        }
    });
    final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(req);
    final HttpServletRequestWrapper wrapper2 = new HttpServletRequestWrapper(wrapper);
    final SlingHttpServletRequestImpl slingRequest = new SlingHttpServletRequestImpl(null, wrapper2);
    final HttpServletRequestWrapper slingWrapper = new HttpServletRequestWrapper(slingRequest);
    ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(slingWrapper);
    assertEquals(wrapper2, unwrapped);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Expectations(org.jmock.Expectations) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) SlingHttpServletRequestImpl(org.apache.sling.engine.impl.SlingHttpServletRequestImpl) Test(org.junit.Test)

Example 2 with SlingHttpServletRequestImpl

use of org.apache.sling.engine.impl.SlingHttpServletRequestImpl in project sling by apache.

the class ExternalServletContextWrapperTest method testUnwrappingSlingRequest.

/**
     * Unwrapping a sling request should return the first-level request wrapped
     * by the sling request.
     */
@Test
public void testUnwrappingSlingRequest() {
    final HttpServletRequest req = context.mock(HttpServletRequest.class);
    context.checking(new Expectations() {

        {
            allowing(req).getServletPath();
            will(returnValue("/"));
            allowing(req).getPathInfo();
            will(returnValue("/test"));
        }
    });
    final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(req);
    final HttpServletRequestWrapper wrapper2 = new HttpServletRequestWrapper(wrapper);
    final SlingHttpServletRequestImpl slingRequest = new SlingHttpServletRequestImpl(null, wrapper2);
    ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(slingRequest);
    assertEquals(wrapper2, unwrapped);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Expectations(org.jmock.Expectations) ServletRequest(javax.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) SlingHttpServletRequestImpl(org.apache.sling.engine.impl.SlingHttpServletRequestImpl) Test(org.junit.Test)

Example 3 with SlingHttpServletRequestImpl

use of org.apache.sling.engine.impl.SlingHttpServletRequestImpl in project sling by apache.

the class RequestDataTest method setup.

@Before
public void setup() throws Exception {
    context = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    req = context.mock(HttpServletRequest.class);
    resp = context.mock(HttpServletResponse.class);
    final ContentData contentData = context.mock(ContentData.class);
    final Servlet servlet = context.mock(Servlet.class);
    final ServletConfig servletConfig = context.mock(ServletConfig.class);
    context.checking(new Expectations() {

        {
            allowing(req).getServletPath();
            will(returnValue("/"));
            allowing(req).getPathInfo();
            will(returnValue(""));
            allowing(req).getMethod();
            will(returnValue("GET"));
            allowing(req).setAttribute(with(any(String.class)), with(any(Object.class)));
            allowing(req).setAttribute(with(any(String.class)), with(aNull(Object.class)));
            allowing(contentData).getServlet();
            will(returnValue(servlet));
            allowing(servlet).getServletConfig();
            will(returnValue(servletConfig));
            allowing(servlet).service(with(any(ServletRequest.class)), with(any(ServletResponse.class)));
            allowing(servletConfig).getServletName();
            will(returnValue("SERVLET_NAME"));
            allowing(req).getAttribute(RequestProgressTracker.class.getName());
            will(returnValue(null));
        }
    });
    requestData = new RequestData(null, req, resp) {

        @Override
        public ContentData getContentData() {
            return contentData;
        }
    };
    slingRequest = new SlingHttpServletRequestImpl(requestData, req);
    slingResponse = new SlingHttpServletResponseImpl(requestData, resp);
    RequestData.setMaxCallCounter(2);
}
Also used : Expectations(org.jmock.Expectations) ServletRequest(javax.servlet.ServletRequest) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) ServletResponse(javax.servlet.ServletResponse) SlingHttpServletResponseImpl(org.apache.sling.engine.impl.SlingHttpServletResponseImpl) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) Mockery(org.jmock.Mockery) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) SlingHttpServletRequestImpl(org.apache.sling.engine.impl.SlingHttpServletRequestImpl) Servlet(javax.servlet.Servlet) Before(org.junit.Before)

Example 4 with SlingHttpServletRequestImpl

use of org.apache.sling.engine.impl.SlingHttpServletRequestImpl in project sling by apache.

the class RequestData method getSlingHttpServletRequestFactory.

// SlingHttpServletRequest instance factory
private static SlingHttpServletRequestFactory getSlingHttpServletRequestFactory() {
    SlingHttpServletRequestFactory factory = RequestData.REQUEST_FACTORY;
    if (factory == null) {
        factory = new SlingHttpServletRequestFactory() {

            @Override
            public SlingHttpServletRequest createRequest(RequestData requestData, HttpServletRequest request) {
                return new SlingHttpServletRequestImpl(requestData, request);
            }
        };
        RequestData.REQUEST_FACTORY = factory;
    }
    return factory;
}
Also used : SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) SlingHttpServletRequestImpl(org.apache.sling.engine.impl.SlingHttpServletRequestImpl) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)4 SlingHttpServletRequestImpl (org.apache.sling.engine.impl.SlingHttpServletRequestImpl)4 ServletRequest (javax.servlet.ServletRequest)3 Expectations (org.jmock.Expectations)3 HttpServletRequestWrapper (javax.servlet.http.HttpServletRequestWrapper)2 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 Test (org.junit.Test)2 Servlet (javax.servlet.Servlet)1 ServletConfig (javax.servlet.ServletConfig)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)1 SlingHttpServletResponseImpl (org.apache.sling.engine.impl.SlingHttpServletResponseImpl)1 Mockery (org.jmock.Mockery)1 Before (org.junit.Before)1