3

I would like to access Server and Connectors from within my webapp. Furthermore, I need to launch this webapp from embedded Tomcat. Here is how I boot tomcat:

Tomcat tomcat = new Tomcat();
tomcat.setPort(port);
StandardServer server = (StandardServer) tomcat.getServer();
server.addLifecycleListener(new AprLifecycleListener());
tomcat.addWebapp("/", webapp.getAbsolutePath());
tomcat.start();
tomcat.getServer().await();

When I use the typical example for accessing the Server via JMX1:

import javax.management.*;
import org.apache.catalina.Server;

MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName name = new ObjectName("Catalina", "type", "Server");
Server server = (Server) mBeanServer.getAttribute(name, "managedResource");

I get:

Caused by: javax.management.InstanceNotFoundException: Catalina:type=Server
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)

I assume this is because I am failing to bootstrap JMX somehow.

Community
  • 1
  • 1
Adam Rabung
  • 5,232
  • 2
  • 27
  • 42

2 Answers2

2

Looks like JMX is running fine, it's the name I used for lookup that is the problem. Should have been:

ObjectName name = new ObjectName("Tomcat", "type", "Server");

instead.

Adam Rabung
  • 5,232
  • 2
  • 27
  • 42
0

It is possible by using the PR_JVMOPTIONS. I got it resolved by using the following configuration parameters in my embedded tomcat installation service file.

set PR_JVMOPTIONS=-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false;-Dcom.sun.management.jmxremote.port=9111
Praveen
  • 1,791
  • 3
  • 20
  • 33