use of org.osgi.service.http.runtime.dto.ServletContextDTO in project felix by apache.
the class HttpServiceRuntimeTest method dtosForSuccesfullyRegisteredResources.
@Test
public void dtosForSuccesfullyRegisteredResources() throws Exception {
// register first resource service
registerResource("/resources", "/resource_1/*");
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTOWithFirstResource = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithFirstResource.failedResourceDTOs.length);
ServletContextDTO contextDTO = assertDefaultContext(runtimeDTOWithFirstResource);
assertEquals(1, contextDTO.resourceDTOs.length);
assertEquals("/resources", contextDTO.resourceDTOs[0].prefix);
assertArrayEquals(new String[] { "/resource_1/*" }, contextDTO.resourceDTOs[0].patterns);
// register second resource service
registerResource("/resources", "/resource_2/*");
RuntimeDTO runtimeDTOWithBothResources = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithBothResources.failedResourceDTOs.length);
contextDTO = assertDefaultContext(runtimeDTOWithBothResources);
assertEquals(2, contextDTO.resourceDTOs.length);
assertEquals("/resources", contextDTO.resourceDTOs[0].prefix);
assertEquals(1, contextDTO.resourceDTOs[0].patterns.length);
assertEquals(1, contextDTO.resourceDTOs[1].patterns.length);
final Set<String> patterns = new HashSet<>();
patterns.add(contextDTO.resourceDTOs[0].patterns[0]);
patterns.add(contextDTO.resourceDTOs[1].patterns[0]);
assertTrue(patterns.contains("/resource_1/*"));
assertTrue(patterns.contains("/resource_2/*"));
}
use of org.osgi.service.http.runtime.dto.ServletContextDTO 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.ServletContextDTO 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.ServletContextDTO 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.dto.ServletContextDTO 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);
}
Aggregations