Search in sources :

Example 1 with FilterDTO

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

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

the class HttpServicePlugin method printFilterDetails.

private void printFilterDetails(final PrintWriter pw, final ServletContextDTO dto) {
    if (dto.filterDTOs.length == 0) {
        return;
    }
    pw.print("<p class=\"statline ui-state-highlight\">${Servlet Context} '");
    pw.print(escapeXml(dto.name));
    pw.println("' ${Registered Filter Services}</p>");
    pw.println("<table class=\"nicetable\">");
    pw.println("<thead><tr>");
    pw.println("<th class=\"header\">${Pattern}</th>");
    pw.println("<th class=\"header\">${Filter}</th>");
    pw.println("<th class=\"header\">${Info}</th>");
    pw.println("</tr></thead>");
    boolean odd = true;
    for (final FilterDTO filter : dto.filterDTOs) {
        final ServiceReference<?> ref = this.getServiceReference(filter.serviceId);
        final StringBuilder sb = new StringBuilder();
        sb.append("${service.id} : ").append(String.valueOf(filter.serviceId)).append("\n");
        appendServiceRanking(sb, ref);
        sb.append("${async} : ").append(String.valueOf(filter.asyncSupported)).append("\n");
        sb.append("${dispatcher} : ").append(getValueAsString(filter.dispatcher)).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 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);
        final StringBuilder psb = new StringBuilder();
        for (final String p : patterns) {
            psb.append(p).append('\n');
        }
        odd = printRow(pw, odd, psb.toString(), filter.name, sb.toString());
    }
    pw.println("</table>");
}
Also used : ArrayList(java.util.ArrayList) FailedFilterDTO(org.osgi.service.http.runtime.dto.FailedFilterDTO) FilterDTO(org.osgi.service.http.runtime.dto.FilterDTO)

Example 3 with FilterDTO

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

the class HttpServicePlugin method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    final String test = request.getParameter(ATTR_TEST);
    String msg = null;
    if (test != null && test.length() > 0) {
        final RequestInfoDTO dto = this.runtime.calculateRequestInfoDTO(test);
        final StringBuilder sb = new StringBuilder();
        if (dto.servletDTO != null) {
            sb.append("Servlet: ");
            sb.append(getValueAsString(dto.servletDTO.patterns));
            sb.append(" (");
            sb.append("service.id=");
            sb.append(String.valueOf(dto.servletDTO.serviceId));
            sb.append("), Filters: [");
            boolean first = true;
            for (final FilterDTO f : dto.filterDTOs) {
                if (first) {
                    first = false;
                } else {
                    sb.append(", ");
                }
                sb.append(f.serviceId);
            }
            sb.append("]");
        } else if (dto.resourceDTO != null) {
            sb.append("Resource: ");
            sb.append(getValueAsString(dto.resourceDTO.patterns));
            sb.append(" (");
            sb.append("service.id=");
            sb.append(String.valueOf(dto.resourceDTO.serviceId));
            sb.append("), Filters: [");
            boolean first = true;
            for (final FilterDTO f : dto.filterDTOs) {
                if (first) {
                    first = false;
                } else {
                    sb.append(", ");
                }
                sb.append(f.serviceId);
            }
            sb.append("]");
        } else {
            sb.append("<404>");
        }
        msg = sb.toString();
    }
    // finally redirect
    final String path = request.getContextPath() + request.getServletPath() + request.getPathInfo();
    final String redirectTo;
    if (msg == null) {
        redirectTo = path;
    } else {
        redirectTo = path + '?' + ATTR_MSG + '=' + encodeParam(msg) + '&' + ATTR_TEST + '=' + encodeParam(test);
    }
    response.sendRedirect(redirectTo);
}
Also used : RequestInfoDTO(org.osgi.service.http.runtime.dto.RequestInfoDTO) FailedFilterDTO(org.osgi.service.http.runtime.dto.FailedFilterDTO) FilterDTO(org.osgi.service.http.runtime.dto.FilterDTO)

Example 4 with FilterDTO

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

the class FilterDTOBuilder method build.

/**
 * Build a filter DTO from a filter handler
 * @param handler The filter handler
 * @return A filter DTO
 */
@Nonnull
public static FilterDTO build(@Nonnull final FilterHandler handler, final int reason) {
    final FilterDTO filterDTO = build(handler.getFilterInfo(), reason);
    filterDTO.name = handler.getName();
    filterDTO.servletContextId = handler.getContextServiceId();
    return filterDTO;
}
Also used : FilterDTO(org.osgi.service.http.runtime.dto.FilterDTO) FailedFilterDTO(org.osgi.service.http.runtime.dto.FailedFilterDTO) Nonnull(javax.annotation.Nonnull)

Example 5 with FilterDTO

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

the class FilterDTOBuilder method build.

/**
 * Build a filter DTO from a filter info
 * @param info The filter info
 * @return A filter DTO
 */
@Nonnull
public static FilterDTO build(@Nonnull final FilterInfo info, final int reason) {
    final FilterDTO filterDTO = (reason != -1 ? new FailedFilterDTO() : new FilterDTO());
    filterDTO.asyncSupported = info.isAsyncSupported();
    filterDTO.dispatcher = getNames(info.getDispatcher());
    filterDTO.initParams = info.getInitParameters();
    filterDTO.name = info.getName();
    filterDTO.patterns = BuilderConstants.copyWithDefault(info.getPatterns(), BuilderConstants.EMPTY_STRING_ARRAY);
    filterDTO.regexs = BuilderConstants.copyWithDefault(info.getRegexs(), BuilderConstants.EMPTY_STRING_ARRAY);
    filterDTO.serviceId = info.getServiceId();
    filterDTO.servletNames = BuilderConstants.copyWithDefault(info.getServletNames(), BuilderConstants.EMPTY_STRING_ARRAY);
    if (reason != -1) {
        ((FailedFilterDTO) filterDTO).failureReason = reason;
    }
    return filterDTO;
}
Also used : FailedFilterDTO(org.osgi.service.http.runtime.dto.FailedFilterDTO) FilterDTO(org.osgi.service.http.runtime.dto.FilterDTO) FailedFilterDTO(org.osgi.service.http.runtime.dto.FailedFilterDTO) Nonnull(javax.annotation.Nonnull)

Aggregations

FailedFilterDTO (org.osgi.service.http.runtime.dto.FailedFilterDTO)5 FilterDTO (org.osgi.service.http.runtime.dto.FilterDTO)5 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 Map (java.util.Map)1 ErrorPageDTO (org.osgi.service.http.runtime.dto.ErrorPageDTO)1 FailedErrorPageDTO (org.osgi.service.http.runtime.dto.FailedErrorPageDTO)1 FailedListenerDTO (org.osgi.service.http.runtime.dto.FailedListenerDTO)1 FailedResourceDTO (org.osgi.service.http.runtime.dto.FailedResourceDTO)1 FailedServletContextDTO (org.osgi.service.http.runtime.dto.FailedServletContextDTO)1 FailedServletDTO (org.osgi.service.http.runtime.dto.FailedServletDTO)1 ListenerDTO (org.osgi.service.http.runtime.dto.ListenerDTO)1 RequestInfoDTO (org.osgi.service.http.runtime.dto.RequestInfoDTO)1 ResourceDTO (org.osgi.service.http.runtime.dto.ResourceDTO)1 RuntimeDTO (org.osgi.service.http.runtime.dto.RuntimeDTO)1 ServletContextDTO (org.osgi.service.http.runtime.dto.ServletContextDTO)1 ServletDTO (org.osgi.service.http.runtime.dto.ServletDTO)1