Reputation: 35
How to get the list of webapps deployed in Tomcat using JMX? The URLs are different for various versions of tomcat (eg. in tomcat v6, the URL: "http://:8080/manager/list" will give the list of webapps deployed). The intention is calculate the sum of all activeSessions in Tomcat. We have calculate the sum of each webapp and arrive at the final number.
Upvotes: 1
Views: 3538
Reputation: 35
This is the solution that worked for us:
Set<ObjectName> names = mbeanServer.queryNames(new ObjectName("Catalina:type=Host,*"), null);
Set<String> hostNames = new HashSet<String>();
for (ObjectName on : names) {
hostNames.add(on.getKeyProperty("host"));
}
for (String str : hostNames) {
ObjectName[] webapps = (ObjectName[]) mbeanServer.getAttribute(new ObjectName("Catalina:type=Host,host=" + str), "children");
for (ObjectName ob : webapps) {
String[] appSpl = ob.getKeyProperty("name").split("//localhost");
webappNames.add(appSpl[1]);
}
}
Upvotes: 1