use of org.apache.catalina.core.StandardServer in project tomee by apache.
the class TomcatHelper method getServer.
public static StandardServer getServer() {
StandardServer server = null;
try {
final Class<?> systemInstanceClass = Thread.currentThread().getContextClassLoader().loadClass("org.apache.openejb.loader.SystemInstance");
final Object instance = systemInstanceClass.getDeclaredMethod("get").invoke(null);
server = (StandardServer) systemInstanceClass.getDeclaredMethod("getComponent", Class.class).invoke(instance, StandardServer.class);
} catch (final Exception classNotFoundException) {
// ignored
}
if (server != null) {
TomcatHelper.server = server;
return server;
}
try {
final Class<?> tomcatServerFactory = Class.forName("org.apache.catalina.ServerFactory");
final Method getServerMethod = tomcatServerFactory.getMethod("getServer");
server = (StandardServer) getServerMethod.invoke(null);
} catch (final Exception e) {
// ignored
}
if (server != null) {
TomcatHelper.server = server;
return server;
}
if (TomcatHelper.server != null) {
// try it before next one otherwise we depend on "Catalina" name which can change
return TomcatHelper.server;
}
// if this fails, we'll try and get a reference from the platform mbean server
try {
final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
server = (StandardServer) mbeanServer.getAttribute(new ObjectName("Catalina:type=Server"), "managedResource");
} catch (final Exception e) {
// ignored
}
if (server != null) {
TomcatHelper.server = server;
return server;
}
// if this still fails, that's too bad.
return TomcatHelper.server;
}
Aggregations