use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method missingContextHelperNameAppearsAsFailure.
// As specified in OSGi Compendium Release 6, Chapter 140.1
@Test
public void missingContextHelperNameAppearsAsFailure() {
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_CONTEXT_PATH, "");
registrations.add(m_context.registerService(ServletContextHelper.class.getName(), mock(ServletContextHelper.class), properties));
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(1, runtimeDTO.failedServletContextDTOs.length);
assertEquals(null, 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 requestInfoDTO.
@Test
public void requestInfoDTO() throws Exception {
registerServlet("servlet", "/default");
registerFilter("filter1", "/default");
registerFilter("filter2", "/default");
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
ServletContextDTO defaultContext = assertDefaultContext(serviceRuntime.getRuntimeDTO());
long defaultContextId = defaultContext.serviceId;
RequestInfoDTO requestInfoDTO = serviceRuntime.calculateRequestInfoDTO("/default");
assertEquals("/default", requestInfoDTO.path);
assertEquals(defaultContextId, requestInfoDTO.servletContextId);
assertEquals("servlet", requestInfoDTO.servletDTO.name);
assertEquals(2, requestInfoDTO.filterDTOs.length);
assertEquals("filter1", requestInfoDTO.filterDTOs[0].name);
assertEquals("filter2", requestInfoDTO.filterDTOs[1].name);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method dtosForSuccesfullyRegisteredListeners.
@Test
public void dtosForSuccesfullyRegisteredListeners() throws Exception {
// register a servlet context listenere as first listener
registerListener(ServletContextListener.class, true);
awaitService(ServletContextListener.class.getName());
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTOWithFirstListener = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithFirstListener.failedListenerDTOs.length);
ServletContextDTO contextDTO = assertDefaultContext(runtimeDTOWithFirstListener);
assertEquals(1, contextDTO.listenerDTOs.length);
assertEquals(ServletContextListener.class.getName(), contextDTO.listenerDTOs[0].types[0]);
// register all other listener types
registerListener(ServletContextAttributeListener.class, true);
registerListener(ServletRequestListener.class, true);
registerListener(ServletRequestAttributeListener.class, true);
registerListener(HttpSessionListener.class, true);
registerListener(HttpSessionAttributeListener.class, true);
awaitService(ServletContextAttributeListener.class.getName());
awaitService(ServletRequestListener.class.getName());
awaitService(ServletRequestAttributeListener.class.getName());
awaitService(HttpSessionListener.class.getName());
awaitService(HttpSessionAttributeListener.class.getName());
RuntimeDTO runtimeDTOWithAllListeners = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithAllListeners.failedListenerDTOs.length);
contextDTO = assertDefaultContext(runtimeDTOWithAllListeners);
assertEquals(6, contextDTO.listenerDTOs.length);
assertEquals(ServletContextListener.class.getName(), contextDTO.listenerDTOs[0].types[0]);
assertEquals(ServletContextAttributeListener.class.getName(), contextDTO.listenerDTOs[1].types[0]);
assertEquals(ServletRequestListener.class.getName(), contextDTO.listenerDTOs[2].types[0]);
assertEquals(ServletRequestAttributeListener.class.getName(), contextDTO.listenerDTOs[3].types[0]);
assertEquals(HttpSessionListener.class.getName(), contextDTO.listenerDTOs[4].types[0]);
assertEquals(HttpSessionAttributeListener.class.getName(), contextDTO.listenerDTOs[5].types[0]);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method patternAndErrorPageSpecified.
// As specified in OSGi Compendium Release 6, Chapter 140.4.1
@Test
public void patternAndErrorPageSpecified() throws InterruptedException {
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/servlet", HTTP_WHITEBOARD_SERVLET_NAME, "servlet", HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, asList("400"));
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();
ServletContextDTO defaultContext = assertDefaultContext(runtimeDTO);
assertEquals(0, runtimeDTO.failedErrorPageDTOs.length);
assertEquals(0, runtimeDTO.failedServletDTOs.length);
assertEquals(1, defaultContext.servletDTOs.length);
assertEquals(1, defaultContext.errorPageDTOs.length);
assertEquals("servlet", defaultContext.servletDTOs[0].name);
assertEquals("servlet", defaultContext.errorPageDTOs[0].name);
assertArrayEquals(new String[] { "/servlet" }, defaultContext.servletDTOs[0].patterns);
assertArrayEquals(new long[] { 400 }, defaultContext.errorPageDTOs[0].errorCodes);
}
use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.
the class HttpServiceRuntimeTest method dtosAreIndependentCopies.
@Test
public void dtosAreIndependentCopies() throws Exception {
// register first servlet
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/test", HTTP_WHITEBOARD_SERVLET_NAME, "servlet 1", HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX + "test", "testValue");
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 runtimeDTOWithFirstSerlvet = serviceRuntime.getRuntimeDTO();
// register second servlet
registerServlet("testServlet 2", "/servlet_2");
RuntimeDTO runtimeDTOWithTwoSerlvets = serviceRuntime.getRuntimeDTO();
assertNotSame(runtimeDTOWithFirstSerlvet, runtimeDTOWithTwoSerlvets);
ServletContextDTO defaultContextFirstServlet = assertDefaultContext(runtimeDTOWithFirstSerlvet);
ServletContextDTO defaultContextTwoServlets = assertDefaultContext(runtimeDTOWithTwoSerlvets);
assertNotSame(defaultContextFirstServlet.servletDTOs[0].patterns, defaultContextTwoServlets.servletDTOs[0].patterns);
boolean mapsModifiable = true;
try {
defaultContextTwoServlets.servletDTOs[0].initParams.clear();
} catch (UnsupportedOperationException e) {
mapsModifiable = false;
}
if (mapsModifiable) {
assertNotSame(defaultContextFirstServlet.servletDTOs[0].initParams, defaultContextTwoServlets.servletDTOs[0].initParams);
}
}
Aggregations