Search in sources :

Example 1 with WebEvent

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

the class WebContainerServiceImpl method stop.

public void stop(List<Long> bundleIds) throws Exception {
    if (bundleIds != null && !bundleIds.isEmpty()) {
        for (long bundleId : bundleIds) {
            if (webEventHandler.getBundleEvents().containsKey(bundleId)) {
                WebEvent webEvent = webEventHandler.getBundleEvents().get(bundleId);
                Bundle bundle = webEvent.getBundle();
                if (bundle != null) {
                    // deploy
                    warManager.stop(bundleId);
                } else {
                    System.out.println("Bundle ID " + bundleId + " is invalid");
                    LOGGER.warn("Bundle ID {} is invalid", bundleId);
                }
            }
        }
    }
}
Also used : WebBundle(org.apache.karaf.web.WebBundle) Bundle(org.osgi.framework.Bundle) WebEvent(org.ops4j.pax.web.service.spi.WebEvent)

Example 2 with WebEvent

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

the class WebContainerServiceImpl method list.

public List<WebBundle> list() throws Exception {
    Bundle[] bundles = bundleContext.getBundles();
    Map<Long, WebEvent> bundleEvents = webEventHandler.getBundleEvents();
    List<WebBundle> webBundles = new ArrayList<>();
    if (bundles != null) {
        for (Bundle bundle : bundles) {
            // first check if the bundle is a web bundle
            String contextPath = bundle.getHeaders().get("Web-ContextPath");
            if (contextPath == null) {
                // this one used by pax-web but is deprecated
                contextPath = bundle.getHeaders().get("Webapp-Context");
            }
            if (contextPath == null) {
                // the bundle is not a web bundle
                continue;
            }
            WebBundle webBundle = new WebBundle();
            contextPath = contextPath.trim();
            // get the bundle name
            String name = bundle.getHeaders().get(Constants.BUNDLE_NAME);
            // if there is no name, then default to symbolic name
            name = (name == null) ? bundle.getSymbolicName() : name;
            // if there is no symbolic name, resort to location
            name = (name == null) ? bundle.getLocation() : name;
            // get the bundle version
            String version = bundle.getHeaders().get(Constants.BUNDLE_VERSION);
            name = ((version != null)) ? name + " (" + version + ")" : name;
            long bundleId = bundle.getBundleId();
            int level = bundle.adapt(BundleStartLevel.class).getStartLevel();
            if (!contextPath.startsWith("/")) {
                contextPath = "/" + contextPath;
            }
            webBundle.setBundleId(bundleId);
            webBundle.setName(name);
            webBundle.setContextPath(contextPath);
            webBundle.setLevel(level);
            webBundle.setState(getStateString(bundle));
            webBundle.setWebState(state(bundle.getBundleId()));
            webBundles.add(webBundle);
        }
    }
    return webBundles;
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) WebBundle(org.apache.karaf.web.WebBundle) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) WebBundle(org.apache.karaf.web.WebBundle) WebEvent(org.ops4j.pax.web.service.spi.WebEvent)

Example 3 with WebEvent

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

the class WebContainerServiceImpl method getWebContextPath.

@Override
public String getWebContextPath(Long id) {
    Map<Long, WebEvent> bundleEvents = webEventHandler.getBundleEvents();
    WebEvent webEvent = bundleEvents.get(id);
    return webEvent.getContextPath();
}
Also used : WebEvent(org.ops4j.pax.web.service.spi.WebEvent)

Example 4 with WebEvent

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

the class WebContainerServiceImpl method state.

public String state(long bundleId) {
    Map<Long, WebEvent> bundleEvents = webEventHandler.getBundleEvents();
    String topic = "Unknown    ";
    if (bundleEvents.containsKey(bundleId)) {
        WebEvent webEvent = bundleEvents.get(bundleId);
        switch(webEvent.getType()) {
            case WebEvent.DEPLOYING:
                topic = "Deploying  ";
                break;
            case WebEvent.DEPLOYED:
                topic = "Deployed   ";
                break;
            case WebEvent.UNDEPLOYING:
                topic = "Undeploying";
                break;
            case WebEvent.UNDEPLOYED:
                topic = "Undeployed ";
                break;
            case WebEvent.FAILED:
                topic = "Failed     ";
                break;
            case WebEvent.WAITING:
                topic = "Waiting    ";
                break;
            default:
                topic = "Failed     ";
        }
    }
    while (topic.length() < 11) {
        topic += " ";
    }
    return topic;
}
Also used : WebEvent(org.ops4j.pax.web.service.spi.WebEvent)

Example 5 with WebEvent

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

the class HttpPlugin method getWebDetails.

protected List<WebDetail> getWebDetails() {
    Map<Long, WebEvent> bundleEvents = webEventHandler.getBundleEvents();
    List<WebDetail> result = new ArrayList<>();
    for (WebEvent event : bundleEvents.values()) {
        WebDetail webDetail = new WebDetail();
        webDetail.setBundleId(event.getBundle().getBundleId());
        webDetail.setContextPath(event.getContextPath().trim().concat("/"));
        int state = bundleContext.getBundle(event.getBundle().getBundleId()).getState();
        String stateStr;
        if (state == Bundle.ACTIVE) {
            stateStr = "Active";
        } else if (state == Bundle.INSTALLED) {
            stateStr = "Installed";
        } else if (state == Bundle.RESOLVED) {
            stateStr = "Resolved";
        } else if (state == Bundle.STARTING) {
            stateStr = "Starting";
        } else if (state == Bundle.STOPPING) {
            stateStr = "Stopping";
        } else {
            stateStr = "Unknown";
        }
        webDetail.setState(stateStr);
        webDetail.setWebState(getStateString(event.getType()));
        result.add(webDetail);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) WebEvent(org.ops4j.pax.web.service.spi.WebEvent)

Aggregations

WebEvent (org.ops4j.pax.web.service.spi.WebEvent)7 WebBundle (org.apache.karaf.web.WebBundle)3 Bundle (org.osgi.framework.Bundle)3 ArrayList (java.util.ArrayList)2 JsonHelper.jsonEncodeString (io.fabric8.internal.JsonHelper.jsonEncodeString)1 ServletEvent (org.ops4j.pax.web.service.spi.ServletEvent)1 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)1