Search in sources :

Example 1 with ServletEvent

use of org.ops4j.pax.web.service.spi.ServletEvent in project karaf by apache.

the class ServletServiceImpl method getServlets.

@Override
public List<ServletInfo> getServlets() {
    List<ServletInfo> servletInfos = new ArrayList<>();
    Collection<ServletEvent> events = servletEventHandler.getServletEvents();
    for (ServletEvent event : events) {
        Servlet servlet = event.getServlet();
        String servletClassName = " ";
        if (servlet != null) {
            servletClassName = servlet.getClass().getName();
            servletClassName = servletClassName.substring(servletClassName.lastIndexOf(".") + 1, servletClassName.length());
        }
        String servletName = event.getServletName() != null ? event.getServletName() : " ";
        if (servletName.contains(".")) {
            servletName = servletName.substring(servletName.lastIndexOf(".") + 1, servletName.length());
        }
        String alias = event.getAlias() != null ? event.getAlias() : " ";
        String[] urls = event.getUrlParameter() != null ? event.getUrlParameter() : new String[] { "" };
        ServletInfo info = new ServletInfo();
        info.setBundleId(event.getBundle().getBundleId());
        info.setName(servletName);
        info.setClassName(servletClassName);
        info.setState(event.getType());
        info.setAlias(alias);
        info.setUrls(urls);
        servletInfos.add(info);
    }
    return servletInfos;
}
Also used : ServletInfo(org.apache.karaf.http.core.ServletInfo) ArrayList(java.util.ArrayList) ServletEvent(org.ops4j.pax.web.service.spi.ServletEvent) Servlet(javax.servlet.Servlet)

Example 2 with ServletEvent

use of org.ops4j.pax.web.service.spi.ServletEvent in project karaf by apache.

the class HttpPlugin method getServletDetails.

protected List<ServletDetails> getServletDetails() {
    Collection<ServletEvent> events = servletEventHandler.getServletEvents();
    List<ServletDetails> result = new ArrayList<>(events.size());
    for (ServletEvent event : events) {
        Servlet servlet = event.getServlet();
        String servletClassName = " ";
        if (servlet != null) {
            servletClassName = servlet.getClass().getName();
            servletClassName = servletClassName.substring(servletClassName.lastIndexOf(".") + 1, servletClassName.length());
        }
        String servletName = event.getServletName() != null ? event.getServletName() : " ";
        if (servletName.contains(".")) {
            servletName = servletName.substring(servletName.lastIndexOf(".") + 1, servletName.length());
        }
        String alias = event.getAlias() != null ? event.getAlias() : " ";
        String[] urls = event.getUrlParameter() != null ? event.getUrlParameter() : new String[] { "" };
        ServletDetails details = new ServletDetails();
        details.setId(event.getBundle().getBundleId());
        details.setAlias(alias);
        details.setServlet(servletClassName);
        details.setServletName(servletName);
        details.setState(getStateString(event.getType()));
        details.setUrls(urls);
        result.add(details);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ServletEvent(org.ops4j.pax.web.service.spi.ServletEvent) Servlet(javax.servlet.Servlet)

Aggregations

ArrayList (java.util.ArrayList)2 Servlet (javax.servlet.Servlet)2 ServletEvent (org.ops4j.pax.web.service.spi.ServletEvent)2 ServletInfo (org.apache.karaf.http.core.ServletInfo)1