use of org.osgi.service.http.runtime.dto.ServletContextDTO 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.ServletContextDTO in project felix by apache.
the class HttpServiceRuntimeTest method testCombinedServletAndResourceRegistration.
/**
* Test for FELIX-5319
* @throws Exception
*/
@Test
public void testCombinedServletAndResourceRegistration() throws Exception {
// register single component as Servlet and Resource
final String servletPath = "/hello/sayHello";
final String servletName = "Hello World";
final String rsrcPattern = "/hello/static/*";
final String rsrcPrefix = "/static";
CountDownLatch initLatch = new CountDownLatch(1);
List<Object> propertyEntries = Arrays.<Object>asList(HTTP_WHITEBOARD_SERVLET_PATTERN, servletPath, HTTP_WHITEBOARD_SERVLET_NAME, servletName, HTTP_WHITEBOARD_RESOURCE_PATTERN, rsrcPattern, HTTP_WHITEBOARD_RESOURCE_PREFIX, rsrcPrefix);
Dictionary<String, ?> properties = createDictionary(propertyEntries.toArray());
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);
assertEquals(0, runtimeDTO.failedResourceDTOs.length);
// check servlet registration
ServletContextDTO contextDTO = assertDefaultContext(runtimeDTO);
assertEquals(1, contextDTO.servletDTOs.length);
assertEquals(servletName, contextDTO.servletDTOs[0].name);
assertEquals(1, contextDTO.servletDTOs[0].patterns.length);
assertEquals(servletPath, contextDTO.servletDTOs[0].patterns[0]);
// check resource registration
assertEquals(1, contextDTO.resourceDTOs.length);
assertEquals(1, contextDTO.resourceDTOs[0].patterns.length);
assertEquals(rsrcPattern, contextDTO.resourceDTOs[0].patterns[0]);
assertEquals(rsrcPrefix, contextDTO.resourceDTOs[0].prefix);
}
use of org.osgi.service.http.runtime.dto.ServletContextDTO in project felix by apache.
the class ErrorPageRegistryTest method testRangeRegistration.
@Test
public void testRangeRegistration() throws InvalidSyntaxException {
final ErrorPageRegistry reg = new ErrorPageRegistry();
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
final ServletHandler handler4 = createServletHandler(1L, 0, "4xx");
final ServletHandler handler5 = createServletHandler(2L, 0, "5xx");
reg.addServlet(handler4);
reg.addServlet(handler5);
// check DTO
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertTrue(holder.failedErrorPageDTOs.isEmpty());
assertEquals(2, dto.errorPageDTOs.length);
assertEquals(100, dto.errorPageDTOs[0].errorCodes.length);
final Set<Long> codes4 = new HashSet<Long>();
for (final long c : dto.errorPageDTOs[0].errorCodes) {
assertTrue(c >= 400 && c < 500);
codes4.add(c);
}
assertEquals(100, codes4.size());
assertEquals(100, dto.errorPageDTOs[1].errorCodes.length);
final Set<Long> codes5 = new HashSet<Long>();
for (final long c : dto.errorPageDTOs[1].errorCodes) {
assertTrue(c >= 500 && c < 600);
codes5.add(c);
}
assertEquals(100, codes5.size());
}
use of org.osgi.service.http.runtime.dto.ServletContextDTO in project felix by apache.
the class HandlerRegistryTest method testInitialSetup.
@Test
public void testInitialSetup() {
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
dto.serviceId = HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID;
assertFalse(registry.getRuntimeInfo(dto, holder));
registry.init();
assertTrue(registry.getRuntimeInfo(dto, holder));
registry.shutdown();
assertFalse(registry.getRuntimeInfo(dto, holder));
}
use of org.osgi.service.http.runtime.dto.ServletContextDTO 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);
}
Aggregations