Search in sources :

Example 1 with ServletContextDTO

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

the class HttpServiceRuntimeTest method serviceWithoutRequiredPropertiesIsIgnored.

// As specified in OSGi Compendium Release 6, Chapter 140.9
@Test
public void serviceWithoutRequiredPropertiesIsIgnored() 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(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 2 with ServletContextDTO

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

the class HttpServicePlugin method doGet.

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
    final RuntimeDTO dto = this.runtime.getRuntimeDTO();
    final PrintWriter pw = resp.getWriter();
    String path = req.getContextPath() + req.getServletPath();
    if (req.getPathInfo() != null) {
        path = path + req.getPathInfo();
    }
    printForm(pw, req.getParameter(ATTR_TEST), req.getParameter(ATTR_MSG), path);
    printRuntimeDetails(pw, dto.serviceDTO);
    for (final ServletContextDTO ctxDto : dto.servletContextDTOs) {
        printContextDetails(pw, ctxDto);
    }
    for (final FailedServletContextDTO ctxDto : dto.failedServletContextDTOs) {
        printFailedContextDetails(pw, ctxDto);
    }
    printFailedServletDetails(pw, dto);
    printFailedFilterDetails(pw, dto);
    printFailedResourceDetails(pw, dto);
    printFailedErrorPageDetails(pw, dto);
    printFailedListenerDetails(pw, dto);
    pw.println("<br/>");
}
Also used : ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) FailedServletContextDTO(org.osgi.service.http.runtime.dto.FailedServletContextDTO) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) FailedServletContextDTO(org.osgi.service.http.runtime.dto.FailedServletContextDTO) PrintWriter(java.io.PrintWriter)

Example 3 with ServletContextDTO

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

the class HttpServicePlugin method printConfiguration.

/**
 * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
 */
public void printConfiguration(final PrintWriter pw) {
    final RuntimeDTO dto = this.runtime.getRuntimeDTO();
    pw.println("HTTP Service Details");
    pw.println("====================");
    pw.println();
    pw.println("Runtime Properties");
    pw.println("------------------");
    for (final Map.Entry<String, Object> prop : dto.serviceDTO.properties.entrySet()) {
        pw.print(prop.getKey());
        pw.print(" : ");
        pw.println(getValueAsString(prop.getValue()));
    }
    pw.println();
    for (final ServletContextDTO ctxDto : dto.servletContextDTOs) {
        pw.print("Servlet Context ");
        pw.println(ctxDto.name);
        pw.println("-----------------------------------------------");
        pw.print("Path : ");
        pw.println(getContextPath(ctxDto.contextPath));
        printServiceIdAndRanking(pw, this.getServiceReference(ctxDto.serviceId), ctxDto.serviceId);
        pw.println();
        if (ctxDto.servletDTOs.length > 0) {
            pw.println("Servlets");
            for (final ServletDTO servlet : ctxDto.servletDTOs) {
                pw.print("Patterns : ");
                pw.println(getValueAsString(servlet.patterns));
                pw.print("Name : ");
                pw.println(servlet.name);
                final ServiceReference<?> ref = this.getServiceReference(servlet.serviceId);
                printServiceIdAndRanking(pw, ref, servlet.serviceId);
                pw.print("async : ");
                pw.println(String.valueOf(servlet.asyncSupported));
                if (ref != null) {
                    pw.print("Bundle : ");
                    pw.print(ref.getBundle().getSymbolicName());
                    pw.print(" <");
                    pw.print(String.valueOf(ref.getBundle().getBundleId()));
                    pw.println(">");
                }
                pw.println();
            }
            pw.println();
        }
        if (ctxDto.filterDTOs.length > 0) {
            pw.println("Filters");
            for (final FilterDTO filter : ctxDto.filterDTOs) {
                final List<String> patterns = new ArrayList<>();
                patterns.addAll(Arrays.asList(filter.patterns));
                patterns.addAll(Arrays.asList(filter.regexs));
                for (final String name : filter.servletNames) {
                    patterns.add("Servlet : " + name);
                }
                Collections.sort(patterns);
                pw.print("Patterns : ");
                pw.println(patterns);
                pw.print("Name : ");
                pw.println(filter.name);
                final ServiceReference<?> ref = this.getServiceReference(filter.serviceId);
                printServiceIdAndRanking(pw, ref, filter.serviceId);
                pw.print("async : ");
                pw.println(String.valueOf(filter.asyncSupported));
                pw.print("dispatcher : ");
                pw.println(getValueAsString(filter.dispatcher));
                if (ref != null) {
                    pw.print("Bundle : ");
                    pw.print(ref.getBundle().getSymbolicName());
                    pw.print(" <");
                    pw.print(String.valueOf(ref.getBundle().getBundleId()));
                    pw.println(">");
                }
                pw.println();
            }
            pw.println();
        }
        if (ctxDto.resourceDTOs.length > 0) {
            pw.println("Resources");
            for (final ResourceDTO rsrc : ctxDto.resourceDTOs) {
                pw.print("Patterns : ");
                pw.println(getValueAsString(rsrc.patterns));
                pw.print("Prefix : ");
                pw.println(rsrc.prefix);
                final ServiceReference<?> ref = this.getServiceReference(rsrc.serviceId);
                printServiceIdAndRanking(pw, ref, rsrc.serviceId);
                if (ref != null) {
                    pw.print("Bundle : ");
                    pw.print(ref.getBundle().getSymbolicName());
                    pw.print(" <");
                    pw.print(String.valueOf(ref.getBundle().getBundleId()));
                    pw.println(">");
                }
                pw.println();
            }
            pw.println();
        }
        if (ctxDto.errorPageDTOs.length > 0) {
            pw.println("Error Pages");
            for (final ErrorPageDTO ep : ctxDto.errorPageDTOs) {
                final List<String> patterns = new ArrayList<>();
                for (final long p : ep.errorCodes) {
                    patterns.add(String.valueOf(p));
                }
                for (final String p : ep.exceptions) {
                    patterns.add(p);
                }
                pw.print("Patterns : ");
                pw.println(patterns);
                pw.print("Name : ");
                pw.println(ep.name);
                final ServiceReference<?> ref = this.getServiceReference(ep.serviceId);
                printServiceIdAndRanking(pw, ref, ep.serviceId);
                pw.print("async : ");
                pw.println(String.valueOf(ep.asyncSupported));
                if (ref != null) {
                    pw.print("Bundle : ");
                    pw.print(ref.getBundle().getSymbolicName());
                    pw.print(" <");
                    pw.print(String.valueOf(ref.getBundle().getBundleId()));
                    pw.println(">");
                }
                pw.println();
            }
            pw.println();
        }
        if (ctxDto.listenerDTOs.length > 0) {
            pw.println("Listeners");
            for (final ListenerDTO ep : ctxDto.listenerDTOs) {
                pw.print("Types : ");
                pw.println(getValueAsString(ep.types));
                final ServiceReference<?> ref = this.getServiceReference(ep.serviceId);
                printServiceIdAndRanking(pw, ref, ep.serviceId);
                if (ref != null) {
                    pw.print("Bundle : ");
                    pw.print(ref.getBundle().getSymbolicName());
                    pw.print(" <");
                    pw.print(String.valueOf(ref.getBundle().getBundleId()));
                    pw.println(">");
                }
                pw.println();
            }
            pw.println();
        }
        pw.println();
    }
    if (dto.failedServletContextDTOs.length > 0) {
        for (final FailedServletContextDTO ctxDto : dto.failedServletContextDTOs) {
            pw.print("Failed Servlet Context ");
            pw.println(ctxDto.name);
            pw.println("-----------------------------------------------");
            pw.print("Reason : ");
            pw.println(getErrorText(ctxDto.failureReason));
            pw.print("Path : ");
            pw.println(getContextPath(ctxDto.contextPath));
            printServiceIdAndRanking(pw, this.getServiceReference(ctxDto.serviceId), ctxDto.serviceId);
            pw.println();
        }
    }
    if (dto.failedServletDTOs.length > 0) {
        pw.println("Failed Servlets");
        for (final FailedServletDTO servlet : dto.failedServletDTOs) {
            pw.print("Patterns : ");
            pw.println(getValueAsString(servlet.patterns));
            pw.print("Reason : ");
            pw.println(getErrorText(servlet.failureReason));
            pw.print("Name : ");
            pw.println(servlet.name);
            final ServiceReference<?> ref = this.getServiceReference(servlet.serviceId);
            printServiceIdAndRanking(pw, ref, servlet.serviceId);
            pw.print("async : ");
            pw.println(String.valueOf(servlet.asyncSupported));
            if (ref != null) {
                pw.print("Bundle : ");
                pw.print(ref.getBundle().getSymbolicName());
                pw.print(" <");
                pw.print(String.valueOf(ref.getBundle().getBundleId()));
                pw.println(">");
            }
            pw.println();
        }
        pw.println();
    }
    if (dto.failedFilterDTOs.length > 0) {
        pw.println("Failed Filters");
        for (final FailedFilterDTO filter : dto.failedFilterDTOs) {
            final List<String> patterns = new ArrayList<>();
            patterns.addAll(Arrays.asList(filter.patterns));
            patterns.addAll(Arrays.asList(filter.regexs));
            for (final String name : filter.servletNames) {
                patterns.add("Servlet : " + name);
            }
            Collections.sort(patterns);
            pw.print("Patterns : ");
            pw.println(patterns);
            pw.print("Reason : ");
            pw.println(getErrorText(filter.failureReason));
            pw.print("Name : ");
            pw.println(filter.name);
            final ServiceReference<?> ref = this.getServiceReference(filter.serviceId);
            printServiceIdAndRanking(pw, ref, filter.serviceId);
            pw.print("async : ");
            pw.println(String.valueOf(filter.asyncSupported));
            pw.print("dispatcher : ");
            pw.println(getValueAsString(filter.dispatcher));
            if (ref != null) {
                pw.print("Bundle : ");
                pw.print(ref.getBundle().getSymbolicName());
                pw.print(" <");
                pw.print(String.valueOf(ref.getBundle().getBundleId()));
                pw.println(">");
            }
            pw.println();
        }
        pw.println();
    }
    if (dto.failedResourceDTOs.length > 0) {
        pw.println("Failed Resources");
        for (final FailedResourceDTO rsrc : dto.failedResourceDTOs) {
            pw.print("Patterns : ");
            pw.println(getValueAsString(rsrc.patterns));
            pw.print("Reason : ");
            pw.println(getErrorText(rsrc.failureReason));
            pw.print("Prefix : ");
            pw.println(rsrc.prefix);
            final ServiceReference<?> ref = this.getServiceReference(rsrc.serviceId);
            printServiceIdAndRanking(pw, ref, rsrc.serviceId);
            if (ref != null) {
                pw.print("Bundle : ");
                pw.print(ref.getBundle().getSymbolicName());
                pw.print(" <");
                pw.print(String.valueOf(ref.getBundle().getBundleId()));
                pw.println(">");
            }
            pw.println();
        }
        pw.println();
    }
    if (dto.failedErrorPageDTOs.length > 0) {
        pw.println("Failed Error Pages");
        for (final FailedErrorPageDTO ep : dto.failedErrorPageDTOs) {
            final List<String> patterns = new ArrayList<>();
            for (final long p : ep.errorCodes) {
                patterns.add(String.valueOf(p));
            }
            for (final String p : ep.exceptions) {
                patterns.add(p);
            }
            pw.print("Patterns : ");
            pw.println(patterns);
            pw.print("Reason : ");
            pw.println(getErrorText(ep.failureReason));
            pw.print("Name : ");
            pw.println(ep.name);
            final ServiceReference<?> ref = this.getServiceReference(ep.serviceId);
            printServiceIdAndRanking(pw, ref, ep.serviceId);
            pw.print("async : ");
            pw.println(String.valueOf(ep.asyncSupported));
            if (ref != null) {
                pw.print("Bundle : ");
                pw.print(ref.getBundle().getSymbolicName());
                pw.print(" <");
                pw.print(String.valueOf(ref.getBundle().getBundleId()));
                pw.println(">");
            }
            pw.println();
        }
        pw.println();
    }
    if (dto.failedListenerDTOs.length > 0) {
        pw.println("Listeners");
        for (final FailedListenerDTO ep : dto.failedListenerDTOs) {
            pw.print("Types : ");
            pw.println(getValueAsString(ep.types));
            pw.print("Reason : ");
            pw.println(getErrorText(ep.failureReason));
            final ServiceReference<?> ref = this.getServiceReference(ep.serviceId);
            printServiceIdAndRanking(pw, ref, ep.serviceId);
            if (ref != null) {
                pw.print("Bundle : ");
                pw.print(ref.getBundle().getSymbolicName());
                pw.print(" <");
                pw.print(String.valueOf(ref.getBundle().getBundleId()));
                pw.println(">");
            }
            pw.println();
        }
        pw.println();
    }
    pw.println();
}
Also used : FailedFilterDTO(org.osgi.service.http.runtime.dto.FailedFilterDTO) FailedServletDTO(org.osgi.service.http.runtime.dto.FailedServletDTO) FailedErrorPageDTO(org.osgi.service.http.runtime.dto.FailedErrorPageDTO) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) FailedServletContextDTO(org.osgi.service.http.runtime.dto.FailedServletContextDTO) ArrayList(java.util.ArrayList) FailedResourceDTO(org.osgi.service.http.runtime.dto.FailedResourceDTO) FailedFilterDTO(org.osgi.service.http.runtime.dto.FailedFilterDTO) FilterDTO(org.osgi.service.http.runtime.dto.FilterDTO) ResourceDTO(org.osgi.service.http.runtime.dto.ResourceDTO) FailedResourceDTO(org.osgi.service.http.runtime.dto.FailedResourceDTO) FailedListenerDTO(org.osgi.service.http.runtime.dto.FailedListenerDTO) ListenerDTO(org.osgi.service.http.runtime.dto.ListenerDTO) FailedListenerDTO(org.osgi.service.http.runtime.dto.FailedListenerDTO) ErrorPageDTO(org.osgi.service.http.runtime.dto.ErrorPageDTO) FailedErrorPageDTO(org.osgi.service.http.runtime.dto.FailedErrorPageDTO) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) FailedServletContextDTO(org.osgi.service.http.runtime.dto.FailedServletContextDTO) Map(java.util.Map) FailedServletDTO(org.osgi.service.http.runtime.dto.FailedServletDTO) ServletDTO(org.osgi.service.http.runtime.dto.ServletDTO)

Example 4 with ServletContextDTO

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

the class WhiteboardManager method getRuntimeInfo.

public RegistryRuntime getRuntimeInfo() {
    final FailedDTOHolder failedDTOHolder = new FailedDTOHolder();
    final Collection<ServletContextDTO> contextDTOs = new ArrayList<>();
    // get sort list of context handlers
    final List<WhiteboardContextHandler> contextHandlerList = new ArrayList<>();
    synchronized (this.contextMap) {
        for (final List<WhiteboardContextHandler> list : this.contextMap.values()) {
            if (!list.isEmpty()) {
                contextHandlerList.add(list.get(0));
            }
        }
        this.failureStateHandler.getRuntimeInfo(failedDTOHolder);
    }
    Collections.sort(contextHandlerList);
    for (final WhiteboardContextHandler handler : contextHandlerList) {
        final ServletContextDTO scDTO = ServletContextDTOBuilder.build(handler.getContextInfo(), handler.getSharedContext(), -1);
        if (registry.getRuntimeInfo(scDTO, failedDTOHolder)) {
            contextDTOs.add(scDTO);
        }
    }
    final List<PreprocessorDTO> preprocessorDTOs = new ArrayList<>();
    final List<PreprocessorHandler> localHandlers = this.preprocessorHandlers;
    for (final PreprocessorHandler handler : localHandlers) {
        preprocessorDTOs.add(PreprocessorDTOBuilder.build(handler.getPreprocessorInfo(), -1));
    }
    return new RegistryRuntime(failedDTOHolder, contextDTOs, preprocessorDTOs);
}
Also used : FailedDTOHolder(org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) PreprocessorDTO(org.osgi.service.http.runtime.dto.PreprocessorDTO) PreprocessorHandler(org.apache.felix.http.base.internal.handler.PreprocessorHandler) ArrayList(java.util.ArrayList) RegistryRuntime(org.apache.felix.http.base.internal.runtime.dto.RegistryRuntime)

Example 5 with ServletContextDTO

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

the class ErrorPageRegistryTest method testRangeRegistrationOverlay.

@Test
public void testRangeRegistrationOverlay() throws InvalidSyntaxException {
    final ErrorPageRegistry reg = new ErrorPageRegistry();
    final FailedDTOHolder holder = new FailedDTOHolder();
    final ServletContextDTO dto = new ServletContextDTO();
    final ServletHandler handler4 = createServletHandler(1L, 0, "4xx");
    final ServletHandler handler = createServletHandler(2L, 10, "404", "403");
    reg.addServlet(handler4);
    reg.addServlet(handler);
    // check DTO
    reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
    // a 4xx is only registered as failure DTO if overlayed by a 4xx!
    // -> no failure in this case
    assertEquals(0, holder.failedErrorPageDTOs.size());
    final Set<Long> codes4 = new HashSet<Long>();
    for (final long c : dto.errorPageDTOs[1].errorCodes) {
        assertTrue(c >= 400 && c < 500);
        codes4.add(c);
    }
    assertEquals(98, codes4.size());
    assertFalse(codes4.contains(404L));
    assertFalse(codes4.contains(403L));
    assertEquals(2, dto.errorPageDTOs[0].errorCodes.length);
    final Set<Long> codes = new HashSet<Long>();
    for (final long c : dto.errorPageDTOs[0].errorCodes) {
        assertTrue(c >= 403 && c < 405);
        codes.add(c);
    }
    assertEquals(2, codes.size());
}
Also used : ServletHandler(org.apache.felix.http.base.internal.handler.ServletHandler) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) FailedDTOHolder(org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ServletContextDTO (org.osgi.service.http.runtime.dto.ServletContextDTO)34 Test (org.junit.Test)29 RuntimeDTO (org.osgi.service.http.runtime.dto.RuntimeDTO)21 HttpServiceRuntime (org.osgi.service.http.runtime.HttpServiceRuntime)20 FailedDTOHolder (org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder)11 CountDownLatch (java.util.concurrent.CountDownLatch)8 Servlet (javax.servlet.Servlet)7 HttpServiceServletHandler (org.apache.felix.http.base.internal.handler.HttpServiceServletHandler)7 ServletHandler (org.apache.felix.http.base.internal.handler.ServletHandler)7 ServletConfig (javax.servlet.ServletConfig)5 HashSet (java.util.HashSet)4 FailedServletDTO (org.osgi.service.http.runtime.dto.FailedServletDTO)4 ArrayList (java.util.ArrayList)3 FailedServletContextDTO (org.osgi.service.http.runtime.dto.FailedServletContextDTO)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 NoSuchElementException (java.util.NoSuchElementException)2 ServletContextListener (javax.servlet.ServletContextListener)2 ServletException (javax.servlet.ServletException)2 ServletRequestListener (javax.servlet.ServletRequestListener)2