Search in sources :

Example 11 with RuntimeDTO

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

the class HttpServiceRuntimeTest method exceptionInServletInitAppearsAsFailure.

@Test
public void exceptionInServletInitAppearsAsFailure() throws ServletException, InterruptedException {
    Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/servlet", HTTP_WHITEBOARD_SERVLET_NAME, "servlet");
    CountDownLatch initLatch = new CountDownLatch(1);
    @SuppressWarnings("serial") Servlet failingServlet = new TestServlet(initLatch, null) {

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

Example 12 with RuntimeDTO

use of org.osgi.service.http.runtime.dto.RuntimeDTO 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);
}
Also used : ServletException(javax.servlet.ServletException) HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 13 with RuntimeDTO

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

the class HttpServiceRuntimeTest method contextHelperWithDuplicateNameAppearsAsFailure.

// As specified in OSGi Compendium Release 6, Chapter 140.1
@Test
public void contextHelperWithDuplicateNameAppearsAsFailure() throws InterruptedException {
    ServiceRegistration<?> firstContextReg = registerContext("contextA", "/first");
    registerContext("contextA", "/second");
    HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
    assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
    RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
    assertEquals(1, runtimeDTO.failedServletContextDTOs.length);
    assertEquals("contextA", runtimeDTO.failedServletContextDTOs[0].name);
    assertEquals("/second", runtimeDTO.failedServletContextDTOs[0].contextPath);
    assertEquals(FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, runtimeDTO.failedServletContextDTOs[0].failureReason);
    assertEquals(3, runtimeDTO.servletContextDTOs.length);
    assertEquals(HTTP_CONTEXT_NAME, runtimeDTO.servletContextDTOs[0].name);
    assertEquals("default", runtimeDTO.servletContextDTOs[2].name);
    assertEquals("contextA", runtimeDTO.servletContextDTOs[1].name);
    assertEquals("/first", runtimeDTO.servletContextDTOs[1].contextPath);
    firstContextReg.unregister();
    runtimeDTO = serviceRuntime.getRuntimeDTO();
    assertEquals(0, runtimeDTO.failedServletContextDTOs.length);
    assertEquals(3, runtimeDTO.servletContextDTOs.length);
    assertEquals(HTTP_CONTEXT_NAME, runtimeDTO.servletContextDTOs[0].name);
    assertEquals("default", runtimeDTO.servletContextDTOs[2].name);
    assertEquals("contextA", runtimeDTO.servletContextDTOs[1].name);
    assertEquals("/second", runtimeDTO.servletContextDTOs[1].contextPath);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 14 with RuntimeDTO

use of org.osgi.service.http.runtime.dto.RuntimeDTO 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 15 with RuntimeDTO

use of org.osgi.service.http.runtime.dto.RuntimeDTO 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)

Aggregations

RuntimeDTO (org.osgi.service.http.runtime.dto.RuntimeDTO)34 HttpServiceRuntime (org.osgi.service.http.runtime.HttpServiceRuntime)31 Test (org.junit.Test)30 ServletContextDTO (org.osgi.service.http.runtime.dto.ServletContextDTO)21 CountDownLatch (java.util.concurrent.CountDownLatch)12 ServletException (javax.servlet.ServletException)5 Servlet (javax.servlet.Servlet)4 FailedServletDTO (org.osgi.service.http.runtime.dto.FailedServletDTO)4 FailedErrorPageDTO (org.osgi.service.http.runtime.dto.FailedErrorPageDTO)3 FailedServletContextDTO (org.osgi.service.http.runtime.dto.FailedServletContextDTO)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 NoSuchElementException (java.util.NoSuchElementException)2 ServletRequestListener (javax.servlet.ServletRequestListener)2 FailedFilterDTO (org.osgi.service.http.runtime.dto.FailedFilterDTO)2 FailedListenerDTO (org.osgi.service.http.runtime.dto.FailedListenerDTO)2 FailedResourceDTO (org.osgi.service.http.runtime.dto.FailedResourceDTO)2 ServletDTO (org.osgi.service.http.runtime.dto.ServletDTO)2 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1