Enterprise Java

Configuring multiple context root for a single webapp – JBoss

Sometime back we made changes to our application to support multiple context root leveraging JBoss capabilities by defining one in jboss-web.xml, as follows:

webapp/WEB-INF/jboss-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
  <context-root>appA</context-root>
  <session-config>
    <session-timeout>10</session-timeout>
  </session-config>
</jboss-web>

And defining the rewrite rule in virtual-server of one of the subsystem in standalone.xml to support other(s) context root, as follows:

jboss-eap/standalone/configuration/standalone.xml:

<subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <virtual-server name="default-host" enable-welcome-root="true">
      <alias name="localhost"/>
      <alias name="example.com"/>
      <rewrite name="rule-1" pattern="^/appB(.*)$" substitution="/appA$1" flags="L"/>
      <rewrite name="rule-2" pattern="^/appC(.*)$" substitution="/appA$1" flags="L"/>
    </virtual-server>
</subsystem>

We were happy to go with the above configuration changes then today while promoting the same configuration to production servers, team came back to us that due to some security policies they cannot enable welcome root to “true” in production and if we make it to “false” multiple context are no more supported.

Then we started looking for different configuration options available for virtual-server to resolve the issue and found we have to configure JBoss with the “/” context to support other context(s) and as our application is having context as “/appA” there is no “/” context available and it’s failing in rewriting the context.

Then we have two immediate fix – first is to redefine our application context to “/” which requires a .war file change and second is to drop another application in JBoss deployment which is having context root as “/” and at point of time when team is in the middle of production deployment we cannot make change in .war file so we chosen the second option over first by deploying another webapp with context-root as “/”.

Arpit Aggarwal

Arpit is a Consultant at Xebia India. He has been designing and building J2EE applications since more than 6 years. He is fond of Object Oriented and lover of Functional programming. You can read more of his writings at aggarwalarpit.wordpress.com
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button