Search in sources :

Example 6 with CayenneRuntime

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);
    }
}
Also used : CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime)

Example 7 with CayenneRuntime

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());
}
Also used : MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime) MockFilterChain(com.mockrunner.mock.web.MockFilterChain) MockServletContext(com.mockrunner.mock.web.MockServletContext) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Test(org.junit.Test)

Example 8 with CayenneRuntime

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);
}
Also used : CayenneRuntime(org.apache.cayenne.configuration.CayenneRuntime) MockServletContext(com.mockrunner.mock.web.MockServletContext) MockFilterConfig(com.mockrunner.mock.web.MockFilterConfig) Test(org.junit.Test)

Aggregations

CayenneRuntime (org.apache.cayenne.configuration.CayenneRuntime)8 MockServletContext (com.mockrunner.mock.web.MockServletContext)6 Test (org.junit.Test)6 MockFilterConfig (com.mockrunner.mock.web.MockFilterConfig)5 ServerModule (org.apache.cayenne.configuration.server.ServerModule)2 Module (org.apache.cayenne.di.Module)2 MockFilterChain (com.mockrunner.mock.web.MockFilterChain)1 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)1