use of javax.management.remote.JMXServerErrorException in project jdk8u_jdk by JetBrains.
the class JMXServerErrorTest method test.
public void test(String url) throws Exception {
final JMXServiceURL jurl = new JMXServiceURL(url);
final ObjectName kname = new ObjectName(":type=Kaeffer");
final MBeanServer mbs = MBeanServerFactory.newMBeanServer();
final String that = "that";
mbs.registerMBean(new Kaeffer(that), kname);
final MBeanServer kbs = new MBeanServerKaeffer(mbs);
final JMXConnectorServer cs;
try {
cs = JMXConnectorServerFactory.newJMXConnectorServer(jurl, null, kbs);
} catch (MalformedURLException m) {
if ("jmxmp".equals(jurl.getProtocol()) || "iiop".equals(jurl.getProtocol())) {
// OK, we may not have this in the classpath...
System.out.println("WARNING: Skipping protocol: " + jurl);
return;
}
throw m;
}
final ObjectName cname = new ObjectName(":type=JMXConnectorServer");
mbs.registerMBean(cs, cname);
cs.start();
JMXConnector c = null;
try {
c = JMXConnectorFactory.connect(cs.getAddress(), null);
final MBeanServerConnection mbsc = c.getMBeanServerConnection();
final KaefferMBean kaeffer = (KaefferMBean) MBeanServerInvocationHandler.newProxyInstance(mbsc, kname, KaefferMBean.class, false);
final String that1 = kaeffer.getThis();
if (!that.equals(that1))
throw new Exception("Unexpected string returned by " + kname + ": " + that1);
try {
kaeffer.setThis("but not that");
throw new Exception("Expected JMXServerErrorException" + " not thrown" + " for setAttribute \"This\" ");
} catch (JMXServerErrorException jsee) {
if (!(jsee.getCause() instanceof KaefferError)) {
final Exception e = new Exception("Expected JMXServerErrorException" + " is not an instance of " + KaefferError.class.getName() + ": " + jsee.getCause());
e.initCause(jsee);
throw e;
}
System.out.println("Got expected error: " + jsee);
}
try {
kaeffer.doThis("but not that");
throw new Exception("Expected JMXServerErrorException" + " not thrown" + " for invoke \"doThis\" ");
} catch (JMXServerErrorException jsee) {
if (!(jsee.getCause() instanceof KaefferError)) {
final Exception e = new Exception("Expected JMXServerErrorException" + " is not an instance of " + KaefferError.class.getName() + ": " + jsee.getCause());
e.initCause(jsee);
throw e;
}
System.out.println("Got expected error: " + jsee);
}
} finally {
if (c != null)
try {
c.close();
} catch (Exception x) {
System.err.println("Failed to close client: " + x);
throw x;
}
try {
cs.stop();
} catch (Exception x) {
System.err.println("Failed to stop server: " + x);
throw x;
}
}
}
use of javax.management.remote.JMXServerErrorException in project jdk8u_jdk by JetBrains.
the class RMIConnectionImpl method doPrivilegedOperation.
private Object doPrivilegedOperation(final int operation, final Object[] params, final Subject delegationSubject) throws PrivilegedActionException, IOException {
serverCommunicatorAdmin.reqIncoming();
try {
final AccessControlContext reqACC;
if (delegationSubject == null)
reqACC = acc;
else {
if (subject == null) {
final String msg = "Subject delegation cannot be enabled unless " + "an authenticated subject is put in place";
throw new SecurityException(msg);
}
reqACC = subjectDelegator.delegatedContext(acc, delegationSubject, removeCallerContext);
}
PrivilegedOperation op = new PrivilegedOperation(operation, params);
if (reqACC == null) {
try {
return op.run();
} catch (Exception e) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new PrivilegedActionException(e);
}
} else {
return AccessController.doPrivileged(op, reqACC);
}
} catch (Error e) {
throw new JMXServerErrorException(e.toString(), e);
} finally {
serverCommunicatorAdmin.rspOutgoing();
}
}
Aggregations