HomeDocumentation > Sample applications > Exposing Web applications on distinct ports
{scrollbar}

top

You may wish to run different web applications on different ports. For example, you might want an admin application on a different port than a production application.

This example also demonstrates how to start listening on the ports after the web applications are fully deployed and ready to be used.

Tomcat example

In non-geronimo tomcat, you can do this by including two or more server definitions in your server.xml file, and including the applications in the server elements. It's possible to set up essentially the same structure in geronimo.

Here's the sample app:

http://issues.apache.org/jira/secure/attachment/12334215/appPerPort.ear

If you unpack it you can deploy it inplace with something like

java -jar bin/deployer.jar deploy --inPlace appPerPort.ear
(Assuming you have logged in to the deployer previously)

Here's the plan, with some explanation. The first thing that happens is that the gbeans in the ear scope start; this starts 2 tomcat servers but no connectors for them.

Then the three web apps start in order. The first two are actual web apps with content. Note that each has a web-container gbean-link to the appropriate web container that just started.

The third web app has the connector gbeans for the web containers we started. Note that the web apps are modules as well as the ear itself, and that web modules start in the same order as they are listed in application.xml. Recall also that in order for a module to start, all its gbeans must start completely. Therefore we have first the tomcat containers starting, then the web apps deployed onto different tomcat containers, and finally once the web apps are completely started, the connectors that open listeners on the two different ports.

Putting the connector gbeans into an otherwise empty web app succeeds in delaying opening the ports until after the applications are ready, but is not exactly elegant. If you are willing to have more than one module, you can put the connector gbeans into a service plan and list the ear as a dependency to get the same effect.

xmlsolidgeronimo-application.xml <?xml version="1.0" encoding="UTF-8"?> <!-- Copyright 2004-2005 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- $Rev: 395697 $ $Date: 2006-04-20 14:07:47 -0700 (Thu, 20 Apr 2006) $ --> <application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.1"> <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1"> <dep:moduleId> <dep:groupId>geronimo</dep:groupId> <dep:artifactId>appPerPort-tomcat</dep:artifactId> <dep:version>1.1-SNAPSHOT</dep:version> <dep:type>car</dep:type> </dep:moduleId> <dep:dependencies> <dep:dependency> <dep:groupId>geronimo</dep:groupId> <dep:artifactId>tomcat</dep:artifactId> <dep:type>car</dep:type> </dep:dependency> </dep:dependencies> <dep:hidden-classes/> <dep:non-overridable-classes/> </dep:environment> <module> <web>war1.war</web> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.1"> <context-priority-classloader>false</context-priority-classloader> <web-container> <gbean-link>TomcatWebContainer1</gbean-link> </web-container> </web-app> </module> <module> <web>war2.war</web> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.1"> <context-priority-classloader>false</context-priority-classloader> <web-container> <gbean-link>TomcatWebContainer2</gbean-link> </web-container> </web-app> </module> <module> <web>connectors.war</web> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/tomcat-1.1"> <context-priority-classloader>false</context-priority-classloader> <gbean name="TomcatWebConnector1" class="org.apache.geronimo.tomcat.ConnectorGBean"> <attribute name="name">HTTP</attribute> <attribute name="host">localhost</attribute> <attribute name="port">8081</attribute> <attribute name="maxHttpHeaderSizeBytes">8192</attribute> <attribute name="maxThreads">150</attribute> <attribute name="minSpareThreads">25</attribute> <attribute name="maxSpareThreads">75</attribute> <attribute name="hostLookupEnabled">false</attribute> <attribute name="redirectPort">8453</attribute> <attribute name="acceptQueueSize">100</attribute> <attribute name="connectionTimeoutMillis">20000</attribute> <attribute name="uploadTimeoutEnabled">false</attribute> <reference name="TomcatContainer"> <name>TomcatWebContainer1</name> </reference> </gbean> <gbean name="TomcatWebConnector2" class="org.apache.geronimo.tomcat.ConnectorGBean"> <attribute name="name">HTTP</attribute> <attribute name="host">localhost</attribute> <attribute name="port">8082</attribute> <attribute name="maxHttpHeaderSizeBytes">8192</attribute> <attribute name="maxThreads">150</attribute> <attribute name="minSpareThreads">25</attribute> <attribute name="maxSpareThreads">75</attribute> <attribute name="hostLookupEnabled">false</attribute> <attribute name="redirectPort">8453</attribute> <attribute name="acceptQueueSize">100</attribute> <attribute name="connectionTimeoutMillis">20000</attribute> <attribute name="uploadTimeoutEnabled">false</attribute> <reference name="TomcatContainer"> <name>TomcatWebContainer2</name> </reference> </gbean> </web-app> </module> <gbean name="TomcatWebContainer1" class="org.apache.geronimo.tomcat.TomcatContainer"> <attribute name="catalinaHome">var/catalina</attribute> <reference name="EngineGBean"> <name>TomcatEngine1</name> </reference> <reference name="ServerInfo"> <name>ServerInfo</name> </reference> <reference name="WebManager"> <name>TomcatWebManager</name> </reference> </gbean> <gbean name="TomcatEngine1" class="org.apache.geronimo.tomcat.EngineGBean"> <attribute name="className">org.apache.geronimo.tomcat.TomcatEngine</attribute> <attribute name="initParams"> name=Geronimo1 </attribute> <reference name="DefaultHost"> <name>TomcatHost1</name> </reference> <references name="Hosts"> <pattern> <name>TomcatHost1</name> </pattern> </references> <reference name="RealmGBean"> <name>TomcatJAASRealm</name> </reference> </gbean> <gbean name="TomcatHost1" class="org.apache.geronimo.tomcat.HostGBean"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams"> name=localhost appBase= workDir=work </attribute> </gbean> <gbean name="TomcatWebContainer2" class="org.apache.geronimo.tomcat.TomcatContainer"> <attribute name="catalinaHome">var/catalina</attribute> <reference name="EngineGBean"> <name>TomcatEngine2</name> </reference> <reference name="ServerInfo"> <name>ServerInfo</name> </reference> <reference name="WebManager"> <name>TomcatWebManager</name> </reference> </gbean> <gbean name="TomcatEngine2" class="org.apache.geronimo.tomcat.EngineGBean"> <attribute name="className">org.apache.geronimo.tomcat.TomcatEngine</attribute> <attribute name="initParams"> name=Geronimo2 </attribute> <reference name="DefaultHost"> <name>TomcatHost2</name> </reference> <references name="Hosts"> <pattern> <name>TomcatHost2</name> </pattern> </references> <reference name="RealmGBean"> <name>TomcatJAASRealm</name> </reference> </gbean> <gbean name="TomcatHost2" class="org.apache.geronimo.tomcat.HostGBean"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams"> name=localhost appBase= workDir=work </attribute> </gbean> </application>

Jetty

Jetty web apps have the same ability to specify which jetty container should be used, however I don't have a sample plan to demonstrate that it works.

There may be a simpler way to limit which ports an app in a jetty web container is available on, in which case for jetty one would not need 2 jetty containers. This requires further investigation.