6

I have a problem. I have two web apps deployed as wars. Let's call them app1.war and app2.war.

I would like app1.war to be accessed at the URL www.website.com and I would like app2.war to be accessible as www.website.com/anotherapp. I have my domain name ready.

Virtual hosting does not seem to help here.

I am running JBoss App Server 5.1 and Seam 2.2.0. I am working on integrating a forum (deployed as a war) with my app (deployed as another war) and therefore need to use single sign on and therefore would like the URL formats described above for easy passing of sso cookies.

Thanks for any insights.

-Charles.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
donakalz
  • 85
  • 1
  • 1
  • 6

4 Answers4

4

You need to do such things:

  1. Configure your JBoss to use virtual host with the www.website.com name.

    You can do it by editing server.xml from jbossweb.sar directory. In short you have to set up another Host directive.

  2. You have to setup your war application. You can do it by creating or editing jboss-web.xml file (it should be placed in WEB-INF directory). In that file you can configure what virtual host should be used and under what context.

Example of that file for app1.war

<jboss-web>
   <context-root>/</context-root>
   <virtual-host>website</virtual-host>
</jboss-web>

Example of that file for app2.war

<jboss-web>
   <context-root>/anotherapp</context-root>
   <virtual-host>website</virtual-host>
</jboss-web>

More info you can find in that post Hosting Multiple Domains With JBoss

Lukasz Stelmach
  • 5,281
  • 4
  • 25
  • 29
  • fantastic! this is what I needed. I already had jboss-web files for both applications but it hadn't occured to me that it was possible for both of them to work with the same virtual host. So for app1 I had a virtual host of 'app1' and for app2.war, virtual host was 'app2'. I just changed both virtual-host entries to that of app1 and specified the context for app2 into what I needed. Thanks a lot. Clean solution which I needed. – donakalz Feb 11 '11 at 14:20
1

Haven't used JBoss in a while or Seam at all but if it's like most application servers there will be an XML file of some description where you match URL patterns to apps. Check you docs for details but I think you want web.xml and a few servlet entries like:

<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.seam</url-pattern>
</servlet-mapping>

Change the url-pattern and servlets accordingly.

SpliFF
  • 38,186
  • 16
  • 91
  • 120
  • Hmmm. well...that is absolutely not what I am looking for. I know about servlets and url-patterns. Perhaps I should try again. I have two seam web apps. Each app runs pretty fine. Each app consists of jsf pages, servlets and what not. Thats not the problem. I have pointed my domain name, www.domain.com (i have substituted 'domain' for my actual site name) to app1.war using jboss virtual hosting mechanism. Everything is great. Now app2.war is another application (jsp) which is served through the domain, app2.domain.com (also using virtual hosting native to jboss app server). – donakalz Feb 10 '11 at 22:43
  • Now I have an authentication mechanism in app1.war and users' information is stored in a database. I would like to implement sso to automatically log users into app2.war (app2.domain.com). However, I would like to take advantage of a major functionality of cookies. Cookies stored for a domain, eg www.domain.com are also accessible to every request for resources under that domain. for example, www.domain.com/foo.html or www.domain.com/foo/bar.html are able to access the same cookies. – donakalz Feb 10 '11 at 22:43
  • With my current setup of both applications, the first app would create cookies under the domain www.domain.com while the second would create cookies under app2.domain.com. This is a problem for me since a cookie written to a client's browser by app1 (www.domain.com) would not be accessible to app2( app2.domain.com). Now I arrive at the question again. Does someone know an elegant way to access app2 as a subpath of app1. So I would like to access app1 as www.domain.com and app2 as www.domain.com/app2. – donakalz Feb 10 '11 at 22:44
  • Obviously I could just integrate all the pages and code from app2 into app1 (thereby having a single app) and have the pages of app2 accessed from a directory (named 'app2' ) under the web root of app1. This approach just seems very dirty to me. However, if I am unable to solve this problem, I'll have to do it the dirty way. – donakalz Feb 10 '11 at 22:45
1

I would like app1.war to be accessed at the following url: www.website.com and I would like app2.war to be accessible as www.website.com/anotherapp. Of course I have my domain name ready.

The easiest way to achieve your specific use case is to deploy app1.war to ROOT.war and app2.war to anotherapp.war in the /deploy directory. This works best when you use exploded war deployments.

If you do not want to rename your exploded war folders, you can use symlinking.

rajeshj
  • 107
  • 1
  • 6
  • Yes I know about that trick. However I do not want to remove the existing ROOT.war in the /deploy directory of my jboss server home. This is because ROOT.war is the app with the page containing links to admin console, jmx console and so on. Lets just say that I would like to be able to delete my app1.war and app2.war, disable virtual hosting and essentially have the container as it was (fresh jboss). Right now, I map admin.domain.com to my ROOT.war. This is not the problem. I just need to know if someone has a solution for my use case as I described it. – donakalz Feb 11 '11 at 08:48
1

To have the same session cookie for all web apps in the servlet container, add SessionCookie to deploy/jbossweb.sar/context.xml:

<Context>
 ...
 <SessionCookie path="/" />
</Context>

If you don't want to rename ROOT.war to something else and let app1.war get the ROOT.war-name (I don't understand why not), maybe you can do some apache redirect/rewrite/proxy stuff to hide the real context root of app1

  • because I do not want to unnecessarily modify my jboss folder. I want to be able to deploy apps to it, use it, remove the apps and regain the original state of the server. Furthermore, people tend to delete ROOT.war and/or rename their apps to ROOT.war just to enable that app gain the privilege of being the root application on the server (typically accessed by localhost or www.website.com if you have pointed your domain to your jboss server ip ). You can simply use virtual hosting instead. Your answer with SessionCookie tag seems interesting. I'll test things out and report back. – donakalz Feb 11 '11 at 10:21