use of javax.management.openmbean.KeyAlreadyExistsException 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.KeyAlreadyExistsException 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;
}
Aggregations