Search in sources :

Example 26 with HttpServiceRuntime

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);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 27 with HttpServiceRuntime

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);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) RequestInfoDTO(org.osgi.service.http.runtime.dto.RequestInfoDTO) Test(org.junit.Test)

Example 28 with HttpServiceRuntime

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]);
}
Also used : ServletContextAttributeListener(javax.servlet.ServletContextAttributeListener) ServletRequestAttributeListener(javax.servlet.ServletRequestAttributeListener) HttpSessionListener(javax.servlet.http.HttpSessionListener) ServletContextListener(javax.servlet.ServletContextListener) HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) ServletRequestListener(javax.servlet.ServletRequestListener) HttpSessionAttributeListener(javax.servlet.http.HttpSessionAttributeListener) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 29 with HttpServiceRuntime

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);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 30 with HttpServiceRuntime

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);
    }
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

HttpServiceRuntime (org.osgi.service.http.runtime.HttpServiceRuntime)34 Test (org.junit.Test)32 RuntimeDTO (org.osgi.service.http.runtime.dto.RuntimeDTO)31 ServletContextDTO (org.osgi.service.http.runtime.dto.ServletContextDTO)20 CountDownLatch (java.util.concurrent.CountDownLatch)12 ServletException (javax.servlet.ServletException)5 Servlet (javax.servlet.Servlet)4 HashSet (java.util.HashSet)2 NoSuchElementException (java.util.NoSuchElementException)2 ServletRequestListener (javax.servlet.ServletRequestListener)2 ServletContextHelper (org.osgi.service.http.context.ServletContextHelper)2 FailedServletDTO (org.osgi.service.http.runtime.dto.FailedServletDTO)2 RequestInfoDTO (org.osgi.service.http.runtime.dto.RequestInfoDTO)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Dictionary (java.util.Dictionary)1 Filter (javax.servlet.Filter)1 FilterConfig (javax.servlet.FilterConfig)1 ServletContextAttributeListener (javax.servlet.ServletContextAttributeListener)1