use of org.apache.cayenne.configuration.CayenneRuntime in project cayenne by apache.
the class CayenneFilter method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
RequestHandler handler = runtime.getInjector().getInstance(RequestHandler.class);
handler.requestStart(request, response);
try {
chain.doFilter(request, response);
} finally {
handler.requestEnd(request, response);
}
}
use of org.apache.cayenne.configuration.CayenneRuntime in project cayenne by apache.
the class CayenneFilterTest method testDoFilter.
@Test
public void testDoFilter() throws Exception {
MockFilterConfig config = new MockFilterConfig();
config.setFilterName("abc");
config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, CayenneFilter_DispatchModule.class.getName());
MockServletContext context = new MockServletContext();
config.setupServletContext(context);
CayenneFilter filter = new CayenneFilter();
filter.init(config);
CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
CayenneFilter_DispatchRequestHandler handler = (CayenneFilter_DispatchRequestHandler) runtime.getInjector().getInstance(RequestHandler.class);
assertEquals(0, handler.getStarted());
assertEquals(0, handler.getEnded());
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertEquals(1, handler.getStarted());
assertEquals(1, handler.getEnded());
filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
assertEquals(2, handler.getStarted());
assertEquals(2, handler.getEnded());
}
use of org.apache.cayenne.configuration.CayenneRuntime in project cayenne by apache.
the class CayenneFilterTest method testInitWithFilterName.
@Test
public void testInitWithFilterName() throws Exception {
MockFilterConfig config = new MockFilterConfig();
config.setFilterName("abc");
MockServletContext context = new MockServletContext();
config.setupServletContext(context);
CayenneFilter filter = new CayenneFilter();
assertNull(WebUtil.getCayenneRuntime(context));
filter.init(config);
CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
assertNotNull(runtime);
List<String> locations = runtime.getInjector().getInstance(Key.getListOf(String.class, Constants.SERVER_PROJECT_LOCATIONS_LIST));
assertEquals(Arrays.asList("abc.xml"), locations);
}
Aggregations