List of usage examples for javax.management.remote JMXConnector CREDENTIALS
String CREDENTIALS
To view the source code for javax.management.remote JMXConnector CREDENTIALS.
Click Source Link
Name of the attribute that specifies the credentials to send to the connector server during connection.
From source file:com.clustercontrol.jmx.factory.RunMonitorJmx.java
/** * JMX ??// ww w .jav a2 s.c o m * * @param facilityId ID * @return ???????true */ @Override public boolean collect(String facilityId) { boolean result = false; if (m_now != null) { m_nodeDate = m_now.getTime(); } m_value = 0; exception = null; NodeInfo node = null; if (!m_isMonitorJob) { node = nodeInfo.get(facilityId); } else { try { // ?? node = new RepositoryControllerBean().getNode(facilityId); } catch (Exception e) { m_message = MessageConstant.MESSAGE_COULD_NOT_GET_NODE_ATTRIBUTES.getMessage(); return false; } } JMXServiceURL url = null; try { String rmiFormat = HinemosPropertyUtil.getHinemosPropertyStr("monitor.jmx.rmi.format", "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi"); String urlStr = String.format(rmiFormat, node.getAvailableIpAddress(), jmx.getPort()); m_log.debug("facilityId=" + facilityId + ", url=" + urlStr); url = new JMXServiceURL(urlStr); } catch (Exception e) { m_log.warn("fail to initialize JMXServiceURL : " + e.getMessage() + " (" + e.getClass().getName() + ")", e); exception = e; return result; } JMXConnector jmxc = null; try { Map<String, Object> env = new HashMap<>(); if (jmx.getAuthUser() != null) env.put(JMXConnector.CREDENTIALS, new String[] { jmx.getAuthUser(), jmx.getAuthPassword() }); System.setProperty("sun.rmi.transport.tcp.responseTimeout", Integer.toString(HinemosPropertyUtil .getHinemosPropertyNum("system.sun.rmi.transport.tcp.responseTimeout", Long.valueOf(10 * 1000)) .intValue())); jmxc = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); JmxMasterInfo jmxMasterInfo = QueryUtil.getJmxMasterInfoPK(jmx.getMasterId()); Object value = mbsc.getAttribute(new ObjectName(jmxMasterInfo.getObjectName()), jmxMasterInfo.getAttributeName()); m_value = Double.parseDouble( searchTargetValue(value, Arrays.asList(KeyParser.parseKeys(jmxMasterInfo.getKeys()))) .toString()); // ?? if (m_convertFlg == ConvertValueConstant.TYPE_DELTA) { // ?? MonitorJmxValue valueEntity = null; Double prevValue = 0d; Long prevDate = 0l; if (!m_isMonitorJob) { // ?? // cache?? valueEntity = MonitorJmxCache.getMonitorJmxValue(m_monitorId, facilityId); // ??? prevValue = valueEntity.getValue(); if (valueEntity.getGetDate() != null) { prevDate = valueEntity.getGetDate(); } } else { // ?? valueEntity = new MonitorJmxValue(new MonitorJmxValuePK(m_monitorId, facilityId)); if (m_prvData instanceof MonitorJmxValue) { // ???? prevValue = ((MonitorJmxValue) m_prvData).getValue(); prevDate = ((MonitorJmxValue) m_prvData).getGetDate(); } } // JMX???? valueEntity.setValue(Double.valueOf(m_value)); valueEntity.setGetDate(m_nodeDate); if (!m_isMonitorJob) { // ???ID????? if (m_monitor.getMonitorFlg()) MonitorJmxCache.update(m_monitorId, facilityId, valueEntity); int m_validSecond = HinemosPropertyUtil .getHinemosPropertyNum("monitor.jmx.valid.second", Long.valueOf(15)).intValue(); // ??????????? int tolerance = (m_runInterval + m_validSecond) * 1000; if (prevDate > m_nodeDate - tolerance) { // ??null??? if (prevValue == null) { m_log.debug("collect() : prevValue is null"); m_prevNullchk = true; return false; } m_value = m_value - prevValue; } else { if (prevDate != 0l) { DateFormat df = DateFormat.getDateTimeInstance(); df.setTimeZone(HinemosTime.getTimeZone()); String[] args = { df.format(new Date(prevDate)) }; m_message = MessageConstant.MESSAGE_TOO_OLD_TO_CALCULATE.getMessage(args); return false; } else { // ???0?? m_nodeDate = 0l; } } } else { m_value = m_value - prevValue; m_curData = valueEntity; } } m_log.debug(jmxMasterInfo.getName() + " : " + m_value + " " + jmxMasterInfo.getMeasure()); result = true; } catch (NumberFormatException e) { m_log.info("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); String[] args = { Double.toString(m_value) }; m_message = MessageConstant.MESSAGE_COULD_NOT_GET_NUMERIC_VALUE.getMessage(args); return false; } catch (Exception e) { String message = e.getMessage(); if (message != null) { message = message.replaceAll("\n", ""); } m_log.warn("fail to access JMXService : " + message + " (" + e.getClass().getName() + ")"); exception = e; } finally { try { if (jmxc != null) { jmxc.close(); } } catch (IOException e) { m_log.info("fail to close JMXService : " + e.getMessage() + " (" + e.getClass().getName() + ")"); exception = e; } } return result; }
From source file:org.wso2.dss.integration.test.datasource.DataSourceInitializationAtStartUpTestCase.java
@Test(dependsOnMethods = { "isServiceExistAfterRestarting" }, enabled = false) @SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) public void testMBeanForDatasource() throws AxisFault { Map<String, String[]> env = new HashMap<String, String[]>(); String[] credentials = { "admin", "admin" }; env.put(JMXConnector.CREDENTIALS, credentials); try {/*w ww . ja va2 s . c o m*/ String url = "service:jmx:rmi://localhost:11111/jndi/rmi://localhost:9999/jmxrmi"; JMXServiceURL jmxUrl = new JMXServiceURL(url); JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env); MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection(); ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource"); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject); Assert.assertNotNull(mBeanInfo, "Data Source is registered in the MBean server"); } catch (MalformedURLException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (IOException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (MalformedObjectNameException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (IntrospectionException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (ReflectionException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (InstanceNotFoundException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } }
From source file:org.wso2.ei.dataservice.integration.test.datasource.DataSourceInitializationAtStartUpTestCase.java
@Test(dependsOnMethods = { "isServiceExistAfterRestarting" }, enabled = false) @SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) public void testMBeanForDatasource() throws AxisFault { Map<String, String[]> env = new HashMap<String, String[]>(); String[] credentials = { "admin", "admin" }; env.put(JMXConnector.CREDENTIALS, credentials); try {// ww w . j av a2 s .c o m String url = "service:jmx:rmi://localhost:11111/jndi/rmi://localhost:9999/jmxrmi"; JMXServiceURL jmxUrl = new JMXServiceURL(url); JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env); MBeanServerConnection mBeanServer = jmxConnector.getMBeanServerConnection(); ObjectName mbeanObject = new ObjectName(dataSourceName + ",-1234:type=DataSource"); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(mbeanObject); Assert.assertNotNull(mBeanInfo, "Datasource is registered in the MBean server"); } catch (MalformedURLException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (IOException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (MalformedObjectNameException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (IntrospectionException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (ReflectionException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } catch (InstanceNotFoundException e) { throw new AxisFault("Error while connecting to MBean Server " + e.getMessage(), e); } }
From source file:com.zabbix.gateway.JMXItemChecker.java
@Override public JSONArray getValues() throws ZabbixException { JSONArray values = new JSONArray(); try {// www . ja va 2 s . c o m HashMap<String, Object> env = null; env = new HashMap<String, Object>(); env.put(JMXConnector.CREDENTIALS, new String[] { username, password }); if (protocol.equals("t3") || protocol.equals("t3s")) { env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); env.put(javax.naming.Context.SECURITY_PRINCIPAL, ((String[]) env.get(JMXConnector.CREDENTIALS))[0]); env.put(javax.naming.Context.SECURITY_CREDENTIALS, ((String[]) env.get(JMXConnector.CREDENTIALS))[1]); } // Required by SSL if (protocol.equals("jmxs")) { env.put("com.sun.jndi.rmi.factory.socket", new SslRMIClientSocketFactory()); } jmxc = ZabbixJMXConnectorFactory.connect(url, env); mbsc = jmxc.getMBeanServerConnection(); for (String key : keys) values.put(getJSONValue(key)); } catch (Exception e) { throw new ZabbixException(e); } finally { try { if (null != jmxc) jmxc.close(); } catch (java.io.IOException exception) { } jmxc = null; mbsc = null; } return values; }
From source file:com.adaptris.core.jmx.JmxConnection.java
private MBeanServerConnection createConnection() throws IOException, AdaptrisSecurityException { MBeanServerConnection result = null; if (!isBlank(getJmxServiceUrl())) { Map env = KeyValuePairBag.asMap(getJmxProperties()); if (!isBlank(getUsername())) { if (!env.containsKey(JMX_REMOTE_PROFILES)) { env.put(JMX_REMOTE_PROFILES, SASL_PLAIN); }// w w w .ja v a2 s. co m env.put(JMXConnector.CREDENTIALS, new String[] { getUsername(), Password.decode(ExternalResolver.resolve(getPassword())) }); } connector = JMXConnectorFactory.connect(new JMXServiceURL(getJmxServiceUrl()), env.size() == 0 ? null : env); result = connector.getMBeanServerConnection(); } else { result = JmxHelper.findMBeanServer(); } return result; }
From source file:com.exxatools.monitoring.jmx.JmxStats.java
/** * Get a MBean server connection. Either opens a new connection or returns an already opened connection. * * @return the opened connection//from www .j a va2 s. c om * @throws IOException in case the connection cannot be established */ protected MBeanServerConnection getConnection() throws IOException { if (connection == null) { Map<String, Object> environment = new HashMap<String, Object>(); if (username != null && password != null) { environment.put(JMXConnector.CREDENTIALS, new String[] { username, password }); } connector = JMXConnectorFactory.connect(serviceUrl, environment); connection = connector.getMBeanServerConnection(); } return connection; }
From source file:com.spotify.reaper.cassandra.JmxProxy.java
/** * Connect to JMX interface on the given host and port. * * @param handler Implementation of {@link RepairStatusHandler} to process incoming * notifications//from w w w .j a v a 2s . c o m * of repair events. * @param host hostname or ip address of Cassandra node * @param port port number to use for JMX connection * @param username username to use for JMX authentication * @param password password to use for JMX authentication */ static JmxProxy connect(Optional<RepairStatusHandler> handler, String host, int port, String username, String password) throws ReaperException { ObjectName ssMbeanName; ObjectName cmMbeanName; JMXServiceURL jmxUrl; try { jmxUrl = new JMXServiceURL(String.format(JMX_URL, host, port)); ssMbeanName = new ObjectName(SS_OBJECT_NAME); cmMbeanName = new ObjectName(CompactionManager.MBEAN_OBJECT_NAME); } catch (MalformedURLException | MalformedObjectNameException e) { LOG.error(String.format("Failed to prepare the JMX connection to %s:%s", host, port)); throw new ReaperException("Failure during preparations for JMX connection", e); } try { Map<String, Object> env = new HashMap<String, Object>(); if (username != null && password != null) { String[] creds = { username, password }; env.put(JMXConnector.CREDENTIALS, creds); } JMXConnector jmxConn = JMXConnectorFactory.connect(jmxUrl, env); MBeanServerConnection mbeanServerConn = jmxConn.getMBeanServerConnection(); Object ssProxy = JMX.newMBeanProxy(mbeanServerConn, ssMbeanName, StorageServiceMBean.class); String cassandraVersion = ((StorageServiceMBean) ssProxy).getReleaseVersion(); if (cassandraVersion.startsWith("2.0") || cassandraVersion.startsWith("1.")) { ssProxy = JMX.newMBeanProxy(mbeanServerConn, ssMbeanName, StorageServiceMBean20.class); } CompactionManagerMBean cmProxy = JMX.newMBeanProxy(mbeanServerConn, cmMbeanName, CompactionManagerMBean.class); JmxProxy proxy = new JmxProxy(handler, host, jmxUrl, jmxConn, ssProxy, ssMbeanName, mbeanServerConn, cmProxy); // registering a listener throws bunch of exceptions, so we do it here rather than in the // constructor mbeanServerConn.addNotificationListener(ssMbeanName, proxy, null, null); LOG.debug("JMX connection to {} properly connected: {}", host, jmxUrl.toString()); return proxy; } catch (IOException | InstanceNotFoundException e) { LOG.error("Failed to establish JMX connection to {}:{}", host, port); throw new ReaperException("Failure when establishing JMX connection", e); } }
From source file:org.wso2.appserver.integration.tests.config.EnvironmentVariableReadTestCase.java
@Test(groups = "wso2.as", description = "Try to persist a Employee obj through the Sessionfactory") public void testConnectingToJMXServer() throws Exception { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:" + (SERVER_PORT + portOffset) + "/jndi/rmi://localhost:" + (REGISTRY_PORT + portOffset) + "/jmxrmi"); Map<String, Object> environment = new HashMap<>(); String[] credentials = { "admin", "admin" }; environment.put(JMXConnector.CREDENTIALS, credentials); JMXConnector jmxc = JMXConnectorFactory.connect(url, environment); log.info("Connection Id =" + jmxc.getConnectionId()); }
From source file:org.apache.cassandra.tools.NodeProbe.java
/** * Create a connection to the JMX agent and setup the M[X]Bean proxies. * * @throws IOException on connection failures *///from w w w .j av a 2 s.c om private void connect() throws IOException { JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port)); Map<String, Object> env = new HashMap<String, Object>(); if (username != null) { String[] creds = { username, password }; env.put(JMXConnector.CREDENTIALS, creds); } env.put("com.sun.jndi.rmi.factory.socket", getRMIClientSocketFactory()); jmxc = JMXConnectorFactory.connect(jmxUrl, env); mbeanServerConn = jmxc.getMBeanServerConnection(); try { ObjectName name = new ObjectName(ssObjName); ssProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageServiceMBean.class); name = new ObjectName(MessagingService.MBEAN_NAME); msProxy = JMX.newMBeanProxy(mbeanServerConn, name, MessagingServiceMBean.class); name = new ObjectName(StreamManagerMBean.OBJECT_NAME); streamProxy = JMX.newMBeanProxy(mbeanServerConn, name, StreamManagerMBean.class); name = new ObjectName(CompactionManager.MBEAN_OBJECT_NAME); compactionProxy = JMX.newMBeanProxy(mbeanServerConn, name, CompactionManagerMBean.class); name = new ObjectName(FailureDetector.MBEAN_NAME); fdProxy = JMX.newMBeanProxy(mbeanServerConn, name, FailureDetectorMBean.class); name = new ObjectName(CacheService.MBEAN_NAME); cacheService = JMX.newMBeanProxy(mbeanServerConn, name, CacheServiceMBean.class); name = new ObjectName(StorageProxy.MBEAN_NAME); spProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageProxyMBean.class); name = new ObjectName(HintedHandOffManager.MBEAN_NAME); hhProxy = JMX.newMBeanProxy(mbeanServerConn, name, HintedHandOffManagerMBean.class); name = new ObjectName(GCInspector.MBEAN_NAME); gcProxy = JMX.newMBeanProxy(mbeanServerConn, name, GCInspectorMXBean.class); } catch (MalformedObjectNameException e) { throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); } memProxy = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); runtimeProxy = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); }
From source file:org.eclipse.virgo.server.svt.watchrepo.WatchedRepositoryTests.java
private static MBeanServerConnection getMBeanServerConnection() throws Exception { String severDir = null;//from w w w . j a va 2s . co m String[] creds = { "admin", "springsource" }; Map<String, String[]> env = new HashMap<String, String[]>(); File testExpanded = new File("./../org.eclipse.virgo.server.svt/target/test-expanded/"); for (File mainDir : testExpanded.listFiles()) { if (mainDir.isDirectory()) { severDir = new File(mainDir.toURI()).getCanonicalPath(); } } env.put(JMXConnector.CREDENTIALS, creds); System.setProperty("javax.net.ssl.trustStore", severDir + KEYSTORE); System.setProperty("javax.net.ssl.trustStorePassword", KEYPASSWORD); JMXServiceURL url = new JMXServiceURL(JMXURL); connection = JMXConnectorFactory.connect(url, env).getMBeanServerConnection(); return connection; }