tags:

views:

154

answers:

1

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 configured on a single host, but running on different app servers. We want to append the appropriate jvmroute to the JSESSIONID using a servlet filter.

+1  A: 

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"
Matt Solnit
Thanks Matt. You were so quick with your answer that my manager found your answer via Google.
braveterry