use of io.crnk.servlet.internal.ServletRequestContext in project crnk-framework by crnk-project.
the class SpringCrnkFilter method doFilter.
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
if (req instanceof HttpServletRequest && res instanceof HttpServletResponse && matchesPrefix((HttpServletRequest) req)) {
ServletContext servletContext = filterConfig.getServletContext();
RequestDispatcher requestDispatcher = boot.getRequestDispatcher();
ServletRequestContext context = new ServletRequestContext(servletContext, (HttpServletRequest) req, (HttpServletResponse) res, boot.getWebPathPrefix(), defaultCharacterEncoding);
requestDispatcher.process(context);
if (!context.checkAbort()) {
chain.doFilter(req, res);
}
} else {
chain.doFilter(req, res);
}
}
use of io.crnk.servlet.internal.ServletRequestContext in project crnk-framework by crnk-project.
the class CrnkServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletContext servletContext = getServletContext();
ServletRequestContext context = new ServletRequestContext(servletContext, request, response, boot.getWebPathPrefix(), defaultCharacterEncoding);
RequestDispatcher requestDispatcher = boot.getRequestDispatcher();
requestDispatcher.process(context);
if (!context.checkAbort()) {
HttpRequestContextBaseAdapter requestContext = new HttpRequestContextBaseAdapter(context);
boolean jsonApiRequest = JsonApiRequestProcessor.isJsonApiRequest(requestContext, acceptPlainJson);
response.setStatus(jsonApiRequest ? HttpStatus.NOT_FOUND_404 : HttpStatus.UNSUPPORTED_MEDIA_TYPE_415);
}
}
use of io.crnk.servlet.internal.ServletRequestContext in project crnk-framework by crnk-project.
the class ServletRequestContextTest method testResponseHeaders.
@Test
public void testResponseHeaders() {
MockHttpServletResponse response = new MockHttpServletResponse();
ServletRequestContext context = new ServletRequestContext(servletContext, request, response, "/api");
context.setResponseHeader("test", "13");
Assert.assertEquals("13", context.getResponseHeader("test"));
}
use of io.crnk.servlet.internal.ServletRequestContext in project crnk-framework by crnk-project.
the class ServletRequestContextTest method testGetters.
@Test
public void testGetters() {
ServletRequestContext context = new ServletRequestContext(servletContext, request, response, "/api");
Assert.assertEquals(request, context.getRequest());
Assert.assertEquals(response, context.getResponse());
Assert.assertEquals(servletContext, context.getServletContext());
}
use of io.crnk.servlet.internal.ServletRequestContext in project crnk-framework by crnk-project.
the class ServletRequestContextTest method testRootPath.
@Test
public void testRootPath() {
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
request.setMethod("GET");
request.setContextPath("");
request.setServletPath("");
request.setPathInfo("");
request.setRequestURI("");
request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
request.addHeader("Accept", "*/*");
request.setServerName("test");
request.setServerPort(1234);
ServletRequestContext context = new ServletRequestContext(servletContext, request, response, null);
Assert.assertEquals("/", context.getPath());
Assert.assertEquals("http://test:1234", context.getBaseUrl());
}
Aggregations