use of com.yahoo.jdisc.http.filter.RequestFilter in project vespa by vespa-engine.
the class JDiscFilterInvokerFilter method runRequestFilterWithMatchingBinding.
private HttpServletRequest runRequestFilterWithMatchingBinding(AtomicReference<Boolean> responseReturned, URI uri, HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
RequestFilter requestFilter = jDiscContext.requestFilters.resolve(uri);
if (requestFilter == null)
return request;
ResponseHandler responseHandler = createResponseHandler(responseReturned, request, response);
return filterInvoker.invokeRequestFilterChain(requestFilter, uri, request, responseHandler);
} catch (Exception e) {
throw new RuntimeException("Failed running request filter chain for uri " + uri, e);
}
}
use of com.yahoo.jdisc.http.filter.RequestFilter in project vespa by vespa-engine.
the class FilterTestCase method requireThatRequestFilterChangesAreSeenByRequestHandler.
@Test
public void requireThatRequestFilterChangesAreSeenByRequestHandler() throws Exception {
final RequestFilter filter = new HeaderRequestFilter("foo", "bar");
final BindingRepository<RequestFilter> requestFilters = new BindingRepository<>();
requestFilters.bind("http://*/*", filter);
final BindingRepository<ResponseFilter> responseFilters = null;
final MyRequestHandler requestHandler = new MyRequestHandler();
final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
testDriver.client().get("status.html");
assertThat(requestHandler.awaitInvocation(), is(true));
assertThat(requestHandler.getHeaderMap().get("foo").get(0), is("bar"));
assertThat(testDriver.close(), is(true));
}
use of com.yahoo.jdisc.http.filter.RequestFilter in project vespa by vespa-engine.
the class FilterTestCase method requireThatResponseFilterIsNotRunOnUnboundPath.
@Test
public void requireThatResponseFilterIsNotRunOnUnboundPath() 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("/status.html");
assertThat(requestHandler.awaitInvocation(), is(true));
verify(filter, never()).filter(any(Response.class), any(Request.class));
assertThat(testDriver.close(), is(true));
}
use of com.yahoo.jdisc.http.filter.RequestFilter in project vespa by vespa-engine.
the class FilterTestCase method requireThatRequestFilterIsNotRunOnUnboundPath.
@Test
public void requireThatRequestFilterIsNotRunOnUnboundPath() 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("/status.html");
assertThat(requestHandler.awaitInvocation(), is(true));
verify(filter, never()).filter(any(HttpRequest.class), any(ResponseHandler.class));
assertThat(testDriver.close(), is(true));
}
use of com.yahoo.jdisc.http.filter.RequestFilter in project vespa by vespa-engine.
the class FilterTestCase method requireThatRequestFilterChainIsRun.
@Test
public void requireThatRequestFilterChainIsRun() throws Exception {
final RequestFilter requestFilter1 = mock(RequestFilter.class);
final RequestFilter requestFilter2 = mock(RequestFilter.class);
final RequestFilter requestFilterChain = RequestFilterChain.newInstance(requestFilter1, requestFilter2);
final HttpRequest request = null;
final ResponseHandler responseHandler = null;
requestFilterChain.filter(request, responseHandler);
verify(requestFilter1).filter(any(HttpRequest.class), any(ResponseHandler.class));
verify(requestFilter2).filter(any(HttpRequest.class), any(ResponseHandler.class));
}
Aggregations