Multiple context root for single war deployment jboss-EAP-6.1

4.5k views Asked by At

In my Jboss-EAP-6.1 I have deployed a .war called 'myRealWebApp.war' I can access my app with this url - http://mywebsite.com/myRealWebApp

I want to configure my webapp 'myRealWebApp' with multiple context root. I mean if I access

http://mywebsite.com/appA
http://mywebsite.com/appB
http://mywebsite.com/appC

those 3 contexts 'appA','appB','appC' points to myRealWebApp.war (One single war deployed)

Is there anyway I can archive this?

Thanks.

Edit: Solution found: I added this code to my standalone-full.xml

   <subsystem xmlns="urn:jboss:domain:web:1.4" 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="^/appA(.*)$" substitution="/myRealWebApp$1" flags="L"/>
            <rewrite name="rule-2" pattern="^/appB(.*)$" substitution="/myRealWebApp$1" flags="L"/>
            <rewrite name="rule-3" pattern="^/appC(.*)$" substitution="/myRealWebApp$1" flags="L"/>
        </virtual-server>
    </subsystem>

The key is the flags="L"

Thanks

2

There are 2 answers

1
iullianr On BEST ANSWER

You can achieve this by configuring an http server in front of the jboss (like an Apache server) and using redirect rulea to translate all the other urls to the one you have configured your application with. It might be that jboss also has a apache module for integration ,but the basic principle remains. Usually it is the recommendec way not to expose directly a jboss or other app server in production, but using http server in front of it ( you can serve static content from http server, you can balance requests, etc)

1
Arpit Aggarwal On

Adding to the Solution shared by OP, this is what I did to achieve multiple context for the single deployed.

Configured one context root in app/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>

Added rewrite rule in 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>