use of org.osgi.service.http.runtime.dto.ServletDTO 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();
}
use of org.osgi.service.http.runtime.dto.ServletDTO in project felix by apache.
the class HttpServicePlugin method printServletDetails.
private void printServletDetails(final PrintWriter pw, final ServletContextDTO dto) {
if (dto.servletDTOs.length == 0) {
return;
}
pw.print("<p class=\"statline ui-state-highlight\">${Servlet Context} '");
pw.print(escapeXml(dto.name));
pw.println("' ${Registered 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 ServletDTO servlet : dto.servletDTOs) {
final StringBuilder sb = new StringBuilder();
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>");
}
use of org.osgi.service.http.runtime.dto.ServletDTO in project felix by apache.
the class ServletRegistry method getRuntimeInfo.
public void getRuntimeInfo(final ServletContextDTO servletContextDTO, final Collection<FailedServletDTO> allFailedServletDTOs, final Collection<FailedResourceDTO> allFailedResourceDTOs) {
final Map<Long, ServletDTO> servletDTOs = new HashMap<Long, ServletDTO>();
final Map<Long, ResourceDTO> resourceDTOs = new HashMap<Long, ResourceDTO>();
final Map<Long, FailedServletDTO> failedServletDTOs = new HashMap<Long, FailedServletDTO>();
final Map<Long, FailedResourceDTO> failedResourceDTOs = new HashMap<Long, FailedResourceDTO>();
for (final Map.Entry<ServletInfo, RegistrationStatus> entry : mapping.entrySet()) {
final long serviceId = entry.getKey().getServiceId();
for (final Map.Entry<Integer, String[]> map : entry.getValue().statusToPath.entrySet()) {
if (entry.getKey().isResource()) {
final ResourceDTO state = ResourceDTOBuilder.build(entry.getValue().handler, map.getKey());
if (map.getValue().length == 1 && NAMED_SERVLET_PATTERN == map.getValue()[0]) {
state.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
} else {
state.patterns = Arrays.copyOf(map.getValue(), map.getValue().length);
}
if (map.getKey() == -1) {
resourceDTOs.put(serviceId, state);
} else {
failedResourceDTOs.put(serviceId, (FailedResourceDTO) state);
}
} else {
final ServletDTO state = ServletDTOBuilder.build(entry.getValue().handler, map.getKey());
if (map.getValue().length == 1 && NAMED_SERVLET_PATTERN == map.getValue()[0]) {
state.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
} else {
state.patterns = Arrays.copyOf(map.getValue(), map.getValue().length);
}
if (map.getKey() == -1) {
servletDTOs.put(serviceId, state);
} else {
failedServletDTOs.put(serviceId, (FailedServletDTO) state);
}
}
}
}
final Collection<ServletDTO> servletDTOsArray = servletDTOs.values();
if (!servletDTOsArray.isEmpty()) {
servletContextDTO.servletDTOs = servletDTOsArray.toArray(new ServletDTO[servletDTOsArray.size()]);
}
final Collection<ResourceDTO> resourceDTOsArray = resourceDTOs.values();
if (!resourceDTOsArray.isEmpty()) {
servletContextDTO.resourceDTOs = resourceDTOsArray.toArray(new ResourceDTO[resourceDTOsArray.size()]);
}
allFailedResourceDTOs.addAll(failedResourceDTOs.values());
allFailedServletDTOs.addAll(failedServletDTOs.values());
}
use of org.osgi.service.http.runtime.dto.ServletDTO in project felix by apache.
the class ServletDTOBuilder method build.
/**
* Build a servlet DTO from a servlet info
* @param info The servlet info
* @return A servlet DTO
*/
public static ServletDTO build(final ServletInfo info, final int reason) {
final ServletDTO dto = (reason != -1 ? new FailedServletDTO() : new ServletDTO());
BaseServletDTOBuilder.fill(dto, info);
if (reason != -1) {
((FailedServletDTO) dto).failureReason = reason;
}
dto.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
final MultipartConfig config = info.getMultipartConfig();
dto.multipartEnabled = config != null;
if (config != null) {
dto.multipartFileSizeThreshold = config.multipartThreshold;
dto.multipartLocation = config.multipartLocation;
dto.multipartMaxFileSize = config.multipartMaxFileSize;
dto.multipartMaxRequestSize = config.multipartMaxRequestSize;
}
return dto;
}
use of org.osgi.service.http.runtime.dto.ServletDTO in project felix by apache.
the class HttpServiceRuntimeTest method mulitpleServletsWithSamePatternHttpServiceRegistrationWins.
// As specified in OSGi Compendium Release 6, Chapter 140.4
@Test
public void mulitpleServletsWithSamePatternHttpServiceRegistrationWins() throws Exception {
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);
CountDownLatch initLatch = new CountDownLatch(1);
CountDownLatch destroyLatch = new CountDownLatch(1);
TestServlet testServlet = new TestServlet(initLatch, destroyLatch);
register("/pathcollision", testServlet);
RuntimeDTO runtimeWithShadowedServlet = serviceRuntime.getRuntimeDTO();
awaitServiceRegistration(initLatch);
defaultContext = assertDefaultContext(runtimeWithShadowedServlet);
ServletContextDTO httpServiceContext = runtimeWithShadowedServlet.servletContextDTOs[0];
assertEquals(HTTP_CONTEXT_NAME, httpServiceContext.name);
assertEquals(1, httpServiceContext.servletDTOs.length);
assertArrayEquals(new String[] { "/pathcollision" }, httpServiceContext.servletDTOs[0].patterns);
assertEquals(1, defaultContext.servletDTOs.length);
ServletDTO servletDTO = defaultContext.servletDTOs[0];
assertEquals("servlet 1", servletDTO.name);
// check request info DTO to see which servlet responds
final RequestInfoDTO infoDTO = serviceRuntime.calculateRequestInfoDTO("/pathcollision");
assertEquals(httpServiceContext.serviceId, infoDTO.servletDTO.servletContextId);
unregister("/pathcollision");
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);
}
Aggregations