use of org.osgi.service.http.runtime.dto.RuntimeDTO 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.dto.RuntimeDTO 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.dto.RuntimeDTO 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);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method hiddenDefaultContextAppearsAsFailure.
// As specified in OSGi Compendium Release 6, Chapter 140.1 (TODO : exact version)
@Test
public void hiddenDefaultContextAppearsAsFailure() throws InterruptedException {
registerContext("default", "");
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(1, runtimeDTO.failedServletContextDTOs.length);
assertEquals("default", runtimeDTO.failedServletContextDTOs[0].name);
assertDefaultContext(runtimeDTO);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method exceptionInServletInitDuringServletRemovalAppearsAsFailure.
@Test
public void exceptionInServletInitDuringServletRemovalAppearsAsFailure() throws ServletException, InterruptedException {
Dictionary<String, ?> properties1 = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/servlet1", HTTP_WHITEBOARD_SERVLET_NAME, "servlet1");
final CountDownLatch initLatch1 = new CountDownLatch(1);
@SuppressWarnings("serial") Servlet failingServlet1 = new TestServlet(initLatch1, null) {
@Override
public void init() throws ServletException {
// fail when initialized the second time
if (initLatch1.getCount() == 0) {
throw new ServletException();
}
super.init();
}
};
Dictionary<String, ?> properties2 = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/servlet2", HTTP_WHITEBOARD_SERVLET_NAME, "servlet2");
final CountDownLatch initLatch2 = new CountDownLatch(1);
@SuppressWarnings("serial") Servlet failingServlet2 = new TestServlet(initLatch2, null) {
@Override
public void init() throws ServletException {
// fail when initialized the second time
if (initLatch2.getCount() == 0) {
throw new ServletException();
}
super.init();
}
};
Dictionary<String, ?> propertiesShadowing = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, asList("/servlet1", "/servlet2"), HTTP_WHITEBOARD_SERVLET_NAME, "servletShadowing", SERVICE_RANKING, Integer.MAX_VALUE);
CountDownLatch initLatchShadowing = new CountDownLatch(1);
Servlet servletShadowing = new TestServlet(initLatchShadowing, null);
registrations.add(m_context.registerService(Servlet.class.getName(), failingServlet1, properties1));
registrations.add(m_context.registerService(Servlet.class.getName(), failingServlet2, properties2));
awaitServiceRegistration(initLatch1);
awaitServiceRegistration(initLatch2);
ServiceRegistration<?> shadowingRegistration = m_context.registerService(Servlet.class.getName(), servletShadowing, propertiesShadowing);
registrations.add(shadowingRegistration);
awaitServiceRegistration(initLatchShadowing);
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(2, runtimeDTO.failedServletDTOs.length);
assertEquals(FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, runtimeDTO.failedServletDTOs[0].failureReason);
assertEquals(FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, runtimeDTO.failedServletDTOs[1].failureReason);
shadowingRegistration.unregister();
runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(2, runtimeDTO.failedServletDTOs.length);
assertEquals(FAILURE_REASON_EXCEPTION_ON_INIT, runtimeDTO.failedServletDTOs[0].failureReason);
assertEquals(FAILURE_REASON_EXCEPTION_ON_INIT, runtimeDTO.failedServletDTOs[1].failureReason);
}
Aggregations