I am trying to get the HeapMemoryUsage a publishing server from an author instance. I have attached the servlet code that is called below.
In the exception, you can see that we get a NullPointerException at line 88, which is JMXConnectorFactory.connect(serviceUrl) .
In Jconsole or running it from a test class (local with the main method), it functions without any problems.
An exception:
29.11.2012 15:01:17.407 *ERROR* [127.0.0.1 [1354197677403] GET /bin/cqdashboard HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable java.lang.NullPointerException at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2327) at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:277) at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248) at com.test.cq.dashboard.servlet.DashboardTestServlet.doGet(DashboardTestServlet.java:88) .....
Code:
String jmxUrl = "service:jmx:rmi:///jndi/rmi://127.0.0.1:43004/jmxrmi"; JMXServiceURL serviceUrl = new JMXServiceURL(jmxUrl); JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl); MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection(); ObjectName on = new ObjectName("java.lang:type=Memory"); CompositeData cd = (CompositeData) mbeanConn.getAttribute(on, "HeapMemoryUsage"); response.getWriter().write(cd.get("used"));
- Do I need to import some packages into an OSGi package?
- Do I need to use other classes provided by adobe?
- Is it possible to do something like this?
Thank you very much in advance
source share