use of javax.management.remote.JMXConnector in project camel by apache.
the class CamelKarafTestSupport method getJMXConnector.
public JMXConnector getJMXConnector(String userName, String passWord) throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
Hashtable<String, Object> env = new Hashtable<>();
String[] credentials = new String[] { userName, passWord };
env.put("jmx.remote.credentials", credentials);
JMXConnector connector = JMXConnectorFactory.connect(url, env);
return connector;
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class StartManagementAgent method tryConnect.
private static void tryConnect(int port, boolean shouldSucceed) throws Exception {
String jmxUrlStr = String.format("service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi", port);
JMXServiceURL url = new JMXServiceURL(jmxUrlStr);
HashMap<String, ?> env = new HashMap<>();
boolean succeeded;
try {
JMXConnector c = JMXConnectorFactory.connect(url, env);
c.getMBeanServerConnection();
succeeded = true;
} catch (Exception ex) {
succeeded = false;
}
if (succeeded && !shouldSucceed) {
throw new Exception("Could connect to agent, but should not have been possible");
}
if (!succeeded && shouldSucceed) {
throw new Exception("Could not connect to agent");
}
}
use of javax.management.remote.JMXConnector 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.JMXConnector in project jdk8u_jdk by JetBrains.
the class RMISocketFactoriesTest method main.
public static void main(String[] args) {
System.out.println("Test RMI factories : " + args[0]);
try {
// Create an RMI registry
//
System.out.println("Start RMI registry...");
Registry reg = null;
int port = 5800;
while (port++ < 6000) {
try {
reg = LocateRegistry.createRegistry(port);
System.out.println("RMI registry running on port " + port);
break;
} catch (RemoteException e) {
// Failed to create RMI registry...
System.out.println("Failed to create RMI registry " + "on port " + port);
}
}
if (reg == null) {
System.exit(1);
}
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Initialize environment map to be passed to the connector server
//
System.out.println("Initialize environment map");
HashMap env = new HashMap();
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, new RMIServerFactory(args[0]));
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, new RMIClientFactory(args[0]));
// Create an RMI connector server
//
System.out.println("Create an RMI connector server");
JMXServiceURL url = new JMXServiceURL("rmi", null, 0, "/jndi/rmi://:" + port + "/server" + port);
JMXConnectorServer rcs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
rcs.start();
// Create an RMI connector client
//
System.out.println("Create an RMI connector client");
JMXConnector jmxc = JMXConnectorFactory.connect(url, new HashMap());
// If this line is executed then the test failed
//
System.exit(1);
} catch (Exception e) {
if (e.getMessage().equals(args[0])) {
System.out.println("Expected exception caught = " + e);
System.out.println("Bye! Bye!");
} else {
System.out.println("Unexpected exception caught = " + e);
e.printStackTrace();
System.exit(1);
}
}
}
use of javax.management.remote.JMXConnector in project jdk8u_jdk by JetBrains.
the class ConcurrentModificationTest method test.
private static void test(String proto) throws Exception {
JMXServiceURL u = new JMXServiceURL(proto, null, 0);
JMXConnectorServer server;
JMXConnector client;
try {
server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);
server.start();
JMXServiceURL addr = server.getAddress();
client = JMXConnectorFactory.connect(addr, null);
} catch (MalformedURLException e) {
System.out.println(">>> not support: " + proto);
return;
}
final MBeanServerConnection mserver = client.getMBeanServerConnection();
int count = 0;
boolean adding = true;
while (uncaughtException == null && count++ < 10) {
for (int i = 0; i < number; i++) {
listenerOp(mserver, listeners[i], adding);
mbeanOp(mserver, timerNames[i], adding);
}
adding = !adding;
}
if (uncaughtException != null) {
// clean
for (int i = 0; i < number; i++) {
try {
mbeanOp(mserver, timerNames[i], false);
} catch (Exception e) {
}
}
}
client.close();
server.stop();
}
Aggregations