use of javax.management.openmbean.TabularData in project karaf by apache.
the class WebTest method listViaMBean.
@Test
public void listViaMBean() throws Exception {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("org.apache.karaf:type=web,name=root");
TabularData webBundles = (TabularData) mbeanServer.getAttribute(name, "WebBundles");
assertEquals(0, webBundles.size());
}
use of javax.management.openmbean.TabularData in project karaf by apache.
the class PackagesMBeanImpl method getImports.
@Override
public TabularData getImports() {
try {
String[] names = new String[] { "PackageName", "Filter", "Optional", "ID", "Bundle Name", "Resolvable" };
CompositeType bundleType = new CompositeType("PackageImports", "Imported packages", names, names, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.LONG, SimpleType.STRING, SimpleType.BOOLEAN });
TabularType tableType = new TabularType("PackageImports", "Imported packages", bundleType, new String[] { "Filter", "ID" });
TabularData table = new TabularDataSupport(tableType);
List<PackageRequirement> imports = packageService.getImports();
for (PackageRequirement req : imports) {
Object[] data = new Object[] { req.getPackageName(), req.getFilter(), req.isOptional(), req.getBundle().getBundleId(), req.getBundle().getSymbolicName(), req.isResolveable() };
CompositeData comp = new CompositeDataSupport(bundleType, names, data);
try {
table.put(comp);
} catch (KeyAlreadyExistsException e) {
throw new RuntimeException("Id: " + req.getBundle().getBundleId() + ", filter: " + req.getFilter(), e);
}
}
return table;
} catch (RuntimeException e) {
// To avoid the exception gets swallowed by jmx
LOGGER.error(e.getMessage(), e);
throw e;
} catch (OpenDataException e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
use of javax.management.openmbean.TabularData in project karaf by apache.
the class JMXSecurityMBeanImpl method canInvoke.
public TabularData canInvoke(Map<String, List<String>> bulkQuery) throws Exception {
TabularData table = new TabularDataSupport(CAN_INVOKE_TABULAR_TYPE);
BulkRequestContext context = BulkRequestContext.newContext(guard.getConfigAdmin());
for (Map.Entry<String, List<String>> entry : bulkQuery.entrySet()) {
String objectName = entry.getKey();
List<String> methods = entry.getValue();
if (methods.size() == 0) {
boolean res = canInvoke(context, objectName);
CompositeData data = new CompositeDataSupport(CAN_INVOKE_RESULT_ROW_TYPE, CAN_INVOKE_RESULT_COLUMNS, new Object[] { objectName, "", res });
table.put(data);
} else {
for (String method : methods) {
List<String> argTypes = new ArrayList<>();
String name = parseMethodName(method, argTypes);
boolean res;
if (name.equals(method)) {
res = canInvoke(context, objectName, name);
} else {
res = canInvoke(context, objectName, name, argTypes.toArray(new String[] {}));
}
CompositeData data = new CompositeDataSupport(CAN_INVOKE_RESULT_ROW_TYPE, CAN_INVOKE_RESULT_COLUMNS, new Object[] { objectName, method, res });
try {
table.put(data);
} catch (KeyAlreadyExistsException e) {
// KeyAlreadyExistsException can happen only when methods are not empty
LOG.warn("{} (objectName = \"{}\", method = \"{}\")", e, objectName, method);
}
}
}
}
return table;
}
use of javax.management.openmbean.TabularData in project karaf by apache.
the class JMXSecurityMBeanImplTestCase method testCanInvokeBulk.
public void testCanInvokeBulk() throws Exception {
MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.replay(mbs);
ConfigurationAdmin testConfigAdmin = EasyMock.createMock(ConfigurationAdmin.class);
EasyMock.expect(testConfigAdmin.listConfigurations(EasyMock.eq("(service.pid=jmx.acl*)"))).andReturn(new Configuration[0]).anyTimes();
EasyMock.expect(testConfigAdmin.listConfigurations(EasyMock.eq("(service.pid=jmx.acl.whitelist)"))).andReturn(new Configuration[0]).once();
EasyMock.replay(testConfigAdmin);
KarafMBeanServerGuard testGuard = EasyMock.createMock(KarafMBeanServerGuard.class);
String objectName = "foo.bar.testing:type=SomeMBean";
final String[] la = new String[] { "long" };
final String[] sa = new String[] { "java.lang.String" };
EasyMock.expect(testGuard.getConfigAdmin()).andReturn(testConfigAdmin).anyTimes();
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName)), EasyMock.eq("testMethod"), EasyMock.aryEq(la))).andReturn(true).anyTimes();
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName)), EasyMock.eq("testMethod"), EasyMock.aryEq(sa))).andReturn(false).anyTimes();
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName)), EasyMock.eq("otherMethod"))).andReturn(true).anyTimes();
String objectName2 = "foo.bar.testing:type=SomeOtherMBean";
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName2)))).andReturn(true).anyTimes();
String objectName3 = "foo.bar.foo.testing:type=SomeOtherMBean";
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName3)))).andReturn(false).anyTimes();
EasyMock.replay(testGuard);
JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl();
mb.setMBeanServer(mbs);
mb.setGuard(testGuard);
Map<String, List<String>> query = new HashMap<>();
query.put(objectName, Arrays.asList("otherMethod", "testMethod(long)", "testMethod(java.lang.String)"));
query.put(objectName2, Collections.emptyList());
query.put(objectName3, Collections.emptyList());
TabularData result = mb.canInvoke(query);
assertEquals(5, result.size());
CompositeData cd = result.get(new Object[] { objectName, "testMethod(long)" });
assertEquals(objectName, cd.get("ObjectName"));
assertEquals("testMethod(long)", cd.get("Method"));
assertEquals(true, cd.get("CanInvoke"));
CompositeData cd2 = result.get(new Object[] { objectName, "testMethod(java.lang.String)" });
assertEquals(objectName, cd2.get("ObjectName"));
assertEquals("testMethod(java.lang.String)", cd2.get("Method"));
assertEquals(false, cd2.get("CanInvoke"));
CompositeData cd3 = result.get(new Object[] { objectName, "otherMethod" });
assertEquals(objectName, cd3.get("ObjectName"));
assertEquals("otherMethod", cd3.get("Method"));
assertEquals(true, cd3.get("CanInvoke"));
CompositeData cd4 = result.get(new Object[] { objectName2, "" });
assertEquals(objectName2, cd4.get("ObjectName"));
assertEquals("", cd4.get("Method"));
assertEquals(true, cd4.get("CanInvoke"));
CompositeData cd5 = result.get(new Object[] { objectName3, "" });
assertEquals(objectName3, cd5.get("ObjectName"));
assertEquals("", cd5.get("Method"));
assertEquals(false, cd5.get("CanInvoke"));
}
use of javax.management.openmbean.TabularData in project karaf by apache.
the class HttpMBeanImpl method getServlets.
public TabularData getServlets() throws MBeanException {
try {
CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet", new String[] { "Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL" }, new String[] { "ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet" }, new OpenType[] { SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[] { "Bundle-ID", "Servlet Name", "State" });
TabularData table = new TabularDataSupport(tableType);
List<ServletInfo> servletInfos = servletService.getServlets();
for (ServletInfo info : servletInfos) {
CompositeData data = new CompositeDataSupport(servletType, new String[] { "Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL" }, new Object[] { info.getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls()) });
table.put(data);
}
return table;
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
Aggregations