Search in sources :

Example 1 with ResponseFilter

use of com.yahoo.jdisc.http.filter.ResponseFilter in project vespa by vespa-engine.

the class JDiscFilterForServletTest method bindings.

private Module bindings(BindingRepository<RequestFilter> requestFilters, BindingRepository<ResponseFilter> responseFilters) {
    return Modules.combine(new AbstractModule() {

        @Override
        protected void configure() {
            bind(FilterBindings.class).toInstance(new FilterBindings(requestFilters, responseFilters));
            bind(FilterInvoker.class).toInstance(new FilterInvoker() {

                @Override
                public HttpServletRequest invokeRequestFilterChain(RequestFilter requestFilter, URI uri, HttpServletRequest httpRequest, ResponseHandler responseHandler) {
                    TestRequestFilter filter = (TestRequestFilter) requestFilter;
                    filter.runAsSecurityFilter(httpRequest, responseHandler);
                    return httpRequest;
                }

                @Override
                public void invokeResponseFilterChain(ResponseFilter responseFilter, URI uri, HttpServletRequest request, HttpServletResponse response) {
                    TestResponseFilter filter = (TestResponseFilter) responseFilter;
                    filter.runAsSecurityFilter(request, response);
                }
            });
        }
    }, guiceModule());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) FilterInvoker(com.yahoo.jdisc.http.server.jetty.FilterInvoker) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) HttpServletResponse(javax.servlet.http.HttpServletResponse) FilterBindings(com.yahoo.jdisc.http.server.FilterBindings) URI(java.net.URI) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) AbstractModule(com.google.inject.AbstractModule)

Example 2 with ResponseFilter

use of com.yahoo.jdisc.http.filter.ResponseFilter in project vespa by vespa-engine.

the class FilterTestCase method requireThatResponseFilterIsRunOnBoundPath.

@Test
public void requireThatResponseFilterIsRunOnBoundPath() throws Exception {
    final ResponseFilter filter = mock(ResponseFilterMockBase.class);
    final BindingRepository<RequestFilter> requestFilters = null;
    final BindingRepository<ResponseFilter> responseFilters = new BindingRepository<>();
    responseFilters.bind("http://*/filtered/*", filter);
    final MyRequestHandler requestHandler = new MyRequestHandler();
    final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
    testDriver.client().get("/filtered/status.html");
    assertThat(requestHandler.awaitInvocation(), is(true));
    verify(filter, times(1)).filter(any(Response.class), any(Request.class));
    assertThat(testDriver.close(), is(true));
}
Also used : HttpResponse(com.yahoo.jdisc.http.HttpResponse) Response(com.yahoo.jdisc.Response) BindingRepository(com.yahoo.jdisc.application.BindingRepository) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Request(com.yahoo.jdisc.Request) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 3 with ResponseFilter

use of com.yahoo.jdisc.http.filter.ResponseFilter in project vespa by vespa-engine.

the class FilterTestCase method requireThatRequestFilterIsRunOnBoundPath.

@Test
public void requireThatRequestFilterIsRunOnBoundPath() throws Exception {
    final RequestFilter filter = mock(RequestFilterMockBase.class);
    final BindingRepository<RequestFilter> requestFilters = new BindingRepository<>();
    requestFilters.bind("http://*/filtered/*", filter);
    final BindingRepository<ResponseFilter> responseFilters = null;
    final MyRequestHandler requestHandler = new MyRequestHandler();
    final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
    testDriver.client().get("/filtered/status.html");
    assertThat(requestHandler.awaitInvocation(), is(true));
    verify(filter, times(1)).filter(any(HttpRequest.class), any(ResponseHandler.class));
    assertThat(testDriver.close(), is(true));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) BindingRepository(com.yahoo.jdisc.application.BindingRepository) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 4 with ResponseFilter

use of com.yahoo.jdisc.http.filter.ResponseFilter in project vespa by vespa-engine.

the class FilterTestCase method requireThatRequestFilterAndResponseFilterCanBindToSamePath.

@Test
public void requireThatRequestFilterAndResponseFilterCanBindToSamePath() throws Exception {
    final String uriPattern = "http://*/*";
    final BindingRepository<RequestFilter> requestFilters = new BindingRepository<>();
    final RequestFilter requestFilter = mock(RequestFilterMockBase.class);
    requestFilters.bind(uriPattern, requestFilter);
    final BindingRepository<ResponseFilter> responseFilters = new BindingRepository<>();
    final ResponseFilter responseFilter = mock(ResponseFilterMockBase.class);
    responseFilters.bind(uriPattern, responseFilter);
    final MyRequestHandler requestHandler = new MyRequestHandler();
    final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
    testDriver.client().get("/status.html");
    assertThat(requestHandler.awaitInvocation(), is(true));
    verify(requestFilter, times(1)).filter(any(HttpRequest.class), any(ResponseHandler.class));
    verify(responseFilter, times(1)).filter(any(Response.class), any(Request.class));
    assertThat(testDriver.close(), is(true));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) HttpResponse(com.yahoo.jdisc.http.HttpResponse) Response(com.yahoo.jdisc.Response) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) BindingRepository(com.yahoo.jdisc.application.BindingRepository) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Request(com.yahoo.jdisc.Request) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 5 with ResponseFilter

use of com.yahoo.jdisc.http.filter.ResponseFilter in project vespa by vespa-engine.

the class FilterTestCase method requireThatResponseFilterChainRetainsFilters.

@Test
public void requireThatResponseFilterChainRetainsFilters() {
    final ResponseFilter responseFilter1 = mock(ResponseFilter.class);
    final ResponseFilter responseFilter2 = mock(ResponseFilter.class);
    verify(responseFilter1, never()).refer();
    verify(responseFilter2, never()).refer();
    final ResourceReference reference1 = mock(ResourceReference.class);
    final ResourceReference reference2 = mock(ResourceReference.class);
    when(responseFilter1.refer()).thenReturn(reference1);
    when(responseFilter2.refer()).thenReturn(reference2);
    final ResponseFilter chain = ResponseFilterChain.newInstance(responseFilter1, responseFilter2);
    verify(responseFilter1, times(1)).refer();
    verify(responseFilter2, times(1)).refer();
    verify(reference1, never()).close();
    verify(reference2, never()).close();
    chain.release();
    verify(reference1, times(1)).close();
    verify(reference2, times(1)).close();
}
Also used : ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) ResourceReference(com.yahoo.jdisc.ResourceReference) Test(org.testng.annotations.Test)

Aggregations

ResponseFilter (com.yahoo.jdisc.http.filter.ResponseFilter)11 RequestFilter (com.yahoo.jdisc.http.filter.RequestFilter)9 Test (org.testng.annotations.Test)8 HttpRequest (com.yahoo.jdisc.http.HttpRequest)7 BindingRepository (com.yahoo.jdisc.application.BindingRepository)6 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)5 Request (com.yahoo.jdisc.Request)4 Response (com.yahoo.jdisc.Response)4 HttpResponse (com.yahoo.jdisc.http.HttpResponse)4 FilterBindings (com.yahoo.jdisc.http.server.FilterBindings)2 AbstractModule (com.google.inject.AbstractModule)1 ComponentId (com.yahoo.component.ComponentId)1 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)1 ChainsConfig (com.yahoo.container.core.ChainsConfig)1 FilterChainRepository (com.yahoo.container.http.filter.FilterChainRepository)1 ResourceReference (com.yahoo.jdisc.ResourceReference)1 AbstractRequestHandler (com.yahoo.jdisc.handler.AbstractRequestHandler)1 BindingNotFoundException (com.yahoo.jdisc.handler.BindingNotFoundException)1 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)1 RequestDeniedException (com.yahoo.jdisc.handler.RequestDeniedException)1