Search code examples
javajakarta-eejbossjboss-eap-7

How to get the instance name (instance-id) of a JBoss EAP 7 instance serving the request


The JBoss EAP 7 server instance-id is configured on standalone.xml, like this:

<subsystem xmlns="urn:jboss:domain:undertow:3.1" instance-id="node2">

I have and environment with load balancing and sticky session. So, the client receives the JSESSIONID cookies with something like this as value: "ckvLpSqtsN2EjA8WpFqml3UMU5ZIyH2YI29Ir-i.node2".

The question is: I'm on the MBean (with access to FacesContext). How can I get the instance-id of the server that is serving the request? In the above scenario, "node2".

What I already tried:

  1. FacesContext.getCurrentInstance().getExternalContext().getSessionId(true).
    • Doesn't work because it strips the instance-id from the value in JSESSIONID.
  2. Reading the JSESSIONID value from the "Cookie" header (avaiable via HttpServletRequest).
    • Doesn't work when the user doesn't have a session yet (he has no JSESSIONID cookie).

I have considered avoiding the problem by setting the instance id in an environment variable and configuring standalone.xml to define instance-id="${my.instance.name}". The application, then, reads the environment variable to get the instance-id. This is portable accross AS, but is prone to configuration error. Ideally the application should get exactly what is on instance-id and I don't need the application to be portable.

This question is similar to "Getting instance name of a WebSphere app Server" (Getting instance name of a WebSphere app Server), but for a JBoss EAP 7 server.


Solution

  • I'm not sure it is a bug or a feature, but setting instance-id as described in the question does not change jboss.node.name or jboss.server.name:

    • jboss.node.name is set as the host name;
    • jboss.server.name is set as the host name;
    • Cookie JSESSIONID has the instance-id appended on the end.

    However, adding a name="node123" attribute on <server> tag (the top level element on standalone.xml) and removing the instance-id attribute from undertow have the following effects:

    • jboss.node.name is set as "node123";
    • jboss.server.name is set as "node123";
    • Cookie JSESSIONID has "node123" appended at the end.

    This is not exactly the answer I was expecting, but I find it more acceptable than defining a custom property and making sure that property is on "instance-id".