[ 
https://issues.apache.org/jira/browse/KARAF-2925?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jean-Baptiste Onofré updated KARAF-2925:
----------------------------------------
    Comment: was deleted

(was: jbonofre closed pull request #37: [KARAF-2925] Add JMXMP support in JMX 
collector
URL: https://github.com/apache/karaf-decanter/pull/37
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/collector/jmx/pom.xml b/collector/jmx/pom.xml
index 73ecd85..8c3c3bb 100644
--- a/collector/jmx/pom.xml
+++ b/collector/jmx/pom.xml
@@ -40,6 +40,12 @@
                        <version>1.10.19</version>
                        <scope>test</scope>
                </dependency>
+        <dependency>
+            <groupId>org.glassfish.external</groupId>
+            <artifactId>opendmk_jmxremote_optional_jar</artifactId>
+            <version>1.0-b01-ea</version>
+            <scope>test</scope>
+        </dependency>
        </dependencies>
 
     <build>
@@ -75,6 +81,20 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Import-Package>
+                            com.sun.jmx.remote.protocol;resolution:=optional,
+                            *
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
diff --git 
a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
 
b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
index f22dd20..c74ffdc 100644
--- 
a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
+++ 
b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
@@ -62,6 +62,8 @@
     private String url;
     private String username;
     private String password;
+    private String remoteProtocolPkgs;
+
     private Set<String> objectNames;
     private Dictionary<String, Object> properties;
 
@@ -72,6 +74,7 @@ public void activate(ComponentContext context) {
         String url = getProperty(this.properties, "url", "local");
         String username = getProperty(this.properties, "username", null);
         String password = getProperty(this.properties, "password", null);
+        String remoteProtocolPkgs = getProperty(this.properties, 
"jmx.remote.protocol.provider.pkgs", null);
         Dictionary<String, String> serviceProperties = new Hashtable<> ();
         serviceProperties.put("decanter.collector.name", type);
 
@@ -79,6 +82,7 @@ public void activate(ComponentContext context) {
         this.url = url;
         this.username = username;
         this.password = password;
+        this.remoteProtocolPkgs = remoteProtocolPkgs;
 
         this.objectNames = new HashSet<> ();
         for (Enumeration<String> e = this.properties.keys(); 
e.hasMoreElements(); ) {
@@ -170,6 +174,9 @@ public void run() {
         if (this.username != null && this.password != null) {
             env.put(JMXConnector.CREDENTIALS, new String[] { this.username, 
this.password });
         }
+        if (this.remoteProtocolPkgs != null) {
+            env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, 
this.remoteProtocolPkgs);
+        }
         return env;
     }
 
diff --git 
a/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestMapAttribute.java
 
b/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestMapAttribute.java
index 3bde32c..3d7e51d 100644
--- 
a/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestMapAttribute.java
+++ 
b/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestMapAttribute.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.karaf.decanter.collector.jmx;
 
 import java.lang.management.ManagementFactory;
diff --git 
a/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestProtocol.java
 
b/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestProtocol.java
new file mode 100644
index 0000000..16e659e
--- /dev/null
+++ 
b/collector/jmx/src/test/java/org/apache/karaf/decanter/collector/jmx/TestProtocol.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.collector.jmx;
+
+import org.junit.*;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.management.*;
+import javax.management.remote.*;
+import java.rmi.registry.LocateRegistry;
+import java.util.Dictionary;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+public class TestProtocol {
+
+    private final static Logger LOGGER = 
LoggerFactory.getLogger(TestProtocol.class);
+
+    private final static String JMX_RMI_SERVICE_URL = 
"service:jmx:rmi:///jndi/rmi://localhost:8888/decanter";
+
+    private static JMXConnectorServer rmiConnectorServer;
+    private static JMXConnectorServer jmxmpConnectorServer;
+    private static MBeanServer mBeanServer;
+
+    @BeforeClass
+    public static void setup() throws Exception {
+        LOGGER.info("Using JMX service URL: {}", JMX_RMI_SERVICE_URL);
+        JMXServiceURL serviceURL = new JMXServiceURL(JMX_RMI_SERVICE_URL);
+
+        LOGGER.info("Creating the RMI registry");
+        LocateRegistry.createRegistry(8888);
+
+        LOGGER.info("Creating MBeanServer");
+        mBeanServer = MBeanServerFactory.createMBeanServer();
+
+        LOGGER.info("Creating RMI connector server");
+        rmiConnectorServer = 
JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null, mBeanServer);
+        rmiConnectorServer.start();
+
+        LOGGER.info("Creating JMXMP connector server");
+        jmxmpConnectorServer = 
JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL("jmxmp", 
null, 9999), null, mBeanServer);
+        jmxmpConnectorServer.start();
+
+        ObjectName testObjectName = new ObjectName("decanter.test:type=test");
+        StandardMBean testMBean = new StandardMBean(new TestMBeanImpl(), 
TestMBean.class);
+        LOGGER.info("Registering MBeanTest");
+        mBeanServer.registerMBean(testMBean, testObjectName);
+    }
+
+    @Test
+    public void rmiTest() throws Exception {
+        JmxCollector collector = new JmxCollector();
+
+        ComponentContextMock componentContextMock = new ComponentContextMock();
+        componentContextMock.getProperties().put("type", "jmx-test");
+        componentContextMock.getProperties().put("url", 
"service:jmx:rmi:///jndi/rmi://localhost:8888/decanter");
+
+        DispatcherMock dispatcherMock = new DispatcherMock();
+        collector.dispatcher = dispatcherMock;
+
+        collector.activate(componentContextMock);
+
+        collector.run();
+
+        Event event = dispatcherMock.getPostedEvents().get(0);
+
+        Assert.assertEquals("decanter/collect/jmx/jmx-test/decanter/test", 
event.getTopic());
+        Assert.assertEquals("Test", event.getProperty("Test"));
+        Assert.assertEquals("decanter.test:type=test", 
event.getProperty("ObjectName"));
+        
Assert.assertEquals("service:jmx:rmi:///jndi/rmi://localhost:8888/decanter", 
event.getProperty("url"));
+    }
+
+    @Test
+    public void jmxmpTest() throws Exception {
+        JmxCollector collector = new JmxCollector();
+
+        ComponentContextMock componentContextMock = new ComponentContextMock();
+        componentContextMock.getProperties().put("type", "jmx-test");
+        componentContextMock.getProperties().put("url", 
"service:jmx:jmxmp://localhost:9999");
+
+        DispatcherMock dispatcherMock = new DispatcherMock();
+        collector.dispatcher = dispatcherMock;
+
+        collector.activate(componentContextMock);
+
+        collector.run();
+
+        Event event = dispatcherMock.getPostedEvents().get(0);
+
+        Assert.assertEquals("decanter/collect/jmx/jmx-test/decanter/test", 
event.getTopic());
+        Assert.assertEquals("Test", event.getProperty("Test"));
+        Assert.assertEquals("decanter.test:type=test", 
event.getProperty("ObjectName"));
+        Assert.assertEquals("service:jmx:jmxmp://localhost:9999", 
event.getProperty("url"));
+    }
+
+    @AfterClass
+    public static void teardown() throws Exception {
+        rmiConnectorServer.stop();
+        jmxmpConnectorServer.stop();
+    }
+
+    private class ComponentContextMock implements ComponentContext {
+
+        private Properties properties;
+
+        public ComponentContextMock() {
+            this.properties = new Properties();
+        }
+
+        @Override
+        public Dictionary getProperties() {
+            return properties;
+        }
+
+        @Override
+        public Object locateService(String s) {
+            return null;
+        }
+
+        @Override
+        public <S> S locateService(String s, ServiceReference<S> 
serviceReference) {
+            return null;
+        }
+
+        @Override
+        public Object[] locateServices(String s) {
+            return new Object[0];
+        }
+
+        @Override
+        public BundleContext getBundleContext() {
+            return null;
+        }
+
+        @Override
+        public Bundle getUsingBundle() {
+            return null;
+        }
+
+        @Override
+        public ComponentInstance getComponentInstance() {
+            return null;
+        }
+
+        @Override
+        public void enableComponent(String s) {
+
+        }
+
+        @Override
+        public void disableComponent(String s) {
+
+        }
+
+        @Override
+        public ServiceReference<?> getServiceReference() {
+            return null;
+        }
+
+    }
+
+    private class DispatcherMock implements EventAdmin {
+
+        private List<Event> postedEvents = new LinkedList<>();
+        private List<Event> sentEvents = new LinkedList<>();
+
+        @Override
+        public void postEvent(Event event) {
+            postedEvents.add(event);
+        }
+
+        @Override
+        public void sendEvent(Event event) {
+            sentEvents.add(event);
+        }
+
+        public List<Event> getPostedEvents() {
+            return this.postedEvents;
+        }
+
+        public List<Event> getSentEvents() {
+            return this.sentEvents;
+        }
+
+    }
+
+    public interface TestMBean {
+
+        String getTest() throws MBeanException;
+    }
+
+    public static class TestMBeanImpl implements TestMBean {
+
+        @Override
+        public String getTest() throws MBeanException {
+            return "Test";
+        }
+
+    }
+
+}
diff --git a/manual/src/main/asciidoc/user-guide/collectors.adoc 
b/manual/src/main/asciidoc/user-guide/collectors.adoc
index f840e33..32b13c2 100644
--- a/manual/src/main/asciidoc/user-guide/collectors.adoc
+++ b/manual/src/main/asciidoc/user-guide/collectors.adoc
@@ -242,6 +242,55 @@ additional data, and create queries based on this data.
 You can retrieve multiple MBean servers. For that, you just create a new 
configuration file using the file name format
 `etc/org.apache.karaf.decanter.collector.jmx-[ANYNAME].cfg`.
 
+===== JMXMP
+
+The Karaf Decanter JMX collector by default uses RMI protocol for JMX. But it 
also supports JMXMP protocol.
+
+The features to install are the sames: `decanter-collector-jmx`.
+
+However, you have to enable the `jmxmp` protocol support in the Apache Karaf 
instance hosting Karaf Decanter.
+
+You can download the `jmxmp` protocol provider artifact on Maven Central: 
[http://repo.maven.apache.org/maven2/org/glassfish/external/opendmk_jmxremote_optional_jar/1.0-b01-ea/opendmk_jmxremote_optional_jar-1.0-b01-ea.jar]
+
+The `opendmk_jmxremote_optional_jar-1.0-b01-ea.jar` file has to be copied in 
the `lib/boot` folder of your Apache Karaf instance.
+
+Then, you have to add the new JMX remote packages by editing 
`etc/config.properties`, appending the following to the 
`org.osgi.framework.system.packages.extra` property:
+
+----
+org.osgi.framework.system.packages.extra = \
+    ...
+    javax.remote, \
+    com.sun.jmx, \
+    com.sun.jmx.remote, \
+    com.sun.jmx.remote.protocol, \
+    com.sun.jmx.remote.generic, \
+    com.sun.jmx.remote.opt, \
+    com.sun.jmx.remote.opt.internal, \
+    com.sun.jmx.remote.opt.security, \
+    com.sun.jmx.remote.opt.util, \
+    com.sun.jmx.remote.profile, \
+    com.sun.jmx.remote.profile.sasl, \
+    com.sun.jmx.remote.profile.tls, \
+    com.sun.jmx.remote.socket, \
+    javax.management, \
+    javax.management.remote, \
+    javax.management.remote.generic, \
+    javax.management.remote.jmxmp, \
+    javax.management.remote.message
+----
+
+Then, you can create a new Decanter JMX collector by creating a new file, like 
`etc/org.apache.karaf.decanter.collector.jmx-mycollector.cfg` containing 
something like:
+
+----
+type=jmx-mycollector
+url=service:jmx:jmxmp://host:port
+jmx.remote.protocol.provider.pkgs=com.sun.jmx.remote.protocol
+----
+
+You can see:
+* the `url` property contains an URL with `jmxmp` instead of `rmi`.
+* in order to support `jmxmp` protocol, you have to set the protocol provider 
via the `jmx.remote.protocol.provider.pkgs` property (by default, Karaf 
Decanter JMX collector uses the `rmi` protocol provider)
+
 ==== ActiveMQ (JMX)
 
 The ActiveMQ JMX collector is just a special configuration of the JMX 
collector.


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org
)

> Add JMXMP support
> -----------------
>
>                 Key: KARAF-2925
>                 URL: https://issues.apache.org/jira/browse/KARAF-2925
>             Project: Karaf
>          Issue Type: New Feature
>          Components: karaf-core
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>             Fix For: 4.2.1
>
>
> In addition of our JMX RMI standard connector, it would be great to provide 
> support for JMXMP protocol.
> The JMX Messaging Protocol (JMXMP) connector is a configuration of the 
> generic connector where the transport protocol is based on TCP and the object 
> wrapping is native Java serialization. Security is more advanced than for the 
> RMI connector. Security is based on the Java Secure Socket Extension (JSSE), 
> the Java Authentication and Authorization Service (JAAS), and the Simple 
> Authentication and Security Layer (SASL).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to