use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method differentTargetIsIgnored.
// As specified in OSGi Compendium Release 6, Chapter 140.3
@Test
public void differentTargetIsIgnored() throws InterruptedException {
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/servlet", HTTP_WHITEBOARD_SERVLET_NAME, "servlet", HTTP_WHITEBOARD_TARGET, "(org.osgi.service.http.port=8282)");
registrations.add(m_context.registerService(Servlet.class.getName(), new TestServlet(), properties));
awaitServiceRegistration();
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTO.failedServletDTOs.length);
ServletContextDTO defaultContext = assertDefaultContext(runtimeDTO);
assertEquals(0, defaultContext.servletDTOs.length);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method namedServletIsNotIgnored.
@Test
public void namedServletIsNotIgnored() throws InterruptedException {
// Neither pattern nor error page specified
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_NAME, "servlet");
registrations.add(m_context.registerService(Servlet.class.getName(), new TestServlet(), properties));
awaitServiceRegistration();
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTO.failedServletContextDTOs.length);
ServletContextDTO defaultContext = assertDefaultContext(runtimeDTO);
assertEquals(1, defaultContext.servletDTOs.length);
assertEquals(0, defaultContext.servletDTOs[0].patterns.length);
assertEquals("servlet", defaultContext.servletDTOs[0].name);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime 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);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method mulitpleServletsWithSamePatternHttpServiceRegistrationWins.
// As specified in OSGi Compendium Release 6, Chapter 140.4
@Test
public void mulitpleServletsWithSamePatternHttpServiceRegistrationWins() throws Exception {
registerServlet("servlet 1", "/pathcollision");
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTO.failedServletDTOs.length);
ServletContextDTO defaultContext = assertDefaultContext(runtimeDTO);
assertEquals(1, defaultContext.servletDTOs.length);
CountDownLatch initLatch = new CountDownLatch(1);
CountDownLatch destroyLatch = new CountDownLatch(1);
TestServlet testServlet = new TestServlet(initLatch, destroyLatch);
register("/pathcollision", testServlet);
RuntimeDTO runtimeWithShadowedServlet = serviceRuntime.getRuntimeDTO();
awaitServiceRegistration(initLatch);
defaultContext = assertDefaultContext(runtimeWithShadowedServlet);
ServletContextDTO httpServiceContext = runtimeWithShadowedServlet.servletContextDTOs[0];
assertEquals(HTTP_CONTEXT_NAME, httpServiceContext.name);
assertEquals(1, httpServiceContext.servletDTOs.length);
assertArrayEquals(new String[] { "/pathcollision" }, httpServiceContext.servletDTOs[0].patterns);
assertEquals(1, defaultContext.servletDTOs.length);
ServletDTO servletDTO = defaultContext.servletDTOs[0];
assertEquals("servlet 1", servletDTO.name);
// check request info DTO to see which servlet responds
final RequestInfoDTO infoDTO = serviceRuntime.calculateRequestInfoDTO("/pathcollision");
assertEquals(httpServiceContext.serviceId, infoDTO.servletDTO.servletContextId);
unregister("/pathcollision");
awaitServiceRegistration(destroyLatch);
runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTO.failedServletDTOs.length);
defaultContext = assertDefaultContext(runtimeDTO);
assertEquals(1, defaultContext.servletDTOs.length);
assertEquals("servlet 1", defaultContext.servletDTOs[0].name);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method dtosForSuccesfullyRegisteredFilters.
@Test
public void dtosForSuccesfullyRegisteredFilters() throws Exception {
// register first filter
registerFilter("testFilter 1", "/servlet_1");
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTOWithFirstFilter = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithFirstFilter.failedFilterDTOs.length);
ServletContextDTO contextDTO = assertDefaultContext(runtimeDTOWithFirstFilter);
assertEquals(1, contextDTO.filterDTOs.length);
assertEquals("testFilter 1", contextDTO.filterDTOs[0].name);
// register second filter
registerFilter("testFilter 2", "/servlet_1");
RuntimeDTO runtimeDTOWithBothFilters = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithBothFilters.failedFilterDTOs.length);
contextDTO = assertDefaultContext(runtimeDTOWithBothFilters);
assertEquals(2, contextDTO.filterDTOs.length);
assertEquals("testFilter 1", contextDTO.filterDTOs[0].name);
assertEquals("testFilter 2", contextDTO.filterDTOs[1].name);
}
Aggregations