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);
}
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);
}
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);
}
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;
}
Aggregations