1

I have 2 webapps deployed in the same JBoss/Jetty server. In Jetty 5.1.14 I had the following jetty-web.xml which configured one of the apps to run as a virtual host (on the same port):

<Configure class="org.jboss.jetty.JBossWebApplicationContext"> 
  <Call name="addVirtualHost"><Arg>app2.localhost.com</Arg></Call> 
</Configure> 

This worked perfectly fine. Unfortunately, it doesn't work with Jetty 6.1.17 at all. First of all, "JBossWebApplicationContext" seems to now be called "JBossWebAppContext", and secondly the documentation I could find suggests that I should be using a jetty-web.xml that looks like this:

<Configure class="org.jboss.jetty.JBossWebAppContext"> 
  <Set name="VirtualHosts"> 
    <Array type="java.lang.String"> 
      <Item>app2.localhost.com</Item> 
    </Array> 
  </Set> 
</Configure> 

But this doesn't work either. The two webapps deploy without error, but when I try to access the 2nd app under the virtual hostname, it just accesses the first app instead. Both applications are in the root context (this is not negotiable).

How can I make virtual hosts work?

2 Answers2

1

I've solved the problem so far by using this syntax:

<Configure class="org.jboss.jetty.JBossWebAppContext">
  <Set name="VirtualHosts">
    <Array type="java.lang.String">
      <Item>host1.domain.com</Item>
      <Item>host2.domain.com</Item>
    </Array>
  </Set>
</Configure>

The problem turned out to be that ALL webapps need the virtual hosts defined if they are running in the same container. For some reason deploying one WAR with virtual hosts and one without didn't work. This worked fine in Jetty 5 so I'm mystified, however defining virtual hosts files for all applications that need this isn't going to be a problem.

0

You might see if this works for you:

<New class="org.jboss.jetty.JBossWebAppContext">
      <Arg><Ref id="Contexts"/></Arg>
      <Arg><SystemProperty name="jetty.home"/>/webapps/app1.war</Arg>
      <Arg>/</Arg>
      <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
      <Set name="VirtualHosts">
        <Array type="java.lang.String">
          <Item>app1.localhost.com</Item>
        </Array>
      </Set>
    </New>

    <New class="org.jboss.jetty.JBossWebAppContext">
      <Arg><Ref id="Contexts"/></Arg>
      <Arg><SystemProperty name="jetty.home"/>/webapps/app2.war</Arg>
      <Arg>/</Arg>
      <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
      <Set name="VirtualHosts">
        <Array type="java.lang.String">
          <Item>app2.localhost.com</Item>
        </Array>
      </Set>
    </New>

(Adjust the file names & paths as needed, of course)

gharper
  • 5,425
  • 4
  • 29
  • 35
  • I'm not sure how this will work. Does this go into the jetty6-web.xml in the WAR itself? Or somewhere else? Also, in JBoss the WARs are typically deployed in an EAR file which determines the app's context through the application.xml file. – Mr. Shiny and New 安宇 May 26 '09 at 13:00