Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The root XML element in the geronimo-web-2.0.1.xsd schema is the <web-app> element. The top-level XML elements of the <web-app> root element are described in the sections below. The deployment plan should always use the Web application namespace, and it typically requires elements from Geronimo System, Geronimo Naming, Geronimo Security, Geronimo Application, and Geronimo Persistence namespaces. Additionally, it has a required attribute to identify its configuration name, and an optional attribute to select a parent configuration. A typical deployment for geronimo-web.xml can be presented as follows:

Code Block
xml
xml
titlegeronimo-web.xml Example
borderStylesolidxml
<web:web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" 
             xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2" 
             xmlns:name="http://geronimo.apache.org/xml/ns/naming-1.2" 
             xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-2.0" 
             xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" 
             xmlns:pers="http://java.sun.com/xml/ns/persistence">
             ...
</web:web-app>

...

An example geronimo-web.xml file is shown below using the <sys:environment> element:

Code Block
xml
xml
borderStylesolid
title<sys:environment> Examplexml
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

    <sys:environment>

        <sys:moduleId>
            <sys:groupId>default</sys:groupId>
            <sys:artifactId>geronimo-web-6</sys:artifactId>
            <sys:version>1.0</sys:version>
            <sys:type>car</sys:type>
        </sys:moduleId>

        <sys:dependencies>
            <sys:dependency>
                <sys:groupId>org.apache.geronimo.configs</sys:groupId>
                <sys:artifactId>tomcat6</sys:artifactId>
                <sys:version>2.1.1</sys:version>
                <sys:type>car</sys:type>
            </sys:dependency>

            <sys:dependency>
                <sys:groupId>default</sys:groupId>
                <sys:artifactId>geronimo-web-5</sys:artifactId>
                <sys:version>1.0</sys:version>
                <sys:type>car</sys:type>
            </sys:dependency>

        </sys:dependencies>

        <sys:hidden-classes/>
        <sys:non-overridable-classes/>
        <sys:inverse-classloading/>
        <sys:suppress-default-environment/>

    </sys:environment> 
   
</web-app>

...

This element is used to specify a reference to a web-container specific GBean either via a pattern to the moduleId of the configuration, or via a link to a GBean. As an example, consider the case where it is required to run a web application in a Tomcat container using a dedicated port such that no other web application is allowed to use that port. To accomplish this a separate GBean would have to be defined for the "Container", "Engine", "Host", and "Connector", and a <naming:web-container> element would have to be used to reference this new Tomcat container. An example geronimo-web.xml file is shown below:

Code Block
xml
xml
borderStylesolid
title<naming:web-container> Examplexml
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
         xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

    <sys:environment>
        <sys:moduleId>
            <sys:groupId>default</sys:groupId>
            <sys:artifactId>geronimo-web-6</sys:artifactId>
            <sys:version>1.0</sys:version>
            <sys:type>car</sys:type>
        </sys:moduleId>
        <sys:dependencies/>
        <sys:hidden-classes/>
        <sys:non-overridable-classes/>
        <sys:inverse-classloading/>
        <sys:suppress-default-environment/>
    </sys:environment> 

    <context-root>contextroot</web:context-root>

    <work-dir>workdir</web:work-dir>   

    <naming:web-container>

        <naming:gbean-link>TomcatWebAppContainer</naming:gbean-link>

    </naming:web-container>

    <gbean name="TomcatWebAppContainer" 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="TomcatWebAppEngine" class="org.apache.geronimo.tomcat.EngineGBean">
        <attribute name="className">org.apache.geronimo.tomcat.TomcatEngine</attribute>
        <attribute name="initParams">
            name=WASCE
        </attribute>
        <reference name="DefaultHost">
            <name>TomcatHost1</name>
        </reference>
        <references name="Hosts">
            <pattern>
                <name>TomcatHost</name>
            </pattern>
        </references>
        <reference name="RealmGBean">
            <name>TomcatJAASRealm</name>
        </reference>
        <reference name="TomcatValveChain">
            <name>FirstValve</name>
        </reference>
        <reference name="LifecycleListenerChain">
            <name>FirstListener</name>
        </reference>
    </gbean>

    <gbean name="TomcatWebAppHost" 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="TomcatWebAppConnector" class="org.apache.geronimo.tomcat.ConnectorGBean">
        <attribute name="name">HTTP</attribute>
        <attribute name="host">localhost</attribute>
        <attribute name="port">8081</attribute>                             <!-- Use port 8081 instead of the default of 8080 -->
        <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>TomcatWebAppContainer</name>
        </reference>
    </gbean>

</web-app>

...

Which to use is left to the discretion of the user. If a web application is meant to be deployed to both Tomcat and Jetty, then the generic schema is typically used, and if a web application is meant to be deployed to only Tomcat or Jetty, then one of the container-specific schemas is typically used. However, another option is available since the generic schema allows the inclusion of the container-specific elements found in the container-specific schemas by using the <container-config> element. This allows the user to use the generic schema even when the web application requires container-specific configuration for Tomcat or Jetty (or both). An example geronimo-web.xml file is shown below using the <container-config> element to configure the Tomcat web container. Note that the <host>, <valve-chain>, and <tomcat-realm> elements are understood only by the Tomcat container, not Jetty:

Code Block
xml
xml
borderStylesolid
title<container-config> Examplexml
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">

    <sys:environment>
        <sys:moduleId>
            <sys:groupId>default</sys:groupId>
            <sys:artifactId>geronimo-web-6</sys:artifactId>
            <sys:version>1.0</sys:version>
            <sys:type>car</sys:type>
        </sys:moduleId>
    </sys:environment> 

    <container-config>

        <tomcat xmlns="http://geronimo.apache.org/xml/ns/web/tomcat/config-1.0">
            <host>testhost.com</host>
            <valve-chain>FirstValve</valve-chain>
            <tomcat-realm>TomcatRealm</tomcat-realm>
        </tomcat>

    </container-config>

</web-app>

...

The <sec:security> element groups the security role mapping settings for the web application. This is an optional element, but if it is present all the web modules must make the appropriate access checks as outlined in the JACC specification. This element includes the <role-mapping> section that references the role(s) defined in the <security-role> element in the web.xml file. An example web.xml and corresponding geronimo-web.xml file is shown below with the "admin" role name defined in the web.xml is referenced in the geronimo-web.xml:

Code Block
xml
xml
borderStylesolid
title<security> web.xml Examplexml
<web-app version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Geronimo Remote Deployer</display-name>

    <description>
        Receives file upload requests from the deployer when running on a different machine
        than the Geronimo server.
    </description>

    <servlet>
        <display-name>File Upload</display-name>
        <servlet-name>file-upload</servlet-name>
        <servlet-class>org.apache.geronimo.deployment.remote.FileUploadServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>file-upload</servlet-name>
        <url-pattern>/upload</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Upload Servlet</web-resource-name>
            <url-pattern>/upload</url-pattern>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>admin</role-name>
        </auth-constraint>
    </security-constraint>

    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Geronimo File Upload</realm-name>
    </login-config>

    <security-role>
        <role-name>admin</role-name>
    </security-role>
</web-app>
Code Block
xml
xml
borderStylesolid
title<security> geronimo-web.xml Examplexml
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0"
         xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
         xmlns:cfg="http://geronimo.apache.org/xml/ns/deployment-1.2">

    <dep:environment>
      <dep:moduleId>
        <dep:groupId>org.apache.geronimo.plugins</dep:groupId>
        <dep:artifactId>geronimo-remote-deploy</dep:artifactId>
        <dep:version>2.1.1</dep:version>
      </dep:moduleId>
      <dep:dependencies/>
      <dep:hidden-classes/>
      <dep:non-overridable-classes/>
    </dep:environment>

    <context-root>/remote-deploy</context-root>

    <security-realm-name>geronimo-admin</security-realm-name>

    <sec:security>
        <sec:role-mappings>
            <sec:role role-name="admin">
                <sec:principal class="org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal"
                               name="admin" designated-run-as="true"/>
            </sec:role>
        </sec:role-mappings>
    </sec:security>

</web-app>

...

An example geronimo-web.xml file is shown below using the <abstract-naming-entry> element to reference a persistence unit:

Code Block
xml
xml
borderStylesolid
title<abstract-naming-entry> Examplexml
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
         xmlns:naming="http://geronimo.apache.org/schemas-2.1/docs/geronimo-naming-1.2">

    <sys:environment>
        <sys:moduleId>
            <sys:groupId>default</sys:groupId>
            <sys:artifactId>geronimo-web-6</sys:artifactId>
            <sys:version>1.0</sys:version>
            <sys:type>car</sys:type>
        </sys:moduleId>
    </sys:environment> 

    <naming:abstract-naming-entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="naming:persistence-unit-refType">

        <naming:persistence-unit-ref-name>messagedrivenbean-persistenceunitref-unitrefname</naming:persistence-unit-ref-name>
        <naming:persistence-unit-name>messagedrivenbean-persistenceunitref-unitname</naming:persistence-unit-name>
        <naming:pattern>
            <naming:groupId>messagedrivenbean-persistenceunitref-pattern-groupid</naming:groupId>
            <naming:artifactId>messagedrivenbean-persistenceunitref-pattern-artifactid</naming:artifactId>
            <naming:version>messagedrivenbean-persistenceunitref-pattern-version</naming:version>
            <naming:module>messagedrivenbean-persistenceunitref-pattern-module</naming:module>
            <naming:name>messagedrivenbean-persistenceunitref-pattern-name</naming:name>
        </naming:pattern>
    </naming:abstract-naming-entry>

</web-app>

...