Search in sources :

Example 31 with HttpServiceRuntime

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

the class HttpServiceRuntimeTest method invalidListenerPopertyValueAppearsAsFailure.

// As specified in OSGi Compendium Release 6, Chapter 140.7
@Test
public void invalidListenerPopertyValueAppearsAsFailure() throws Exception {
    Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_LISTENER, "invalid");
    registrations.add(m_context.registerService(ServletRequestListener.class.getName(), mock(ServletRequestListener.class), properties));
    HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
    assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
    RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
    assertEquals(1, runtimeDTO.failedListenerDTOs.length);
    assertEquals(FAILURE_REASON_VALIDATION_FAILED, runtimeDTO.failedListenerDTOs[0].failureReason);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 32 with HttpServiceRuntime

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

the class HttpServiceRuntimeTest method selectionOfNonExistingContextHelperAppearsAsFailure.

// As specified in OSGi Compendium Release 6, Chapter 140.3
@Test
public void selectionOfNonExistingContextHelperAppearsAsFailure() throws InterruptedException {
    registerServlet("servlet 1", "/", "(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=contextA)", null);
    awaitServiceRegistration();
    HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
    assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
    RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
    assertEquals(1, runtimeDTO.failedServletDTOs.length);
    assertEquals("servlet 1", runtimeDTO.failedServletDTOs[0].name);
    assertEquals(FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING, runtimeDTO.failedServletDTOs[0].failureReason);
    registerContext("contextA", "/contextA");
    runtimeDTO = serviceRuntime.getRuntimeDTO();
    assertEquals(0, runtimeDTO.failedServletDTOs.length);
    assertEquals(3, runtimeDTO.servletContextDTOs.length);
    assertEquals("contextA", runtimeDTO.servletContextDTOs[1].name);
    assertEquals(1, runtimeDTO.servletContextDTOs[1].servletDTOs.length);
    assertEquals("servlet 1", runtimeDTO.servletContextDTOs[1].servletDTOs[0].name);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 33 with HttpServiceRuntime

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

the class HttpServiceRuntimeTest method httpRuntimeServiceIsAvailableAfterBundleActivation.

@Test
public void httpRuntimeServiceIsAvailableAfterBundleActivation() throws Exception {
    HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
    assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
    RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
    ServiceReferenceDTO serviceDTO = runtimeDTO.serviceDTO;
    assertNotNull(serviceDTO);
    assertNotNull(serviceDTO.properties);
    assertTrue(serviceDTO.properties.containsKey(HTTP_SERVICE_ID));
    assertTrue(serviceDTO.properties.containsKey(HTTP_SERVICE_ENDPOINT));
    assertTrue(serviceDTO.properties.get(HTTP_SERVICE_ID) instanceof Collection);
    final Collection ids = (Collection) serviceDTO.properties.get(HTTP_SERVICE_ID);
    assertTrue(ids.size() == 1);
    assertTrue(ids.iterator().next() instanceof Long);
    assertTrue(0 < (Long) ids.iterator().next());
    assertEquals(0, runtimeDTO.failedErrorPageDTOs.length);
    assertEquals(0, runtimeDTO.failedFilterDTOs.length);
    assertEquals(0, runtimeDTO.failedListenerDTOs.length);
    assertEquals(0, runtimeDTO.failedResourceDTOs.length);
    assertEquals(0, runtimeDTO.failedServletContextDTOs.length);
    assertEquals(0, runtimeDTO.failedServletDTOs.length);
    ServletContextDTO defaultContext = assertDefaultContext(runtimeDTO);
    assertEquals(0, defaultContext.attributes.size());
    // TODO The default context should have a negative service Id
    // assertTrue(0 > runtimeDTO.servletContextDTOs[0].serviceId);
    // TODO Should be "/" ?
    assertEquals("", defaultContext.contextPath);
    assertEquals(0, defaultContext.initParams.size());
    assertEquals(0, defaultContext.filterDTOs.length);
    assertEquals(0, defaultContext.servletDTOs.length);
    assertEquals(0, defaultContext.resourceDTOs.length);
    assertEquals(0, defaultContext.errorPageDTOs.length);
    assertEquals(0, defaultContext.listenerDTOs.length);
}
Also used : ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) Collection(java.util.Collection) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 34 with HttpServiceRuntime

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

the class HttpServiceTest method testServletAndOldWhiteboardFilter.

@Test
public void testServletAndOldWhiteboardFilter() throws Exception {
    final HttpService service = this.getHttpService();
    service.registerServlet("/tesths", new TestServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
            resp.getWriter().print("helloworld");
            resp.flushBuffer();
        }
    }, null, null);
    this.setupLatches(1);
    this.setupOldWhiteboardFilter(".*");
    assertTrue(initLatch.await(5, TimeUnit.SECONDS));
    final HttpServiceRuntime rt = this.getService(HttpServiceRuntime.class.getName());
    System.out.println(rt.getRuntimeDTO());
    try {
        assertContent("FILTER-helloworld", createURL("/tesths"));
    } finally {
        service.unregister("/tesths");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) HttpService(org.osgi.service.http.HttpService) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) 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