use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.
the class MXBeanFallbackTest method testPrivateMXBean.
private static void testPrivateMXBean(String type, Object bean) throws Exception {
System.out.println(type + " MXBean test...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName on = new ObjectName("test:type=" + type);
try {
mbs.registerMBean(bean, on);
success("Private MXBean registered");
} catch (NotCompliantMBeanException e) {
failure("Failed to register the private MXBean - " + bean.getClass().getInterfaces()[0].getName());
}
}
use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.
the class ExceptionDiagnosisTest method testMXBeans.
private static void testMXBeans(Object mbean, Type... expectedTypes) throws Exception {
try {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
ObjectName name = new ObjectName("a:b=c");
mbs.registerMBean(mbean, name);
fail("No exception from registerMBean for " + mbean);
} catch (NotCompliantMBeanException e) {
checkExceptionChain("MBean " + mbean, e, expectedTypes);
}
}
use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.
the class Introspector method checkCompliance.
public static void checkCompliance(Class<?> mbeanClass) throws NotCompliantMBeanException {
//
if (DynamicMBean.class.isAssignableFrom(mbeanClass))
return;
// Is Standard MBean?
//
final Exception mbeanException;
try {
getStandardMBeanInterface(mbeanClass);
return;
} catch (NotCompliantMBeanException e) {
mbeanException = e;
}
// Is MXBean?
//
final Exception mxbeanException;
try {
getMXBeanInterface(mbeanClass);
return;
} catch (NotCompliantMBeanException e) {
mxbeanException = e;
}
final String msg = "MBean class " + mbeanClass.getName() + " does not implement " + "DynamicMBean, and neither follows the Standard MBean conventions (" + mbeanException.toString() + ") nor the MXBean conventions (" + mxbeanException.toString() + ")";
throw new NotCompliantMBeanException(msg);
}
use of javax.management.NotCompliantMBeanException in project jdk8u_jdk by JetBrains.
the class MLet method getMBeansFromURL.
/**
* Loads a text file containing MLET tags that define the MBeans to
* be added to the MBean server. The location of the text file is specified by
* a URL. The MBeans specified in the MLET file will be instantiated and
* registered in the MBean server.
*
* @param url The URL of the text file to be loaded as String object.
*
* @return A set containing one entry per MLET tag in the m-let
* text file loaded. Each entry specifies either the
* ObjectInstance for the created MBean, or a throwable object
* (that is, an error or an exception) if the MBean could not be
* created.
*
* @exception ServiceNotFoundException One of the following
* errors has occurred: The m-let text file does not contain an
* MLET tag, the m-let text file is not found, a mandatory
* attribute of the MLET tag is not specified, the url is
* malformed.
* @exception IllegalStateException MLet MBean is not registered
* with an MBeanServer.
*
*/
public Set<Object> getMBeansFromURL(String url) throws ServiceNotFoundException {
String mth = "getMBeansFromURL";
if (server == null) {
throw new IllegalStateException("This MLet MBean is not " + "registered with an MBeanServer.");
}
// Parse arguments
if (url == null) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "URL is null");
throw new ServiceNotFoundException("The specified URL is null");
} else {
url = url.replace(File.separatorChar, '/');
}
if (MLET_LOGGER.isLoggable(Level.FINER)) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "<URL = " + url + ">");
}
// Parse URL
try {
MLetParser parser = new MLetParser();
mletList = parser.parseURL(url);
} catch (Exception e) {
final String msg = "Problems while parsing URL [" + url + "], got exception [" + e.toString() + "]";
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
throw EnvHelp.initCause(new ServiceNotFoundException(msg), e);
}
// Check that the list of MLets is not empty
if (mletList.size() == 0) {
final String msg = "File " + url + " not found or MLET tag not defined in file";
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
throw new ServiceNotFoundException(msg);
}
// Walk through the list of MLets
Set<Object> mbeans = new HashSet<Object>();
for (MLetContent elmt : mletList) {
// Initialize local variables
String code = elmt.getCode();
if (code != null) {
if (code.endsWith(".class")) {
code = code.substring(0, code.length() - 6);
}
}
String name = elmt.getName();
URL codebase = elmt.getCodeBase();
String version = elmt.getVersion();
String serName = elmt.getSerializedObject();
String jarFiles = elmt.getJarFiles();
URL documentBase = elmt.getDocumentBase();
// Display debug information
if (MLET_LOGGER.isLoggable(Level.FINER)) {
final StringBuilder strb = new StringBuilder().append("\n\tMLET TAG = ").append(elmt.getAttributes()).append("\n\tCODEBASE = ").append(codebase).append("\n\tARCHIVE = ").append(jarFiles).append("\n\tCODE = ").append(code).append("\n\tOBJECT = ").append(serName).append("\n\tNAME = ").append(name).append("\n\tVERSION = ").append(version).append("\n\tDOCUMENT URL = ").append(documentBase);
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, strb.toString());
}
// Load classes from JAR files
StringTokenizer st = new StringTokenizer(jarFiles, ",", false);
while (st.hasMoreTokens()) {
String tok = st.nextToken().trim();
if (MLET_LOGGER.isLoggable(Level.FINER)) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "Load archive for codebase <" + codebase + ">, file <" + tok + ">");
}
//
try {
codebase = check(version, codebase, tok, elmt);
} catch (Exception ex) {
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), mth, "Got unexpected exception", ex);
mbeans.add(ex);
continue;
}
// URLs to search for classes and resources.
try {
if (!Arrays.asList(getURLs()).contains(new URL(codebase.toString() + tok))) {
addURL(codebase + tok);
}
} catch (MalformedURLException me) {
// OK : Ignore jar file if its name provokes the
// URL to be an invalid one.
}
}
// Instantiate the class specified in the
// CODE or OBJECT section of the MLet tag
//
Object o;
ObjectInstance objInst;
if (code != null && serName != null) {
final String msg = "CODE and OBJECT parameters cannot be specified at the " + "same time in tag MLET";
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
mbeans.add(new Error(msg));
continue;
}
if (code == null && serName == null) {
final String msg = "Either CODE or OBJECT parameter must be specified in " + "tag MLET";
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg);
mbeans.add(new Error(msg));
continue;
}
try {
if (code != null) {
List<String> signat = elmt.getParameterTypes();
List<String> stringPars = elmt.getParameterValues();
List<Object> objectPars = new ArrayList<Object>();
for (int i = 0; i < signat.size(); i++) {
objectPars.add(constructParameter(stringPars.get(i), signat.get(i)));
}
if (signat.isEmpty()) {
if (name == null) {
objInst = server.createMBean(code, null, mletObjectName);
} else {
objInst = server.createMBean(code, new ObjectName(name), mletObjectName);
}
} else {
Object[] parms = objectPars.toArray();
String[] signature = new String[signat.size()];
signat.toArray(signature);
if (MLET_LOGGER.isLoggable(Level.FINEST)) {
final StringBuilder strb = new StringBuilder();
for (int i = 0; i < signature.length; i++) {
strb.append("\n\tSignature = ").append(signature[i]).append("\t\nParams = ").append(parms[i]);
}
MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), mth, strb.toString());
}
if (name == null) {
objInst = server.createMBean(code, null, mletObjectName, parms, signature);
} else {
objInst = server.createMBean(code, new ObjectName(name), mletObjectName, parms, signature);
}
}
} else {
o = loadSerializedObject(codebase, serName);
if (name == null) {
server.registerMBean(o, null);
} else {
server.registerMBean(o, new ObjectName(name));
}
objInst = new ObjectInstance(name, o.getClass().getName());
}
} catch (ReflectionException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "ReflectionException", ex);
mbeans.add(ex);
continue;
} catch (InstanceAlreadyExistsException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "InstanceAlreadyExistsException", ex);
mbeans.add(ex);
continue;
} catch (MBeanRegistrationException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "MBeanRegistrationException", ex);
mbeans.add(ex);
continue;
} catch (MBeanException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "MBeanException", ex);
mbeans.add(ex);
continue;
} catch (NotCompliantMBeanException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "NotCompliantMBeanException", ex);
mbeans.add(ex);
continue;
} catch (InstanceNotFoundException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "InstanceNotFoundException", ex);
mbeans.add(ex);
continue;
} catch (IOException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "IOException", ex);
mbeans.add(ex);
continue;
} catch (SecurityException ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "SecurityException", ex);
mbeans.add(ex);
continue;
} catch (Exception ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "Exception", ex);
mbeans.add(ex);
continue;
} catch (Error ex) {
MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, "Error", ex);
mbeans.add(ex);
continue;
}
mbeans.add(objInst);
}
return mbeans;
}
use of javax.management.NotCompliantMBeanException in project ddf by codice.
the class UndeliveredMessages method registerMbean.
private void registerMbean() {
try {
undeliveredMessagesObjectName = new ObjectName(UndeliveredMessages.class.getName() + M_BEAN_NAME);
} catch (MalformedObjectNameException e) {
LOGGER.warn("Unable to create MBean: [{}]. For more " + "information, set logging level to DEBUG.", undeliveredMessagesObjectName);
LOGGER.debug("Unable to create MBean: [{}].", undeliveredMessagesObjectName, e);
}
if (mBeanServer == null) {
LOGGER.warn("Could not register MBean: [{}], MBean server is null.", undeliveredMessagesObjectName);
return;
}
try {
try {
mBeanServer.registerMBean(this, undeliveredMessagesObjectName);
LOGGER.info("Registered MBean under object name: {}", undeliveredMessagesObjectName);
} catch (InstanceAlreadyExistsException e) {
// Try to remove and re-register
mBeanServer.unregisterMBean(undeliveredMessagesObjectName);
mBeanServer.registerMBean(this, undeliveredMessagesObjectName);
LOGGER.info("Re-registered MBean: [{}]", undeliveredMessagesObjectName);
}
} catch (MBeanRegistrationException | InstanceNotFoundException | InstanceAlreadyExistsException | NotCompliantMBeanException e) {
LOGGER.warn("Could not register MBean: [{}]. For more information, set " + "logging level to DEBUG.", undeliveredMessagesObjectName);
LOGGER.debug("Could not register MBean: [{}].", undeliveredMessagesObjectName, e);
}
}
Aggregations