use of javax.servlet.Filter in project camel by apache.
the class CustomFiltersTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
List<Filter> filters = new ArrayList<Filter>();
filters.add(new MyTestFilter());
jndi.bind("myFilters", filters);
return jndi;
}
use of javax.servlet.Filter in project camel by apache.
the class CometdCrossOriginConsumerTest method testCrossOriginFilterAddedWhenOn.
@Test
public void testCrossOriginFilterAddedWhenOn() throws Exception {
// setup
CometdComponent component = context.getComponent("cometd", CometdComponent.class);
Server server = new Server();
when(endpoint.isCrossOriginFilterOn()).thenReturn(true);
when(endpoint.getFilterPath()).thenReturn(FILTER_PATH);
when(endpoint.getAllowedOrigins()).thenReturn(ALLOWED_ORIGINS);
// act
component.createServletForConnector(server, connector, endpoint);
// assert
ServletContextHandler handler = (ServletContextHandler) server.getHandler();
assertEquals(1, handler.getServletHandler().getFilters().length);
FilterHolder filterHolder = handler.getServletHandler().getFilters()[0];
Filter filter = filterHolder.getFilter();
assertTrue(filter instanceof CrossOriginFilter);
}
use of javax.servlet.Filter in project felix by apache.
the class EventListenerRegistryTest method createFilterHandler.
private static FilterHandler createFilterHandler(final long id, final int ranking, final String... paths) throws InvalidSyntaxException {
final FilterInfo si = createFilterInfo(id, ranking, paths);
final ExtServletContext ctx = mock(ExtServletContext.class);
final Filter filter = mock(Filter.class);
return new HttpServiceFilterHandler(ctx, si, filter);
}
use of javax.servlet.Filter in project felix by apache.
the class EventListenerRegistryTest method testSingleFilter.
@Test
public void testSingleFilter() throws InvalidSyntaxException, ServletException {
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
// check DTO
reg.getRuntimeInfo(dto, holder.failedFilterDTOs);
assertEmpty(dto, holder);
// register filter
final FilterHandler h1 = createFilterHandler(1L, 0, "/foo");
reg.addFilter(h1);
verify(h1.getFilter()).init(Matchers.any(FilterConfig.class));
// one entry in DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedFilterDTOs);
assertTrue(holder.failedFilterDTOs.isEmpty());
assertNotNull(dto.filterDTOs);
assertEquals(1, dto.filterDTOs.length);
assertEquals(1, dto.filterDTOs[0].patterns.length);
assertEquals("/foo", dto.filterDTOs[0].patterns[0]);
// remove filter
final Filter f = h1.getFilter();
reg.removeFilter(h1.getFilterInfo(), true);
verify(f).destroy();
// empty again
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedFilterDTOs);
assertEmpty(dto, holder);
}
use of javax.servlet.Filter in project felix by apache.
the class HttpServiceRuntimeTest method exceptionInFilterInitAppearsAsFailure.
@Test
public void exceptionInFilterInitAppearsAsFailure() throws ServletException, InterruptedException {
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_FILTER_PATTERN, "/filter", HTTP_WHITEBOARD_FILTER_NAME, "filter");
CountDownLatch initLatch = new CountDownLatch(1);
Filter failingFilter = new TestFilter(initLatch, null) {
@Override
public void init(FilterConfig config) throws ServletException {
super.init(config);
throw new ServletException();
}
};
registrations.add(m_context.registerService(Filter.class.getName(), failingFilter, properties));
awaitServiceRegistration(initLatch);
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(1, runtimeDTO.failedFilterDTOs.length);
assertEquals("filter", runtimeDTO.failedFilterDTOs[0].name);
assertEquals(FAILURE_REASON_EXCEPTION_ON_INIT, runtimeDTO.failedFilterDTOs[0].failureReason);
}
Aggregations