use of org.apache.karaf.web.WebBundle 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;
}
use of org.apache.karaf.web.WebBundle in project karaf by apache.
the class WebMBeanImpl method getWebBundles.
public TabularData getWebBundles() throws MBeanException {
try {
CompositeType webType = new CompositeType("Web Bundle", "An OSGi Web bundle", new String[] { "ID", "State", "Web-State", "Level", "Web-ContextPath", "Name" }, new String[] { "ID of the bundle", "OSGi state of the bundle", "Web state of the bundle", "Start level of the bundle", "Web context path", "Name of the bundle" }, new OpenType[] { SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING });
TabularType tableType = new TabularType("Web Bundles", "Table of web bundles", webType, new String[] { "ID" });
TabularData table = new TabularDataSupport(tableType);
for (WebBundle webBundle : webContainerService.list()) {
try {
CompositeData data = new CompositeDataSupport(webType, new String[] { "ID", "State", "Web-State", "Level", "Web-ContextPath", "Name" }, new Object[] { webBundle.getBundleId(), webBundle.getState(), webBundle.getWebState(), webBundle.getLevel(), webBundle.getContextPath(), webBundle.getName() });
table.put(data);
} catch (Exception e) {
e.printStackTrace();
}
}
return table;
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
use of org.apache.karaf.web.WebBundle in project karaf by apache.
the class List method execute.
@Override
public Object execute() throws Exception {
ShellTable table = new ShellTable();
table.column(new Col("ID"));
table.column(new Col("State"));
table.column(new Col("Web-State"));
table.column(new Col("Level"));
table.column(new Col("Web-ContextPath"));
table.column(new Col("Name"));
java.util.List<WebBundle> webBundles = webContainerService.list();
if (webBundles != null && !webBundles.isEmpty()) {
for (WebBundle webBundle : webBundles) {
table.addRow().addContent(webBundle.getBundleId(), webBundle.getState(), webBundle.getWebState(), webBundle.getLevel(), webBundle.getContextPath(), webBundle.getName());
}
}
table.print(System.out, !noFormat);
return null;
}
Aggregations