Is there a way to read the jvmRoute value from JBoss server.xml at runtime?
Our JBoss server.xml file has the following line:
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="app_server_01">
Is there a way to get the jvmroute value (in this case app_server_01
) at runtime using Java?
Background
We have session affinity (sticky sessions) configured between our application servers and our Apache servers. JBoss attaches jvmroute (app_server_01) to JSESSIONID. We have multiple applications configured on the same host but running on different application servers. We want to add the appropriate jvmroute to the JSESSIONID using a servlet filter.
source to share
JMX version
You can request MBM Engine 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 to the server.xml file and then just open it with an XML parser.
For example, in JBoss 4.2.2 the server.xml file is located 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 any XML parser you like.
In JBoss 5.1.0, the directory structure has changed, so it will be:
// Incompatible with JBoss 4.x:
System.getProperty("jboss.server.home.dir") + File.separator +
"deploy" + File.separator +
"jbossweb.sar" + File.separator +
"server.xml"
source to share