use of javax.management.remote.JMXServiceURL in project geode by apache.
the class JMXDataUpdater method connect.
/**
* Get the jmx connection
*/
public JMXConnector connect(String username, String password) {
// Reference to repository
Repository repository = Repository.get();
try {
String jmxSerURL = "";
logger.info("{}:{}", resourceBundle.getString("LOG_MSG_USE_LOCATOR_VALUE"), repository.getJmxUseLocator());
if (repository.getJmxUseLocator()) {
JmxManagerInfo jmxManagerInfo = getManagerInfoFromLocator(repository);
if (jmxManagerInfo.port == 0) {
logger.info(resourceBundle.getString("LOG_MSG_LOCATOR_COULD_NOT_FIND_MANAGER"));
} else {
logger.info("{}: {}={} & {}={}, {}", resourceBundle.getString("LOG_MSG_LOCATOR_FOUND_MANAGER"), resourceBundle.getString("LOG_MSG_HOST"), jmxManagerInfo.host, resourceBundle.getString("LOG_MSG_PORT"), jmxManagerInfo.port, (jmxManagerInfo.ssl ? resourceBundle.getString("LOG_MSG_WITH_SSL") : resourceBundle.getString("LOG_MSG_WITHOUT_SSL")));
jmxSerURL = formJMXServiceURLString(jmxManagerInfo.host, String.valueOf(jmxManagerInfo.port));
}
} else {
logger.info("{}={} & {}={}", resourceBundle.getString("LOG_MSG_HOST"), this.serverName, resourceBundle.getString("LOG_MSG_PORT"), this.port);
jmxSerURL = formJMXServiceURLString(this.serverName, this.port);
}
if (StringUtils.isNotBlank(jmxSerURL)) {
JMXServiceURL url = new JMXServiceURL(jmxSerURL);
String[] creds = { username, password };
Map<String, Object> env = new HashMap<String, Object>();
env.put(JMXConnector.CREDENTIALS, creds);
if (repository.isUseSSLManager()) {
// use ssl to connect
env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory());
}
logger.info("Connecting to jmxURL : {}", jmxSerURL);
this.conn = JMXConnectorFactory.connect(url, env);
this.mbs = this.conn.getMBeanServerConnection();
cluster.setConnectedFlag(true);
}
} catch (Exception e) {
cluster.setConnectedFlag(false);
cluster.setConnectionErrorMsg(e.getMessage());
logger.fatal(e.getMessage(), e);
if (this.conn != null) {
try {
this.conn.close();
} catch (Exception e1) {
logger.fatal(e1.getMessage(), e1);
}
this.conn = null;
}
}
return this.conn;
}
use of javax.management.remote.JMXServiceURL in project karaf by apache.
the class DeployMojo method deployWithJmx.
protected void deployWithJmx(List<String> locations) throws MojoExecutionException {
try {
JMXServiceURL jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/" + instance);
ArrayList<String> list = new ArrayList<>();
if (user != null)
list.add(user);
if (password != null)
list.add(password);
HashMap env = new HashMap();
String[] credentials = list.toArray(new String[list.size()]);
env.put(JMXConnector.CREDENTIALS, credentials);
JMXConnector jmxConnector = null;
if (credentials.length > 0)
jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, env);
else
jmxConnector = JMXConnectorFactory.connect(jmxServiceURL);
MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
for (String location : locations) {
mBeanServerConnection.invoke(new ObjectName("org.apache.karaf:type=bundle,name=*"), "install", new Object[] { location, true }, new String[] { "java.lang.String", "boolean" });
}
} catch (Exception e) {
throw new MojoExecutionException("Can't deploy using JMX", e);
}
}
use of javax.management.remote.JMXServiceURL in project spring-framework by spring-projects.
the class MBeanClientInterceptorTests method testTestLazyConnectionToRemote.
@Test
public void testTestLazyConnectionToRemote() throws Exception {
assumeTrue(runTests);
Assume.group(TestGroup.JMXMP);
final int port = SocketUtils.findAvailableTcpPort();
JMXServiceURL url = new JMXServiceURL("service:jmx:jmxmp://localhost:" + port);
JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer());
MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
factory.setServiceUrl(url.toString());
factory.setProxyInterface(IJmxTestBean.class);
factory.setObjectName(OBJECT_NAME);
factory.setConnectOnStartup(false);
factory.setRefreshOnConnectFailure(true);
// should skip connection to the server
factory.afterPropertiesSet();
IJmxTestBean bean = (IJmxTestBean) factory.getObject();
// now start the connector
try {
connector.start();
} catch (BindException ex) {
System.out.println("Skipping remainder of JMX LazyConnectionToRemote test because binding to local port [" + port + "] failed: " + ex.getMessage());
return;
}
// should now be able to access data via the lazy proxy
try {
assertEquals("Rob Harrop", bean.getName());
assertEquals(100, bean.getAge());
} finally {
connector.stop();
}
try {
bean.getName();
} catch (JmxException ex) {
// expected
}
connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, getServer());
connector.start();
// should now be able to access data via the lazy proxy
try {
assertEquals("Rob Harrop", bean.getName());
assertEquals(100, bean.getAge());
} finally {
connector.stop();
}
}
use of javax.management.remote.JMXServiceURL 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.JMXServiceURL in project camel by apache.
the class ManagedServiceUrlPathTest method testConnectToJmx.
public void testConnectToJmx() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
clientConnector = JMXConnectorFactory.connect(new JMXServiceURL(JMXSERVICEURL), null);
MBeanServerConnection mbeanServer = clientConnector.getMBeanServerConnection();
ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"direct://start\"");
String uri = (String) mbeanServer.getAttribute(name, "EndpointUri");
assertEquals("direct://start", uri);
name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"log://foo\"");
uri = (String) mbeanServer.getAttribute(name, "EndpointUri");
assertEquals("log://foo", uri);
name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"mock://result\"");
uri = (String) mbeanServer.getAttribute(name, "EndpointUri");
assertEquals("mock://result", uri);
String id = (String) mbeanServer.getAttribute(name, "CamelId");
assertEquals("camel-1", id);
Boolean singleton = (Boolean) mbeanServer.getAttribute(name, "Singleton");
assertEquals(Boolean.TRUE, singleton);
}
Aggregations