use of javax.rmi.ssl.SslRMIClientSocketFactory in project jvm-tools by aragozin.
the class JmxConnectionInfo method connectJmx.
@SuppressWarnings("resource")
private MBeanServerConnection connectJmx(String host, int port, Map<String, Object> props) {
try {
RMIServer rmiServer = null;
try {
if (diagMode) {
System.out.println("Try to connect via TLS");
}
Registry registry = LocateRegistry.getRegistry(host, port, new SslRMIClientSocketFactory());
try {
rmiServer = (RMIServer) registry.lookup("jmxrmi");
} catch (NotBoundException nbe) {
throw (IOException) new IOException(nbe.getMessage()).initCause(nbe);
}
} catch (IOException e) {
if (diagMode) {
System.out.println("Failed to connect using TLS: " + e.toString());
System.out.println("Try to use plain socket");
}
Registry registry = LocateRegistry.getRegistry(host, port);
try {
rmiServer = (RMIServer) registry.lookup("jmxrmi");
} catch (NotBoundException nbe) {
if (diagMode) {
System.out.println("Failed using LocateRegistry. Fallback to JMXConnectorFactory");
}
}
}
if (rmiServer != null) {
RMIConnector rmiConnector = new RMIConnector(rmiServer, props);
rmiConnector.connect();
return rmiConnector.getMBeanServerConnection();
}
String proto = System.getProperty("jmx.service.protocol", "rmi");
final String uri = "rmi".equals(proto) ? "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi" : "service:jmx:" + proto + "://" + host + ":" + port;
if (diagMode) {
System.out.println("Using JMX URI: " + uri);
}
JMXServiceURL jmxurl = new JMXServiceURL(uri);
JMXConnector conn = props == null ? JMXConnectorFactory.connect(jmxurl) : JMXConnectorFactory.connect(jmxurl, props);
MBeanServerConnection mserver = conn.getMBeanServerConnection();
return mserver;
} catch (MalformedURLException e) {
commandHost.fail("JMX Connection failed: " + e.toString(), e);
} catch (IOException e) {
commandHost.fail("JMX Connection failed: " + e.toString(), e);
}
return null;
}
use of javax.rmi.ssl.SslRMIClientSocketFactory in project graphdb by neo4j-attic.
the class HotspotManagementSupport method createServer.
private JMXConnectorServer createServer(int port, boolean useSSL) {
MBeanServer server = getMBeanServer();
final JMXServiceURL url;
try {
url = new JMXServiceURL("rmi", null, port);
} catch (MalformedURLException e) {
log.log(Level.WARNING, "Failed to start JMX Server", e);
return null;
}
Map<String, Object> env = new HashMap<String, Object>();
if (useSSL) {
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, new SslRMIClientSocketFactory());
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, new SslRMIServerSocketFactory());
}
try {
return JMXConnectorServerFactory.newJMXConnectorServer(url, env, server);
} catch (IOException e) {
log.log(Level.WARNING, "Failed to start JMX Server", e);
return null;
}
}
Aggregations