use of javax.servlet.ServletRequest in project sling by apache.
the class ExternalServletContextWrapperTest method testUnwrappingRegularRequest.
/**
* Unwrapping a non-wrapper request should return the request itself.
*/
@Test
public void testUnwrappingRegularRequest() {
final ServletRequest req = context.mock(ServletRequest.class);
ServletRequest unwrapped = ExternalServletContextWrapper.RequestDispatcherWrapper.unwrapServletRequest(req);
assertEquals(req, unwrapped);
}
use of javax.servlet.ServletRequest 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 javax.servlet.ServletRequest in project sling by apache.
the class SlingAuthenticator method requestDestroyed.
@Override
public void requestDestroyed(ServletRequestEvent sre) {
ServletRequest request = sre.getServletRequest();
Object resolverAttr = request.getAttribute(REQUEST_ATTRIBUTE_RESOLVER);
if (resolverAttr instanceof ResourceResolver) {
((ResourceResolver) resolverAttr).close();
request.removeAttribute(REQUEST_ATTRIBUTE_RESOLVER);
}
}
use of javax.servlet.ServletRequest in project spring-boot by spring-projects.
the class WebRequestTraceFilterTests method filterHas500ResponseStatusWhenExceptionIsThrown.
@Test
@SuppressWarnings("unchecked")
public void filterHas500ResponseStatusWhenExceptionIsThrown() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
MockHttpServletResponse response = new MockHttpServletResponse();
try {
this.filter.doFilterInternal(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
throw new RuntimeException();
}
});
fail("Exception was swallowed");
} catch (RuntimeException ex) {
Map<String, Object> headers = (Map<String, Object>) this.repository.findAll().iterator().next().getInfo().get("headers");
Map<String, Object> responseHeaders = (Map<String, Object>) headers.get("response");
assertThat((String) responseHeaders.get("status")).isEqualTo("500");
}
}
use of javax.servlet.ServletRequest in project spring-boot by spring-projects.
the class WebRequestTraceFilterTests method filterDoesNotAddAuthorizationHeaderWithoutAuthorizationHeaderInclude.
@Test
@SuppressWarnings({ "unchecked" })
public void filterDoesNotAddAuthorizationHeaderWithoutAuthorizationHeaderInclude() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
request.addHeader("Authorization", "my-auth-header");
MockHttpServletResponse response = new MockHttpServletResponse();
this.filter.doFilterInternal(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
}
});
Map<String, Object> info = this.repository.findAll().iterator().next().getInfo();
Map<String, Object> headers = (Map<String, Object>) info.get("headers");
assertThat(((Map<Object, Object>) headers.get("request"))).hasSize(0);
}
Aggregations