Search in sources :

Example 6 with FailedServletDTO

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

the class ServletRegistryTest method testSimpleHiding.

@Test
public void testSimpleHiding() throws InvalidSyntaxException, ServletException {
    final FailedDTOHolder holder = new FailedDTOHolder();
    final ServletContextDTO dto = new ServletContextDTO();
    // empty reg
    reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
    assertEmpty(dto, holder);
    // register servlets
    final ServletHandler h1 = createServletHandler(1L, 10, "/foo");
    reg.addServlet(h1);
    verify(h1.getServlet()).init(Matchers.any(ServletConfig.class));
    final ServletHandler h2 = createServletHandler(2L, 0, "/foo");
    reg.addServlet(h2);
    verify(h2.getServlet(), never()).init(Matchers.any(ServletConfig.class));
    verify(h1.getServlet(), never()).destroy();
    // two entries in reg
    // h1 is active
    // h2 is hidden
    clear(dto, holder);
    reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
    assertNull(dto.resourceDTOs);
    assertTrue(holder.failedResourceDTOs.isEmpty());
    assertFalse(holder.failedServletDTOs.isEmpty());
    assertNotNull(dto.servletDTOs);
    assertEquals(1, dto.servletDTOs.length);
    assertEquals(1, dto.servletDTOs[0].patterns.length);
    assertEquals("/foo", dto.servletDTOs[0].patterns[0]);
    assertEquals(1, dto.servletDTOs[0].serviceId);
    assertEquals(1, holder.failedServletDTOs.size());
    final FailedServletDTO failedDTO = holder.failedServletDTOs.iterator().next();
    assertEquals(1, failedDTO.patterns.length);
    assertEquals("/foo", failedDTO.patterns[0]);
    assertEquals(2, failedDTO.serviceId);
    // remove servlet 1
    final Servlet s1 = h1.getServlet();
    reg.removeServlet(h1.getServletInfo(), true);
    verify(s1).destroy();
    verify(h2.getServlet()).init(Matchers.any(ServletConfig.class));
    // h2 is active
    clear(dto, holder);
    reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
    assertNull(dto.resourceDTOs);
    assertTrue(holder.failedResourceDTOs.isEmpty());
    assertTrue(holder.failedServletDTOs.isEmpty());
    assertNotNull(dto.servletDTOs);
    assertEquals(1, dto.servletDTOs.length);
    assertEquals(1, dto.servletDTOs[0].patterns.length);
    assertEquals("/foo", dto.servletDTOs[0].patterns[0]);
    assertEquals(2, dto.servletDTOs[0].serviceId);
    // remove servlet 2
    final Servlet s2 = h2.getServlet();
    reg.removeServlet(h2.getServletInfo(), true);
    verify(s2).destroy();
    // empty again
    clear(dto, holder);
    reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
    assertEmpty(dto, holder);
}
Also used : ServletHandler(org.apache.felix.http.base.internal.handler.ServletHandler) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) FailedServletDTO(org.osgi.service.http.runtime.dto.FailedServletDTO) FailedDTOHolder(org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) ServletConfig(javax.servlet.ServletConfig) Servlet(javax.servlet.Servlet) Test(org.junit.Test)

Example 7 with FailedServletDTO

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

the class FailureStateHandlerTest method assertContainsExactly.

private void assertContainsExactly(final List<FailedServletDTO> dtos, final long[] contextIds) {
    assertEquals(dtos.size(), contextIds.length);
    final Set<Long> set = new HashSet<Long>();
    for (final long l : contextIds) {
        set.add(l);
    }
    for (final FailedServletDTO dto : dtos) {
        assertTrue(set.remove(dto.servletContextId));
    }
}
Also used : FailedServletDTO(org.osgi.service.http.runtime.dto.FailedServletDTO) HashSet(java.util.HashSet)

Example 8 with FailedServletDTO

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

the class HttpServiceRuntimeTest method multipleServletsForSamePatternChoosenByServiceRankingRules.

// As specified in OSGi Compendium Release 6, Chapter 140.4.1
@Test
public void multipleServletsForSamePatternChoosenByServiceRankingRules() throws InterruptedException {
    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);
    Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/pathcollision", HTTP_WHITEBOARD_SERVLET_NAME, "servlet 2", SERVICE_RANKING, Integer.MAX_VALUE);
    CountDownLatch initLatch = new CountDownLatch(1);
    CountDownLatch destroyLatch = new CountDownLatch(1);
    TestServlet testServlet = new TestServlet(initLatch, destroyLatch);
    ServiceRegistration<?> higherRankingServlet = m_context.registerService(Servlet.class.getName(), testServlet, properties);
    registrations.add(higherRankingServlet);
    RuntimeDTO runtimeWithShadowedServlet = serviceRuntime.getRuntimeDTO();
    awaitServiceRegistration(initLatch);
    defaultContext = assertDefaultContext(runtimeWithShadowedServlet);
    assertEquals(1, defaultContext.servletDTOs.length);
    assertEquals(1, runtimeWithShadowedServlet.failedServletDTOs.length);
    FailedServletDTO failedServletDTO = runtimeWithShadowedServlet.failedServletDTOs[0];
    assertEquals("servlet 1", failedServletDTO.name);
    assertEquals(FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, failedServletDTO.failureReason);
    higherRankingServlet.unregister();
    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 : FailedServletDTO(org.osgi.service.http.runtime.dto.FailedServletDTO) HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) Servlet(javax.servlet.Servlet) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 9 with FailedServletDTO

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

the class HttpServicePlugin method printFailedServletDetails.

private void printFailedServletDetails(final PrintWriter pw, final RuntimeDTO dto) {
    if (dto.failedServletDTOs.length == 0) {
        return;
    }
    pw.print("<p class=\"statline ui-state-highlight\">${Failed Servlet Services}</p>");
    pw.println("<table class=\"nicetable\">");
    pw.println("<thead><tr>");
    pw.println("<th class=\"header\">${Path}</th>");
    pw.println("<th class=\"header\">${Name}</th>");
    pw.println("<th class=\"header\">${Info}</th>");
    pw.println("</tr></thead>");
    boolean odd = true;
    for (final FailedServletDTO servlet : dto.failedServletDTOs) {
        final StringBuilder sb = new StringBuilder();
        sb.append("${reason} : ").append(getErrorText(servlet.failureReason)).append("\n");
        final ServiceReference<?> ref = this.getServiceReference(servlet.serviceId);
        sb.append("${service.id} : ").append(String.valueOf(servlet.serviceId)).append("\n");
        appendServiceRanking(sb, ref);
        sb.append("${async} : ").append(String.valueOf(servlet.asyncSupported)).append("\n");
        if (ref != null) {
            sb.append("${bundle} : ");
            sb.append("${#link:");
            sb.append(ref.getBundle().getBundleId());
            sb.append("}");
            sb.append(ref.getBundle().getSymbolicName());
            sb.append("${link#}\n");
        }
        final StringBuilder psb = new StringBuilder();
        for (final String p : servlet.patterns) {
            psb.append(p).append('\n');
        }
        odd = printRow(pw, odd, psb.toString(), servlet.name, sb.toString());
    }
    pw.println("</table>");
}
Also used : FailedServletDTO(org.osgi.service.http.runtime.dto.FailedServletDTO)

Aggregations

FailedServletDTO (org.osgi.service.http.runtime.dto.FailedServletDTO)9 FailedResourceDTO (org.osgi.service.http.runtime.dto.FailedResourceDTO)4 FailedErrorPageDTO (org.osgi.service.http.runtime.dto.FailedErrorPageDTO)3 FailedFilterDTO (org.osgi.service.http.runtime.dto.FailedFilterDTO)3 FailedListenerDTO (org.osgi.service.http.runtime.dto.FailedListenerDTO)3 FailedServletContextDTO (org.osgi.service.http.runtime.dto.FailedServletContextDTO)3 RuntimeDTO (org.osgi.service.http.runtime.dto.RuntimeDTO)3 ServletContextDTO (org.osgi.service.http.runtime.dto.ServletContextDTO)3 ServletDTO (org.osgi.service.http.runtime.dto.ServletDTO)3 Map (java.util.Map)2 Servlet (javax.servlet.Servlet)2 ServletInfo (org.apache.felix.http.base.internal.runtime.ServletInfo)2 Test (org.junit.Test)2 FailedPreprocessorDTO (org.osgi.service.http.runtime.dto.FailedPreprocessorDTO)2 ResourceDTO (org.osgi.service.http.runtime.dto.ResourceDTO)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1