简体   繁体   English

码头获取webapp列表

[英]jetty get webapp list

I need to get some server properties from server to my servlet in init method, before any request execute(in init method). 任何请求执行之前 (在init方法中),我需要在init方法中从服务器到servlet获得一些服务器属性。 Actually I neet get list on all working on this server connectors, all working webapps and, most important, - port numbers or connectors. 实际上,我没有收到有关此服务器连接器上所有正在运行的列表,所有正在运行的Web应用程序以及最重要的端口号或连接器的列表。 Desired jetty version - up to 8 version including. 所需的码头版本-最多包括8个版本。

So I need something like org.eclipse.jetty.server.Server , but not for embdeded, but from existing server, on wich my servlet is running. 因此,我需要类似org.eclipse.jetty.server.Server东西,但不是用于嵌入式的,而是从现有服务器运行的servlet。 This information shuld be on jetty as far as webapp deployer operating with this info. 只要使用此信息进行操作的webapp部署程序,此信息就应该存在于码头上。 But I can't find where. 但是我找不到地方。

Enabling JMX in Jetty's start.ini would allow you to use code similar to the following: 在Jetty的start.ini启用JMX将允许您使用类似于以下内容的代码:

final MBeanServer mBeanServerConnection = ManagementFactory.getPlatformMBeanServer();
final String[] portAttribute = new String[] {"port"};

// Jetty 9 MBeans
final ObjectName webappcontext9 = new ObjectName("org.eclipse.jetty.webapp:context=*,type=webappcontext,id=*");
final Set<ObjectName> webappcontexts9 = mBeanServerConnection.queryNames(webappcontext9, null);
for (final ObjectName objectName : webappcontexts9) {
    System.out.println(objectName.getKeyProperty("context"));
}

final ObjectName serverconnector9 = new ObjectName("org.eclipse.jetty.server:context=*,type=serverconnector,id=*");
final Set<ObjectName> serverconnectors9 = mBeanServerConnection.queryNames(serverconnector9, null);
for (final ObjectName objectName : serverconnectors9) {
    System.out.println("listening port for " + objectName.getCanonicalName() + " is " + mBeanServerConnection.getAttributes(objectName, portAttribute).asList().get(0).getValue());
}

// Jetty 8 and 7 MBeans
final ObjectName webappcontext8 = new ObjectName("org.eclipse.jetty.webapp:type=webappcontext,id=*,name=*");
final Set<ObjectName> webappcontexts8 = mBeanServerConnection.queryNames(webappcontext8, null);
for (final ObjectName objectName : webappcontexts8) {
    System.out.println(objectName.getKeyProperty("name"));
}

final ObjectName serverconnector8 = new ObjectName("org.eclipse.jetty.server.nio:type=selectchannelconnector,id=*");
final Set<ObjectName> serverconnectors8 = mBeanServerConnection.queryNames(serverconnector8, null);
for (final ObjectName objectName : serverconnectors8) {
    System.out.println("listening port for " + objectName.getCanonicalName() + " is " + mBeanServerConnection.getAttributes(objectName, portAttribute).asList().get(0).getValue());
}

Of course you'll need to configure Jetty to load the web application that contains this code last or it won't get the complete list of other web applications loaded. 当然,您需要配置Jetty才能最后加载包含此代码的Web应用程序,否则它将无法获取其他Web应用程序的完整列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM