use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method exceptionInServletInitAppearsAsFailure.
@Test
public void exceptionInServletInitAppearsAsFailure() throws ServletException, InterruptedException {
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/servlet", HTTP_WHITEBOARD_SERVLET_NAME, "servlet");
CountDownLatch initLatch = new CountDownLatch(1);
@SuppressWarnings("serial") Servlet failingServlet = new TestServlet(initLatch, null) {
@Override
public void init() throws ServletException {
super.init();
throw new ServletException();
}
};
registrations.add(m_context.registerService(Servlet.class.getName(), failingServlet, properties));
awaitServiceRegistration(initLatch);
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(1, runtimeDTO.failedServletDTOs.length);
assertEquals("servlet", runtimeDTO.failedServletDTOs[0].name);
assertEquals(FAILURE_REASON_EXCEPTION_ON_INIT, runtimeDTO.failedServletDTOs[0].failureReason);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method dtosForSuccesfullyRegisteredErrorPages.
@Test
public void dtosForSuccesfullyRegisteredErrorPages() throws Exception {
// register first error page
registerErrorPage("error page 1", asList("404", NoSuchElementException.class.getName()));
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTOWithFirstErrorPage = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithFirstErrorPage.failedServletDTOs.length);
assertEquals(0, runtimeDTOWithFirstErrorPage.failedErrorPageDTOs.length);
ServletContextDTO contextDTO = assertDefaultContext(runtimeDTOWithFirstErrorPage);
assertEquals(1, contextDTO.errorPageDTOs.length);
assertEquals("error page 1", contextDTO.errorPageDTOs[0].name);
assertArrayEquals(new String[] { NoSuchElementException.class.getName() }, contextDTO.errorPageDTOs[0].exceptions);
assertArrayEquals(new long[] { 404 }, contextDTO.errorPageDTOs[0].errorCodes);
// register second error page
registerErrorPage("error page 2", asList("500", ServletException.class.getName()));
RuntimeDTO runtimeDTOWithBothErrorPages = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithBothErrorPages.failedServletDTOs.length);
assertEquals(0, runtimeDTOWithBothErrorPages.failedErrorPageDTOs.length);
contextDTO = assertDefaultContext(runtimeDTOWithBothErrorPages);
assertEquals(2, contextDTO.errorPageDTOs.length);
assertEquals("error page 1", contextDTO.errorPageDTOs[0].name);
assertEquals("error page 2", contextDTO.errorPageDTOs[1].name);
assertArrayEquals(new String[] { ServletException.class.getName() }, contextDTO.errorPageDTOs[1].exceptions);
assertArrayEquals(new long[] { 500 }, contextDTO.errorPageDTOs[1].errorCodes);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method contextHelperWithDuplicateNameAppearsAsFailure.
// As specified in OSGi Compendium Release 6, Chapter 140.1
@Test
public void contextHelperWithDuplicateNameAppearsAsFailure() throws InterruptedException {
ServiceRegistration<?> firstContextReg = registerContext("contextA", "/first");
registerContext("contextA", "/second");
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(1, runtimeDTO.failedServletContextDTOs.length);
assertEquals("contextA", runtimeDTO.failedServletContextDTOs[0].name);
assertEquals("/second", runtimeDTO.failedServletContextDTOs[0].contextPath);
assertEquals(FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, runtimeDTO.failedServletContextDTOs[0].failureReason);
assertEquals(3, runtimeDTO.servletContextDTOs.length);
assertEquals(HTTP_CONTEXT_NAME, runtimeDTO.servletContextDTOs[0].name);
assertEquals("default", runtimeDTO.servletContextDTOs[2].name);
assertEquals("contextA", runtimeDTO.servletContextDTOs[1].name);
assertEquals("/first", runtimeDTO.servletContextDTOs[1].contextPath);
firstContextReg.unregister();
runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTO.failedServletContextDTOs.length);
assertEquals(3, runtimeDTO.servletContextDTOs.length);
assertEquals(HTTP_CONTEXT_NAME, runtimeDTO.servletContextDTOs[0].name);
assertEquals("default", runtimeDTO.servletContextDTOs[2].name);
assertEquals("contextA", runtimeDTO.servletContextDTOs[1].name);
assertEquals("/second", runtimeDTO.servletContextDTOs[1].contextPath);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO 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.dto.RuntimeDTO 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);
}
Aggregations