use of javax.management.IntrospectionException in project jdk8u_jdk by JetBrains.
the class XSheet method displayMBeanNode.
// Call on EDT
private void displayMBeanNode(final DefaultMutableTreeNode node) {
final XNodeInfo uo = (XNodeInfo) node.getUserObject();
if (!uo.getType().equals(Type.MBEAN)) {
return;
}
mbean = (XMBean) uo.getData();
SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() {
@Override
public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
return mbean.getMBeanInfo();
}
@Override
protected void done() {
try {
MBeanInfo mbi = get();
if (mbi != null) {
if (!isSelectedNode(node, currentNode)) {
return;
}
mbeanInfo.addMBeanInfo(mbean, mbi);
invalidate();
mainPanel.removeAll();
mainPanel.add(mbeanInfo, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
}
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Couldn't get MBeanInfo for MBean [" + mbean.getObjectName() + "]");
t.printStackTrace();
}
showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
}
}
};
sw.execute();
}
use of javax.management.IntrospectionException in project sling by apache.
the class JMXResourceProvider method parse.
/**
* Parse the path
*/
private PathInfo parse(final String path) {
for (final String root : this.rootsWithSlash) {
if (path.startsWith(root)) {
final String subPath = path.substring(root.length());
if (subPath.length() == 0) {
return new PathInfo(true);
}
// MBean name / path
String checkPath = subPath;
String pathInfo = null;
ObjectName objectName = null;
MBeanInfo mbi = null;
while (checkPath.length() > 0 && mbi == null) {
try {
objectName = this.convertResourcePathToObjectName(checkPath);
if (objectName != null) {
mbi = this.mbeanServer.getMBeanInfo(objectName);
}
} catch (final IntrospectionException e) {
// ignore
} catch (final InstanceNotFoundException e) {
// ignore
} catch (final ReflectionException e) {
// ignore
}
if (mbi == null) {
final int sep = checkPath.lastIndexOf('/');
if (sep == -1) {
checkPath = "";
pathInfo = subPath;
} else {
checkPath = checkPath.substring(0, sep);
pathInfo = subPath.substring(sep + 1);
}
}
}
final PathInfo info = new PathInfo(pathInfo);
if (mbi != null) {
info.objectName = objectName;
info.mbeanInfo = mbi;
}
return info;
}
}
for (final String root : this.roots) {
if (path.equals(root)) {
return new PathInfo(true);
}
}
return null;
}
use of javax.management.IntrospectionException in project sling by apache.
the class JMXResourceProvider method listChildren.
/**
* @see org.apache.sling.api.resource.ResourceProvider#listChildren(org.apache.sling.api.resource.Resource)
*/
public Iterator<Resource> listChildren(final Resource parent) {
final PathInfo info = this.parse(parent.getPath());
if (info != null) {
if (info.isRoot || info.mbeanInfo == null) {
// list all MBeans
final Set<ObjectName> names = this.queryObjectNames(info.isRoot ? null : info.pathInfo);
final Set<String> filteredNames = new HashSet<String>();
final String prefix = (info.isRoot ? null : info.pathInfo + "/");
for (final ObjectName name : names) {
final String path = this.convertObjectNameToResourcePath(name);
final String testName = (info.isRoot ? path : path.substring(prefix.length()));
final int sep = testName.indexOf('/');
if (sep == -1) {
filteredNames.add(":" + name.getCanonicalName());
} else {
filteredNames.add(testName.substring(0, sep));
}
}
final List<String> sortedNames = new ArrayList<String>(filteredNames);
Collections.sort(sortedNames);
final Iterator<String> iter = sortedNames.iterator();
return new Iterator<Resource>() {
private Resource next;
{
seek();
}
private void seek() {
while (iter.hasNext() && this.next == null) {
final String name = iter.next();
if (name.startsWith(":")) {
try {
final ObjectName on = new ObjectName(name.substring(1));
final MBeanInfo info = mbeanServer.getMBeanInfo(on);
final String path = convertObjectNameToResourcePath(on);
final int sep = path.lastIndexOf('/');
this.next = new MBeanResource(mbeanServer, parent.getResourceResolver(), path, parent.getPath() + "/" + path.substring(sep + 1), info, on);
} catch (final IntrospectionException e) {
// ignore
} catch (final InstanceNotFoundException e) {
// ignore
} catch (final ReflectionException e) {
// ignore
} catch (final MalformedObjectNameException e) {
// ignore
}
} else {
this.next = new RootResource(parent.getResourceResolver(), parent.getPath() + '/' + name);
}
}
}
public boolean hasNext() {
return next != null;
}
public Resource next() {
if (next != null) {
final Resource rsrc = next;
this.next = null;
seek();
return rsrc;
}
throw new NoSuchElementException();
}
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
} else {
if (info.pathInfo == null) {
final MBeanResource parentResource;
if (parent instanceof MBeanResource) {
parentResource = (MBeanResource) parent;
} else {
parentResource = (MBeanResource) this.getResource(parent.getResourceResolver(), parent.getPath());
}
final List<Resource> list = new ArrayList<Resource>();
list.add(new AttributesResource(parent.getResourceResolver(), parent.getPath() + "/mbean:attributes", parentResource));
return list.iterator();
} else if (info.pathInfo.equals("mbean:attributes")) {
final AttributesResource parentResource;
if (parent instanceof AttributesResource) {
parentResource = (AttributesResource) parent;
} else {
parentResource = (AttributesResource) this.getResource(parent.getResourceResolver(), parent.getPath());
}
final MBeanResource parentMBeanResource = (MBeanResource) parentResource.getParent();
final AttributeList result = parentMBeanResource.getAttributes();
final MBeanAttributeInfo[] infos = info.mbeanInfo.getAttributes();
final Map<String, MBeanAttributeInfo> infoMap = new HashMap<String, MBeanAttributeInfo>();
for (final MBeanAttributeInfo i : infos) {
infoMap.put(i.getName(), i);
}
final Iterator iter = result.iterator();
return new Iterator<Resource>() {
public void remove() {
throw new UnsupportedOperationException("remove");
}
public Resource next() {
final Attribute attr = (Attribute) iter.next();
return new AttributeResource(parent.getResourceResolver(), parent.getPath() + "/" + attr.getName(), infoMap.get(attr.getName()), attr.getValue(), parentResource);
}
public boolean hasNext() {
return iter.hasNext();
}
};
} else if (info.pathInfo.startsWith("mbean:attributes/")) {
Resource checkParentResource = parent;
if (!(checkParentResource instanceof AttributeResource) && !(checkParentResource instanceof MapResource)) {
checkParentResource = this.getResource(parent.getResourceResolver(), parent.getPath());
}
final AttributeResource parentResource;
if (checkParentResource instanceof AttributeResource) {
parentResource = (AttributeResource) checkParentResource;
} else {
parentResource = ((MapResource) checkParentResource).getAttributeResource();
}
final String attrPath = info.pathInfo.substring("mbean:attributes/".length());
final int pos = attrPath.indexOf('/');
final String subPath;
if (pos == -1) {
subPath = null;
} else {
subPath = attrPath.substring(pos + 1);
}
return parentResource.getChildren(parent.getPath(), subPath);
}
}
}
return null;
}
use of javax.management.IntrospectionException in project hadoop by apache.
the class JMXJsonServlet method listBeans.
// --------------------------------------------------------- Private Methods
private void listBeans(JsonGenerator jg, ObjectName qry, String attribute, HttpServletResponse response) throws IOException {
LOG.debug("Listing beans for " + qry);
Set<ObjectName> names = null;
names = mBeanServer.queryNames(qry, null);
jg.writeArrayFieldStart("beans");
Iterator<ObjectName> it = names.iterator();
while (it.hasNext()) {
ObjectName oname = it.next();
MBeanInfo minfo;
String code = "";
Object attributeinfo = null;
try {
minfo = mBeanServer.getMBeanInfo(oname);
code = minfo.getClassName();
String prs = "";
try {
if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
prs = "modelerType";
code = (String) mBeanServer.getAttribute(oname, prs);
}
if (attribute != null) {
prs = attribute;
attributeinfo = mBeanServer.getAttribute(oname, prs);
}
} catch (AttributeNotFoundException e) {
// If the modelerType attribute was not found, the class name is used
// instead.
LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
} catch (MBeanException e) {
// The code inside the attribute getter threw an exception so log it,
// and fall back on the class name
LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
} catch (RuntimeException e) {
// For some reason even with an MBeanException available to them
// Runtime exceptionscan still find their way through, so treat them
// the same as MBeanException
LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
} catch (ReflectionException e) {
// This happens when the code inside the JMX bean (setter?? from the
// java docs) threw an exception, so log it and fall back on the
// class name
LOG.error("getting attribute " + prs + " of " + oname + " threw an exception", e);
}
} catch (InstanceNotFoundException e) {
//Ignored for some reason the bean was not found so don't output it
continue;
} catch (IntrospectionException e) {
// This is an internal error, something odd happened with reflection so
// log it and don't output the bean.
LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
continue;
} catch (ReflectionException e) {
// This happens when the code inside the JMX bean threw an exception, so
// log it and don't output the bean.
LOG.error("Problem while trying to process JMX query: " + qry + " with MBean " + oname, e);
continue;
}
jg.writeStartObject();
jg.writeStringField("name", oname.toString());
jg.writeStringField("modelerType", code);
if ((attribute != null) && (attributeinfo == null)) {
jg.writeStringField("result", "ERROR");
jg.writeStringField("message", "No attribute with name " + attribute + " was found.");
jg.writeEndObject();
jg.writeEndArray();
jg.close();
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (attribute != null) {
writeAttribute(jg, attribute, attributeinfo);
} else {
MBeanAttributeInfo[] attrs = minfo.getAttributes();
for (int i = 0; i < attrs.length; i++) {
writeAttribute(jg, oname, attrs[i]);
}
}
jg.writeEndObject();
}
jg.writeEndArray();
}
use of javax.management.IntrospectionException in project spring-framework by spring-projects.
the class MBeanClientInterceptor method retrieveMBeanInfo.
/**
* Loads the management interface info for the configured MBean into the caches.
* This information is used by the proxy when determining whether an invocation matches
* a valid operation or attribute on the management interface of the managed resource.
*/
private void retrieveMBeanInfo() throws MBeanInfoRetrievalException {
try {
MBeanInfo info = this.serverToUse.getMBeanInfo(this.objectName);
MBeanAttributeInfo[] attributeInfo = info.getAttributes();
this.allowedAttributes = new HashMap<>(attributeInfo.length);
for (MBeanAttributeInfo infoEle : attributeInfo) {
this.allowedAttributes.put(infoEle.getName(), infoEle);
}
MBeanOperationInfo[] operationInfo = info.getOperations();
this.allowedOperations = new HashMap<>(operationInfo.length);
for (MBeanOperationInfo infoEle : operationInfo) {
Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader);
this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle);
}
} catch (ClassNotFoundException ex) {
throw new MBeanInfoRetrievalException("Unable to locate class specified in method signature", ex);
} catch (IntrospectionException ex) {
throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]", ex);
} catch (InstanceNotFoundException ex) {
// if we are this far this shouldn't happen, but...
throw new MBeanInfoRetrievalException("Unable to obtain MBean info for bean [" + this.objectName + "]: it is likely that this bean was unregistered during the proxy creation process", ex);
} catch (ReflectionException ex) {
throw new MBeanInfoRetrievalException("Unable to read MBean info for bean [ " + this.objectName + "]", ex);
} catch (IOException ex) {
throw new MBeanInfoRetrievalException("An IOException occurred when communicating with the " + "MBeanServer. It is likely that you are communicating with a remote MBeanServer. " + "Check the inner exception for exact details.", ex);
}
}
Aggregations