Search in sources :

Example 1 with HttpFilter

use of org.codice.ddf.platform.filter.http.HttpFilter in project ddf by codice.

the class DelegatingHttpFilterHandlerTest method mockHttpFilter.

private HttpFilter mockHttpFilter() throws Exception {
    HttpFilter mockFilter = mock(HttpFilter.class);
    doAnswer(invocationOnMock -> {
        HttpServletRequest request = invocationOnMock.getArgument(0);
        HttpServletResponse response = invocationOnMock.getArgument(1);
        HttpFilterChain filterChain = invocationOnMock.getArgument(2);
        filterChain.doFilter(request, response);
        return null;
    }).when(mockFilter).doFilter(any(), any(), any());
    return mockFilter;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpFilter(org.codice.ddf.platform.filter.http.HttpFilter) HttpFilterChain(org.codice.ddf.platform.filter.http.HttpFilterChain)

Example 2 with HttpFilter

use of org.codice.ddf.platform.filter.http.HttpFilter in project ddf by codice.

the class ProxyHttpFilterChain method doFilter.

@Override
public void doFilter(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    if (iterator.hasNext()) {
        HttpFilter filter = iterator.next();
        LOGGER.debug("Calling filter {}.doFilter({}, {}, {}, {}, {})", filter.getClass().getName(), target, baseRequest, request, response, this);
        filter.doFilter(request, response, this);
    } else {
        handler.handle(target, baseRequest, request, response);
    }
}
Also used : HttpFilter(org.codice.ddf.platform.filter.http.HttpFilter)

Example 3 with HttpFilter

use of org.codice.ddf.platform.filter.http.HttpFilter in project ddf by codice.

the class DelegatingHttpFilterHandlerTest method testDelegatingHttpFilterHandler.

@Test
public void testDelegatingHttpFilterHandler() throws Exception {
    Request mockBaseRequest = mock(Request.class);
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);
    HttpFilter mockFilter = mockHttpFilter();
    ServiceReference<HttpFilter> mockServiceReference = mock(ServiceReference.class);
    BundleContext mockBundleContext = mock(BundleContext.class);
    when(mockBundleContext.getServiceReferences(any(Class.class), anyString())).thenReturn(Collections.singletonList(mockServiceReference));
    when(mockBundleContext.getService(mockServiceReference)).thenReturn(mockFilter);
    Handler handler = mock(Handler.class);
    DelegatingHttpFilterHandler underTest = new DelegatingHttpFilterHandler(mockBundleContext);
    underTest.setHandler(handler);
    underTest.handle("/", mockBaseRequest, mockRequest, mockResponse);
    verify(mockFilter).doFilter(any(), any(), any());
    verify(handler).handle("/", mockBaseRequest, mockRequest, mockResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Handler(org.eclipse.jetty.server.Handler) HttpFilter(org.codice.ddf.platform.filter.http.HttpFilter) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 4 with HttpFilter

use of org.codice.ddf.platform.filter.http.HttpFilter in project ddf by codice.

the class DelegatingHttpFilterHandlerTest method testDelegatingHttpFilterHandlerWithServiceRanking.

@Test
public void testDelegatingHttpFilterHandlerWithServiceRanking() throws Exception {
    Request mockBaseRequest = mock(Request.class);
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);
    HttpFilter filter1 = mockHttpFilter();
    HttpFilter filter2 = mockHttpFilter();
    HttpFilter filter3 = mockHttpFilter();
    ServiceReference<HttpFilter> reference1 = mock(ServiceReference.class);
    ServiceReference<HttpFilter> reference2 = mock(ServiceReference.class);
    ServiceReference<HttpFilter> reference3 = mock(ServiceReference.class);
    rankServiceReferences(reference1, reference2, reference3);
    BundleContext mockBundleContext = mock(BundleContext.class);
    when(mockBundleContext.getService(reference1)).thenReturn(filter1);
    when(mockBundleContext.getService(reference2)).thenReturn(filter2);
    when(mockBundleContext.getService(reference3)).thenReturn(filter3);
    when(mockBundleContext.getServiceReferences(any(Class.class), anyString())).thenReturn(Arrays.asList(reference2, reference3, reference1));
    Handler handler = mock(Handler.class);
    DelegatingHttpFilterHandler underTest = new DelegatingHttpFilterHandler(mockBundleContext);
    underTest.setHandler(handler);
    underTest.handle("/", mockBaseRequest, mockRequest, mockResponse);
    InOrder inOrder = Mockito.inOrder(filter1, filter2, filter3);
    inOrder.verify(filter1).doFilter(any(), any(), any());
    inOrder.verify(filter2).doFilter(any(), any(), any());
    inOrder.verify(filter3).doFilter(any(), any(), any());
    inOrder.verifyNoMoreInteractions();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InOrder(org.mockito.InOrder) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Handler(org.eclipse.jetty.server.Handler) HttpFilter(org.codice.ddf.platform.filter.http.HttpFilter) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

HttpFilter (org.codice.ddf.platform.filter.http.HttpFilter)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Handler (org.eclipse.jetty.server.Handler)2 Request (org.eclipse.jetty.server.Request)2 Test (org.junit.Test)2 BundleContext (org.osgi.framework.BundleContext)2 HttpFilterChain (org.codice.ddf.platform.filter.http.HttpFilterChain)1 InOrder (org.mockito.InOrder)1