Connect to JMX tools from java | Community
Skip to main content
Community_Admin
Adobe Employee
Adobe Employee
October 16, 2015
Solved

Connect to JMX tools from java

  • October 16, 2015
  • 1 reply
  • 1074 views

Hello everyone, hope you’re all having a wonderful day,

 

I’m currently trying to connect to the JMX console’s LDAP functionality through a custom login module. I’m currently trying to use the code located on this web page:

 

http://dev.day.com/content/kb/home/Crx/CrxFAQ/how-to-synchronize-user- with-ldap.html

 

The problem I am running into is this:

 

I run the code, and I am greeted with a null pointer error originating from the line: MBeanServerConnection server = (MBeanServerConnection) JMXConnectorFactory.connect(new JMXServiceURL(serverUrl), attributes).getMBeanServerConnection();

 

What I would like to know is this:

What are the possible causes? I believe that the problem stems from the fact that I cannot connect to the JMX console for some unknown reason, but I could be wrong. I’ve had LDAP working for a while now, so I know that I am able to successfully connect to the server.

 

Additionally: How do I close my connection to the LDAP server after I have finished? I’ve pasted the code below so you guys can try and figure what the problem is. Thanks!

 

            public static void syncUserToCrx(String userName){

                        String userid = "admin";

                        String password = "admin";

                        String serverUrl = "service:jmx:rmi:///jndi/rmi://localhost:9000/jmxrmi";

                        String OBJECT_NAME = "com.adobe.granite.ldap:host=(host),port=389,type=Tools";

                        String[] buffer = new String[] { userid, password };

                        Hashtable<String, String[]> attributes = new Hashtable<String, String[]>();

                        attributes.put("jmx.remote.credentials", (String[]) buffer);       

                        MBeanServerConnection server;

                        ObjectName name;

                        try {

                                    server = (MBeanServerConnection) JMXConnectorFactory.connect(new JMXServiceURL(serverUrl), attributes).getMBeanServerConnection();

                                    name = new ObjectName(OBJECT_NAME);

                                    LDAPUserMBean ldap = (LDAPUserMBean) MBeanServerInvocationHandler.newProxyInstance(server, name, LDAPUserMBean.class,false);

                                    ldap.syncUser(userName);

                                   //This is my trying to close the connection

                                    server.unregisterMBean(name);

                        } catch (MalformedObjectNameException e) {

 

                                    LOG.error("Line 79: "+e.getMessage());

                                    e.printStackTrace();

                        } catch (NullPointerException e) {

 

                                    LOG.error("Line 83: "+e.getMessage());

                                    e.printStackTrace();

                        }

                        catch (MalformedURLException e) {

                                    LOG.error("Line 88: "+e.getMessage());

                                    e.printStackTrace();

                        } catch (IOException e) {

                                    LOG.error("Line 90: "+e.getMessage());

                                    e.printStackTrace();

                        } catch (InstanceNotFoundException e) {

                                    LOG.error("Line 94: "+e.getMessage());

                                    e.printStackTrace();

                        } catch (MBeanRegistrationException e) {

                                    LOG.error("Line 97: "+e.getMessage());

                                    e.printStackTrace();

                        }

 

 

            }

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Community_Admin

The most likely cause of this is that you haven't actually enabled remote JMX access. To use remote JMX access, you need to pass several system properties:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9000

 

See http://docs.oracle.com/javase/1.5.0/docs/guide/management/agent.html#p roperties

 

Before using the code above, I'd suggest ensuring that you can connect to the URL using jconsole.

 

Regards,

Justin

1 reply

Community_Admin
Adobe Employee
Community_AdminAdobe EmployeeAuthorAccepted solution
Adobe Employee
October 16, 2015

The most likely cause of this is that you haven't actually enabled remote JMX access. To use remote JMX access, you need to pass several system properties:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9000

 

See http://docs.oracle.com/javase/1.5.0/docs/guide/management/agent.html#p roperties

 

Before using the code above, I'd suggest ensuring that you can connect to the URL using jconsole.

 

Regards,

Justin