Search in sources :

Example 1 with JMXServerErrorException

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;
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) JMXServerErrorException(javax.management.remote.JMXServerErrorException) MalformedURLException(java.net.MalformedURLException) JMXServerErrorException(javax.management.remote.JMXServerErrorException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName) JMXConnectorServer(javax.management.remote.JMXConnectorServer) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) MBeanServer(javax.management.MBeanServer)

Example 2 with JMXServerErrorException

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();
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedActionException(java.security.PrivilegedActionException) JMXServerErrorException(javax.management.remote.JMXServerErrorException) UnmarshalException(java.rmi.UnmarshalException) JMXServerErrorException(javax.management.remote.JMXServerErrorException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 JMXServerErrorException (javax.management.remote.JMXServerErrorException)2 MalformedURLException (java.net.MalformedURLException)1 UnmarshalException (java.rmi.UnmarshalException)1 AccessControlContext (java.security.AccessControlContext)1 PrivilegedActionException (java.security.PrivilegedActionException)1 MBeanServer (javax.management.MBeanServer)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 ObjectName (javax.management.ObjectName)1 JMXConnector (javax.management.remote.JMXConnector)1 JMXConnectorServer (javax.management.remote.JMXConnectorServer)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1