开发者

Is there a way to read the jvmRoute value from the JBoss server.xml at runtime?

Our JBoss server.xml file has this line:

 <Engine name="jboss.web" defaultHost="localhost" jvmRoute="app_server_01">

Is there any way to get the jvmroute value (in this case app_server_01) at runtime using Java?

Background

We've got session affinity (sticky sessions) configured between our app servers and Apache servers. JBoss appends the jvmroute (app_server_01) to the JSESSIONID. We have multiple apps c开发者_开发问答onfigured on a single host, but running on different app servers. We want to append the appropriate jvmroute to the JSESSIONID using a servlet filter.


JMX version

You can query the Engine's MBean to get this information:

  MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
  String jvmRoute = (String)server.getAttribute(new ObjectName("jboss.web:type=Engine"), "jvmRoute");

XML Parsing version

Another option is to use the "jboss.server.home.dir" system property to find the full path of the server.xml file, and then just open it using an XML parser.

For example, in JBoss 4.2.2, the server.xml file is at:

System.getProperty("jboss.server.home.dir") + File.separator +
  "deploy" + File.separator +
  "jboss-web.deployer" + File.separator +
  "server.xml"

You can load this file into whatever XML parser you like.

In JBoss 5.1.0, the directory structure has changed, so it would be:

// Incompatible with JBoss 4.x:
System.getProperty("jboss.server.home.dir") + File.separator +
  "deploy" + File.separator +
  "jbossweb.sar" + File.separator +
  "server.xml"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜