use of javax.management.MBeanException in project ddf by codice.
the class ResourceDownloadActionEndpointTest method getDownloadToLocalSiteExceptionWrappedInMBeanException.
private MBeanException getDownloadToLocalSiteExceptionWrappedInMBeanException() {
String message = "exception message";
DownloadToLocalSiteException downloadToCacheException = new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message);
MBeanException mBeanException = new MBeanException(downloadToCacheException, message);
return mBeanException;
}
use of javax.management.MBeanException in project jdk8u_jdk by JetBrains.
the class MBeanExceptionTest method test.
private static int test(MBeanServer mbs, ObjectName name, boolean testChecked) throws Exception {
System.out.println("--------" + name + "--------");
int failures = 0;
final String[] ops = { "getAttribute", "setAttribute", "invoke" };
final int GET = 0, SET = 1, INVOKE = 2;
final String[] targets = { "UncheckedException", "CheckedException" };
final int UNCHECKED = 0, CHECKED = 1;
for (int i = 0; i < ops.length; i++) {
for (int j = 0; j < targets.length; j++) {
if (j == CHECKED && !testChecked)
continue;
String target = targets[j];
String what = ops[i] + "/" + target;
System.out.println(what);
try {
switch(i) {
case GET:
mbs.getAttribute(name, target);
break;
case SET:
mbs.setAttribute(name, new Attribute(target, "x"));
break;
case INVOKE:
mbs.invoke(name, target, null, null);
break;
default:
throw new AssertionError();
}
System.out.println("failure: " + what + " returned!");
failures++;
} catch (RuntimeMBeanException e) {
if (j == CHECKED) {
System.out.println("failure: RuntimeMBeanException " + "when checked expected: " + e);
failures++;
} else {
Throwable cause = e.getCause();
if (cause == theUncheckedException)
System.out.println("ok: " + what);
else {
System.out.println("failure: " + what + " wrapped " + cause);
failures++;
}
}
} catch (MBeanException e) {
if (j == UNCHECKED) {
System.out.println("failure: checked exception " + "when unchecked expected: " + e);
failures++;
} else {
Throwable cause = e.getCause();
if (cause == theCheckedException)
System.out.println("ok: " + what);
else {
System.out.println("failure: " + what + " wrapped " + cause);
failures++;
}
}
} catch (Throwable t) {
System.out.println("failure: " + what + " threw: " + t);
while ((t = t.getCause()) != null) System.out.println(" ... " + t);
failures++;
}
}
}
return failures;
}
use of javax.management.MBeanException in project geode by apache.
the class MBeanProcessController method invokeOperationOnTargetMBean.
/**
* Connects to the process and use its MBean to stop it.
*
* @param namePattern the name pattern of the MBean to use for stopping
* @param pidAttribute the name of the MBean attribute with the process id to compare against
* @param methodName the name of the MBean operation to invoke
* @param attributes the names of the MBean attributes to compare with expected values
* @param values the expected values of the specified MBean attributes
*
* @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
* in the process
* @throws IOException if a communication problem occurred when talking to the MBean server
* @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason
*/
private Object invokeOperationOnTargetMBean(final ObjectName namePattern, final String pidAttribute, final String methodName, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException {
ObjectName objectName = namePattern;
connect();
try {
final QueryExp constraint = buildQueryExp(pidAttribute, attributes, values);
final Set<ObjectName> mbeanNames = this.server.queryNames(namePattern, constraint);
if (mbeanNames.isEmpty()) {
throw new MBeanInvocationFailedException("Failed to find mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
}
if (mbeanNames.size() > 1) {
throw new MBeanInvocationFailedException("Found more than one mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
}
objectName = mbeanNames.iterator().next();
return invoke(objectName, methodName);
} catch (InstanceNotFoundException e) {
throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
} catch (MBeanException e) {
throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
} catch (ReflectionException e) {
throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
} finally {
disconnect();
}
}
use of javax.management.MBeanException in project geode by apache.
the class LocalProcessController method invokeOperationOnTargetMBean.
/**
* Connects to the process and use its MBean to stop it.
*
* @param namePattern the name pattern of the MBean to use for stopping
* @param pidAttribute the name of the MBean attribute with the process id to compare against
* @param methodName the name of the MBean operation to invoke
* @param attributes the names of the MBean attributes to compare with expected values
* @param values the expected values of the specified MBean attributes
*
* @throws ConnectionFailedException if there was a failure to connect to the local JMX connector
* in the process
* @throws IOException if a communication problem occurred when talking to the MBean server
* @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason
* @throws PidUnavailableException if parsing the pid from the RuntimeMXBean name fails
*/
private Object invokeOperationOnTargetMBean(final ObjectName namePattern, final String pidAttribute, final String methodName, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException, PidUnavailableException {
ObjectName objectName = namePattern;
connect();
try {
final QueryExp constraint = buildQueryExp(pidAttribute, attributes, values);
final Set<ObjectName> mbeanNames = this.server.queryNames(namePattern, constraint);
if (mbeanNames.isEmpty()) {
throw new MBeanInvocationFailedException("Failed to find mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
}
if (mbeanNames.size() > 1) {
throw new MBeanInvocationFailedException("Found more than one mbean matching '" + namePattern + "' with attribute '" + pidAttribute + "' of value '" + this.pid + "'");
}
objectName = mbeanNames.iterator().next();
return invoke(objectName, methodName);
} catch (InstanceNotFoundException e) {
throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
} catch (MBeanException e) {
throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
} catch (ReflectionException e) {
throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e);
} finally {
disconnect();
}
}
use of javax.management.MBeanException in project geode by apache.
the class ConnectionNotificationFilterImpl method stopRMIConnectorServer.
/** Stops the RMIConnectorServer and unregisters its MBean. */
private void stopRMIConnectorServer() {
if (!this.agentConfig.isRmiEnabled())
return;
// stop the RMI Connector server...
try {
this.rmiConnector.stop();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
try {
ObjectName rmiRegistryNamingName = getRMIRegistryNamingName();
if (this.agentConfig.isRmiRegistryEnabled() && mBeanServer.isRegistered(rmiRegistryNamingName)) {
String[] empty = new String[0];
mBeanServer.invoke(rmiRegistryNamingName, "stop", empty, empty);
MBeanUtil.unregisterMBean(rmiRegistryNamingName);
}
} catch (MalformedObjectNameException e) {
logger.warn(e.getMessage(), e);
} catch (InstanceNotFoundException e) {
logger.warn(e.getMessage(), e);
} catch (ReflectionException e) {
logger.warn(e.getMessage(), e);
} catch (MBeanException e) {
logger.warn(e.getMessage(), e);
}
try {
ObjectName rmiConnectorServerName = getRMIConnectorServerName();
if (mBeanServer.isRegistered(rmiConnectorServerName)) {
MBeanUtil.unregisterMBean(rmiConnectorServerName);
}
} catch (MalformedObjectNameException e) {
logger.warn(e.getMessage(), e);
}
}
Aggregations