use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method multipleErrorPagesForSameErrorCodeChoosenByServiceRankingRules.
// As specified in OSGi Compendium Release 6, Chapter 140.4.1
@Test
public void multipleErrorPagesForSameErrorCodeChoosenByServiceRankingRules() throws InterruptedException {
registerErrorPage("error page 1", asList(NullPointerException.class.getName(), "500"));
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
ServletContextDTO defaultContext = assertDefaultContext(runtimeDTO);
assertEquals(0, runtimeDTO.failedErrorPageDTOs.length);
assertEquals(1, defaultContext.errorPageDTOs.length);
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, asList("500", IllegalArgumentException.class.getName()), HTTP_WHITEBOARD_SERVLET_NAME, "error page 2", SERVICE_RANKING, Integer.MAX_VALUE);
CountDownLatch initLatch = new CountDownLatch(1);
CountDownLatch destroyLatch = new CountDownLatch(1);
TestServlet testServlet = new TestServlet(initLatch, destroyLatch);
ServiceRegistration<?> higherRankingServlet = m_context.registerService(Servlet.class.getName(), testServlet, properties);
registrations.add(higherRankingServlet);
awaitServiceRegistration(initLatch);
RuntimeDTO runtimeWithShadowedErrorPage = serviceRuntime.getRuntimeDTO();
defaultContext = assertDefaultContext(runtimeWithShadowedErrorPage);
assertEquals(2, defaultContext.errorPageDTOs.length);
assertEquals("error page 2", defaultContext.errorPageDTOs[0].name);
assertArrayEquals(new long[] { 500 }, defaultContext.errorPageDTOs[0].errorCodes);
assertArrayEquals(new String[] { IllegalArgumentException.class.getName() }, defaultContext.errorPageDTOs[0].exceptions);
assertEquals("error page 1", defaultContext.errorPageDTOs[1].name);
assertEquals(0, defaultContext.errorPageDTOs[1].errorCodes.length);
assertArrayEquals(new String[] { NullPointerException.class.getName() }, defaultContext.errorPageDTOs[1].exceptions);
assertEquals(1, runtimeWithShadowedErrorPage.failedErrorPageDTOs.length);
FailedErrorPageDTO failedErrorPageDTO = runtimeWithShadowedErrorPage.failedErrorPageDTOs[0];
assertEquals("error page 1", failedErrorPageDTO.name);
assertArrayEquals(new long[] { 500 }, failedErrorPageDTO.errorCodes);
assertEquals(0, failedErrorPageDTO.exceptions.length);
assertEquals(FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, failedErrorPageDTO.failureReason);
higherRankingServlet.unregister();
awaitServiceRegistration(destroyLatch);
runtimeDTO = serviceRuntime.getRuntimeDTO();
defaultContext = assertDefaultContext(runtimeDTO);
assertEquals(0, runtimeDTO.failedErrorPageDTOs.length);
assertEquals(1, defaultContext.errorPageDTOs.length);
assertEquals("error page 1", defaultContext.errorPageDTOs[0].name);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method successfulSetup.
@Test
public void successfulSetup() throws InterruptedException {
CountDownLatch initLatch = new CountDownLatch(6);
registerContext("test-context", "/test-context");
registerServlet("default servlet", "/default", initLatch);
registerFilter("default filter", "/default", initLatch);
registerErrorPage("default error page", asList(Exception.class.getName()), initLatch);
registerResource("/", "/default/resource");
registerListener(ServletRequestListener.class, true);
registerServlet("context servlet", "/default", "(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=test-context)", initLatch);
registerFilter("context filter", "/default", "(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=test-context)", initLatch);
registerErrorPage("context error page", asList("500"), "(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=test-context)", initLatch);
registerResource("/", "/test-contextd/resource", "(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=test-context)");
registerListener(ServletRequestListener.class, true, "(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=test-context)");
awaitServiceRegistration(initLatch);
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTO.failedErrorPageDTOs.length);
assertEquals(0, runtimeDTO.failedFilterDTOs.length);
assertEquals(0, runtimeDTO.failedListenerDTOs.length);
assertEquals(0, runtimeDTO.failedResourceDTOs.length);
assertEquals(0, runtimeDTO.failedServletContextDTOs.length);
assertEquals(0, runtimeDTO.failedServletDTOs.length);
assertEquals(3, runtimeDTO.servletContextDTOs.length);
assertEquals(HTTP_CONTEXT_NAME, runtimeDTO.servletContextDTOs[0].name);
assertEquals("test-context", runtimeDTO.servletContextDTOs[1].name);
assertEquals("default", runtimeDTO.servletContextDTOs[2].name);
ServletContextDTO defaultContextDTO = runtimeDTO.servletContextDTOs[2];
long contextServiceId = defaultContextDTO.serviceId;
assertEquals(Arrays.toString(defaultContextDTO.servletDTOs), 2, defaultContextDTO.servletDTOs.length);
assertServlet(defaultContextDTO.servletDTOs, "default servlet", contextServiceId);
assertServlet(defaultContextDTO.servletDTOs, "default error page", contextServiceId);
assertEquals(1, defaultContextDTO.filterDTOs.length);
assertEquals("default filter", defaultContextDTO.filterDTOs[0].name);
assertEquals(contextServiceId, defaultContextDTO.filterDTOs[0].servletContextId);
assertEquals(1, defaultContextDTO.errorPageDTOs.length);
assertEquals(Exception.class.getName(), defaultContextDTO.errorPageDTOs[0].exceptions[0]);
assertEquals(contextServiceId, defaultContextDTO.errorPageDTOs[0].servletContextId);
assertEquals(1, defaultContextDTO.listenerDTOs.length);
assertEquals(ServletRequestListener.class.getName(), defaultContextDTO.listenerDTOs[0].types[0]);
assertEquals(contextServiceId, defaultContextDTO.listenerDTOs[0].servletContextId);
ServletContextDTO testContextDTO = runtimeDTO.servletContextDTOs[1];
contextServiceId = testContextDTO.serviceId;
assertEquals(2, testContextDTO.servletDTOs.length);
assertServlet(testContextDTO.servletDTOs, "context servlet", contextServiceId);
assertServlet(testContextDTO.servletDTOs, "context error page", contextServiceId);
assertEquals(1, testContextDTO.filterDTOs.length);
assertEquals("context filter", testContextDTO.filterDTOs[0].name);
assertEquals(contextServiceId, testContextDTO.filterDTOs[0].servletContextId);
assertEquals(1, testContextDTO.errorPageDTOs.length);
assertEquals(500L, testContextDTO.errorPageDTOs[0].errorCodes[0]);
assertEquals(contextServiceId, testContextDTO.errorPageDTOs[0].servletContextId);
assertEquals(1, testContextDTO.listenerDTOs.length);
assertEquals(ServletRequestListener.class.getName(), testContextDTO.listenerDTOs[0].types[0]);
assertEquals(contextServiceId, testContextDTO.listenerDTOs[0].servletContextId);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method servletWithoutNameGetsFullyQualifiedName.
// As specified in OSGi Compendium Release 6, Chapter 140.4
@Test
public void servletWithoutNameGetsFullyQualifiedName() throws InterruptedException {
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/servlet");
CountDownLatch initLatch = new CountDownLatch(1);
registrations.add(m_context.registerService(Servlet.class.getName(), new TestServlet(initLatch, null), properties));
awaitServiceRegistration(initLatch);
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTO.failedServletDTOs.length);
ServletContextDTO defaultContext = assertDefaultContext(serviceRuntime.getRuntimeDTO());
assertEquals(1, defaultContext.servletDTOs.length);
assertEquals(TestServlet.class.getName(), defaultContext.servletDTOs[0].name);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method invalidContextHelperNameAppearsAsFailure.
// As specified in OSGi Compendium Release 6, Chapter 140.1
@Test
public void invalidContextHelperNameAppearsAsFailure() throws InterruptedException {
registerContext("context A", "");
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(1, runtimeDTO.failedServletContextDTOs.length);
assertEquals("context A", runtimeDTO.failedServletContextDTOs[0].name);
assertEquals(FAILURE_REASON_VALIDATION_FAILED, runtimeDTO.failedServletContextDTOs[0].failureReason);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method dtosForSuccesfullyRegisteredErrorPageWithWildcardErrorCode.
public void dtosForSuccesfullyRegisteredErrorPageWithWildcardErrorCode(String code, long startCode) throws Exception {
registerErrorPage("error page 1", asList(code));
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTOWithErrorPage = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithErrorPage.failedServletDTOs.length);
assertEquals(0, runtimeDTOWithErrorPage.failedErrorPageDTOs.length);
ServletContextDTO contextDTO = assertDefaultContext(runtimeDTOWithErrorPage);
assertEquals(1, contextDTO.errorPageDTOs.length);
assertEquals("error page 1", contextDTO.errorPageDTOs[0].name);
assertContainsAllHundredFrom(startCode, contextDTO.errorPageDTOs[0].errorCodes);
}
Aggregations