diff --git a/source/code/JEE/Common/src/com/interopbridges/scx/ScxExceptionBundle.java b/source/code/JEE/Common/src/com/interopbridges/scx/ScxExceptionBundle.java index 8ca1f73..24a5a4f 100644 --- a/source/code/JEE/Common/src/com/interopbridges/scx/ScxExceptionBundle.java +++ b/source/code/JEE/Common/src/com/interopbridges/scx/ScxExceptionBundle.java @@ -94,7 +94,7 @@ private ScxExceptionBundle(ResourceBundle bundle) { /** *

* Get the localized message for the given Exception Code. - *

* * @param key * A key to look-up in the resource file. diff --git a/source/code/JEE/Common/src/com/interopbridges/scx/jeeinfo/JeeServerInfo.java b/source/code/JEE/Common/src/com/interopbridges/scx/jeeinfo/JeeServerInfo.java index 5d8773d..b3fb668 100644 --- a/source/code/JEE/Common/src/com/interopbridges/scx/jeeinfo/JeeServerInfo.java +++ b/source/code/JEE/Common/src/com/interopbridges/scx/jeeinfo/JeeServerInfo.java @@ -169,6 +169,11 @@ public Statistic getAppServerName() { ServerName = getJMXAttribute(ijmx, "WebSphere:j2eeType=J2EEServer,*", "platformName"); } + else + if(storename.compareTo(JmxConstant.KARAF_MBEAN_STORE_NAME)==0) + { + ServerName = "JBoss A-MQ (on Karaf)"; + } } } @@ -225,6 +230,11 @@ public Statistic getVersion() { ServerVersion = getJMXAttribute(ijmx, "WebSphere:j2eeType=J2EEServer,*", "platformVersion"); } + else + if(storename.compareTo(JmxConstant.KARAF_MBEAN_STORE_NAME)==0) + { + ServerVersion = getJMXAttribute(ijmx, "org.apache.activemq:brokerName=*,type=Broker", "BrokerVersion"); + } } } return ServerVersion!=null ? new Statistic(AppServerVersion, String.class, ServerVersion) : null; diff --git a/source/code/JEE/Common/src/com/interopbridges/scx/jmx/JmxStores.java b/source/code/JEE/Common/src/com/interopbridges/scx/jmx/JmxStores.java index 01d59ee..7d0bef9 100644 --- a/source/code/JEE/Common/src/com/interopbridges/scx/jmx/JmxStores.java +++ b/source/code/JEE/Common/src/com/interopbridges/scx/jmx/JmxStores.java @@ -80,6 +80,7 @@ public static void connectToJmxStores() addStoreToJmxStores(JmxConstant.TOMCAT_MBEAN_STORE_NAME,null); addStoreToJmxStores(JmxConstant.WEBSPHERE_MBEAN_STORE_NAME,null); addStoreToJmxStores(JmxConstant.WEBLOGIC_MBEAN_STORE_NAME,null); + addStoreToJmxStores(JmxConstant.KARAF_MBEAN_STORE_NAME,null); /* * The JdkJMXAbstraction needs to be the last entry in the list to avoid the * version information being processed from the JdkJMXAbstraction MBean store. diff --git a/source/code/JEE/Common/src/com/interopbridges/scx/jmx/KarafJMXAbstraction.java b/source/code/JEE/Common/src/com/interopbridges/scx/jmx/KarafJMXAbstraction.java new file mode 100644 index 0000000..46f6837 --- /dev/null +++ b/source/code/JEE/Common/src/com/interopbridges/scx/jmx/KarafJMXAbstraction.java @@ -0,0 +1,225 @@ +/** + * Copyright (c) Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the + * License at http://www.apache.org/licenses/LICENSE-2.0. + * + * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS + * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION + * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + * MERCHANTABLITY OR NON-INFRINGEMENT. + * + * See the Apache Version 2.0 License for specific language governing + * permissions and limitations under the License. + */ + +package com.interopbridges.scx.jmx; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.Set; + +import javax.management.AttributeNotFoundException; +import javax.management.InstanceAlreadyExistsException; +import javax.management.InstanceNotFoundException; +import javax.management.IntrospectionException; +import javax.management.MBeanException; +import javax.management.MBeanInfo; +import javax.management.MBeanRegistrationException; +import javax.management.MBeanServer; +import javax.management.MBeanServerConnection; +import javax.management.NotCompliantMBeanException; +import javax.management.ObjectInstance; +import javax.management.ObjectName; +import javax.management.QueryExp; +import javax.management.ReflectionException; +import javax.naming.NamingException; + +import com.interopbridges.scx.ScxException; + + +/** + *

+ * Karaf 2.2.3 for the Runtime JMX Store + *

+ * + * @author Geoff Erasmus + */ +public class KarafJMXAbstraction implements IJMX { + + /** + *

+ * Connection to the MBeanServer + *

+ */ + private MBeanServerConnection _server; + + /** + *

+ * Constructor. The constructor sets the MBeanServer to be used by this class. + *

+ * + * @param server + * An instance of a MBeanServer to be used by this class. + * + */ + public KarafJMXAbstraction(MBeanServer server) throws + NamingException + { + _server = server; + } + + /** + *

+ * Default Constructor. The constructor attempts to locate a reference to the Weblogic runtime JMX MBean Store + * it does not use specific API calls but rather does a JNDI lookup to retrieve the reference to the + * MBeanServer. + *

+ * + * @throws ScxException + * The JNDI lookup could not return an instance of a MBeanServer. + */ + public KarafJMXAbstraction() throws + NamingException, + ScxException + { + /* + try + { + //JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi"); + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root"); + HashMap env = new HashMap(); + String[] credentials = new String[] {"admin","admin"}; + env.put(JMXConnector.CREDENTIALS, credentials); + + JMXConnector connector = JMXConnectorFactory.connect(url, env); + //JMXConnector connector = JMXConnectorFactory.connect(url, null); + _server = connector.getMBeanServerConnection(); + + } + catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + _server = ManagementFactory.getPlatformMBeanServer(); + + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#getAttribute(javax.management.ObjectName, + * java.lang.String) + */ + public Object getAttribute(ObjectName name, String attribute) + throws MBeanException, AttributeNotFoundException, + InstanceNotFoundException, ReflectionException, IOException { + return this._server.getAttribute(name, attribute); + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#getMBeanServerID() + */ + public int getMBeanServerID() + { + return this._server.hashCode(); + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#getMBeanCount() + */ + public Integer getMBeanCount() + throws IOException + { + return this._server.getMBeanCount(); + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#getMBeanInfo(javax.management.ObjectName) + */ + public MBeanInfo getMBeanInfo(ObjectName name) + throws InstanceNotFoundException, IntrospectionException, + ReflectionException, IOException { + return this._server.getMBeanInfo(name); + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#isStandAloneJmxStore() + */ + public boolean isStandAloneJmxStore() + { + return true; + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#queryMBeans(javax.management.ObjectName, + * javax.management.QueryExp) + */ + public Set queryMBeans(ObjectName name, QueryExp query) + throws IOException + { + return this._server.queryMBeans(name, query); + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#queryNames(javax.management.ObjectName, + * javax.management.QueryExp) + */ + public Set queryNames(ObjectName name, QueryExp query) + throws IOException + { + return this._server.queryNames(name, query); + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#registerMbean(java.lang.Object, + * javax.management.ObjectName) + */ + public void registerMBean(Object bean, ObjectName keys) + throws InstanceAlreadyExistsException, MBeanRegistrationException, + NotCompliantMBeanException, IOException { + /* do nothing */ + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#verifyStoreConnection() + */ + public boolean verifyStoreConnection() + { + // No additional checks are needed for this platform to + // verify the JMX store connection + return true; + } + + /* + * (non-Javadoc) + * + * @see com.interopbridges.scx.jmx.IJMX#invoke(ObjectName, String, Object[], String[]) + */ + public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) + throws InstanceNotFoundException, ReflectionException, MBeanException, IOException + { + return this._server.invoke(name, operationName, params, signature); + } +} diff --git a/source/code/JEE/Common/src/com/interopbridges/scx/util/JmxConstant.java b/source/code/JEE/Common/src/com/interopbridges/scx/util/JmxConstant.java index a0a34c9..ea63a72 100644 --- a/source/code/JEE/Common/src/com/interopbridges/scx/util/JmxConstant.java +++ b/source/code/JEE/Common/src/com/interopbridges/scx/util/JmxConstant.java @@ -286,4 +286,5 @@ public class JmxConstant { public static final String WEBSPHERE_MBEAN_STORE_NAME = "com.interopbridges.scx.jmx.WebSphereJMXAbstraction"; public static final String WEBLOGIC_MBEAN_STORE_NAME = "com.interopbridges.scx.jmx.WeblogicRuntimeJMXAbstraction"; public static final String JDK_MBEAN_STORE_NAME = "com.interopbridges.scx.jmx.JdkJMXAbstraction"; + public static final String KARAF_MBEAN_STORE_NAME = "com.interopbridges.scx.jmx.KarafJMXAbstraction"; } diff --git a/source/code/JEE/WSJMX/src/com/interopbridges/scx/beanspy/BeanSpyMainTest.java b/source/code/JEE/WSJMX/src/com/interopbridges/scx/beanspy/BeanSpyMainTest.java new file mode 100644 index 0000000..e7c0657 --- /dev/null +++ b/source/code/JEE/WSJMX/src/com/interopbridges/scx/beanspy/BeanSpyMainTest.java @@ -0,0 +1,71 @@ +package com.interopbridges.scx.beanspy; + +import java.io.IOException; +import java.util.HashMap; + +import com.interopbridges.scx.ScxException; +import com.interopbridges.scx.jmx.JmxStores; +import com.interopbridges.scx.log.ILogger; +import com.interopbridges.scx.log.LoggingFactory; +import com.interopbridges.scx.mbeans.MBeanGetter; +import com.interopbridges.scx.util.JmxURLCheck; +import com.interopbridges.scx.util.MsVersion; + +public class BeanSpyMainTest { + + /** + *

+ * Logger for the class. + *

+ */ + private static ILogger _logger = LoggingFactory.getLogger(); + + + /** + *

+ * Interface to getting the desired MBeans from the JMX Store (as XML). + *

+ */ + protected MBeanGetter _mbeanAccessor; + + public BeanSpyMainTest(){ + + //this._logger = LoggingFactory.getLogger(); + _mbeanAccessor = new MBeanGetter(JmxStores.getListOfJmxStoreAbstractions()); + + + String JMXQuery = "org.apache.activemq:type=Broker,*"; + HashMap Params = null; + try { + String xml = _mbeanAccessor.getMBeansAsXml(JMXQuery, Params) + .toString(); + System.out.println(xml); + } catch (ScxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + + + + + JmxStores.clearListOfJmxStores(); + + } + + + public static void main(String[] args) { + _logger.info(new StringBuffer("Initializing BeanSpy (Build: ") + .append(MsVersion.VERSION).append(", Label: ").append( + MsVersion.LABEL_NAME).append(", BuildDate: ").append( + MsVersion.BUILD_DATE).append(")").toString()); + _logger.info("contextInitialized: connecting to JMX Stores"); + JmxStores.connectToJmxStores(); + new BeanSpyMainTest(); + } + +} diff --git a/source/code/JEE/WSJMX/src/com/interopbridges/scx/beanspy/DummyKarafTest.java b/source/code/JEE/WSJMX/src/com/interopbridges/scx/beanspy/DummyKarafTest.java new file mode 100644 index 0000000..41abbe8 --- /dev/null +++ b/source/code/JEE/WSJMX/src/com/interopbridges/scx/beanspy/DummyKarafTest.java @@ -0,0 +1,30 @@ +package com.interopbridges.scx.beanspy; + +import java.util.HashMap; + +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +public class DummyKarafTest { + + public static void main(String[] args) throws Exception { + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root"); + HashMap env = new HashMap(); + String[] credentials = new String[] {"admin","admin"}; + env.put(JMXConnector.CREDENTIALS, credentials); + + JMXConnector connector = JMXConnectorFactory.connect(url, env); + + MBeanServerConnection mbeanServer = connector.getMBeanServerConnection(); + ObjectName systemMBean = new ObjectName("org.apache.activemq:brokerName=amq,type=Broker,*"); + // systemMBean. + connector.close(); + + System.out.println("Done"); + + } + +}