Search in sources :

Example 11 with HttpServiceRuntime

use of org.osgi.service.http.runtime.HttpServiceRuntime 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);
}
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 12 with HttpServiceRuntime

use of org.osgi.service.http.runtime.HttpServiceRuntime 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);
}
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 13 with HttpServiceRuntime

use of org.osgi.service.http.runtime.HttpServiceRuntime in project felix by apache.

the class HttpServiceRuntimeTest method exceptionInFilterInitAppearsAsFailure.

@Test
public void exceptionInFilterInitAppearsAsFailure() throws ServletException, InterruptedException {
    Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_FILTER_PATTERN, "/filter", HTTP_WHITEBOARD_FILTER_NAME, "filter");
    CountDownLatch initLatch = new CountDownLatch(1);
    Filter failingFilter = new TestFilter(initLatch, null) {

        @Override
        public void init(FilterConfig config) throws ServletException {
            super.init(config);
            throw new ServletException();
        }
    };
    registrations.add(m_context.registerService(Filter.class.getName(), failingFilter, properties));
    awaitServiceRegistration(initLatch);
    HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
    assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
    RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
    assertEquals(1, runtimeDTO.failedFilterDTOs.length);
    assertEquals("filter", runtimeDTO.failedFilterDTOs[0].name);
    assertEquals(FAILURE_REASON_EXCEPTION_ON_INIT, runtimeDTO.failedFilterDTOs[0].failureReason);
}
Also used : ServletException(javax.servlet.ServletException) Filter(javax.servlet.Filter) HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) FilterConfig(javax.servlet.FilterConfig) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 14 with HttpServiceRuntime

use of org.osgi.service.http.runtime.HttpServiceRuntime 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);
}
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) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) CountDownLatch(java.util.concurrent.CountDownLatch) FailedServletDTO(org.osgi.service.http.runtime.dto.FailedServletDTO) ServletDTO(org.osgi.service.http.runtime.dto.ServletDTO) Test(org.junit.Test)

Example 15 with HttpServiceRuntime

use of org.osgi.service.http.runtime.HttpServiceRuntime 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);
}
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)

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