Java Web Application (webapp) is a collection of servlets, HTML pages, classes and other resources bundled together and run on a servlet container. The following items can exist in a webapp:

  • Servlets
  • JavaServer Pages
  • Utility classes
  • Static documents including XHTML and images
  • Client side classes
  • Meta information that describes the webapp

Webapps provided by Magnolia

Magnolia provides the following webapps:
  • Empty: Not actually "empty" but minimal. Contains only basic modules such as core, UI and templating. Use for a streamlined project.
    • Artifact: magnolia-empty-webapp
    • Parent bundle: ce-bundle
  • Bundled: Same as empty plus most community modules. Use for a complete community environment.
    • Artifact: magnolia-bundled-webapp
    • Parent bundle: ce-bundle
  • Enterprise: Same as bundled plus most enterprise modules depending on license. Use for a complete enterprise environment. 
    • Artifact: magnolia-enterprise-webapp
    • Parent bundle: ee-bundle
  • WebLogic: Same as enterprise but optimized for Oracle WebLogic application server.
    • Artifact: magnolia-enterprise-weblogic-webapp
    • Parent bundle: ee-bundle
  • WebSphere: Same as enterprise but optimized for IBM WebSphere application server.
    • Artifact: magnolia-enterprise-websphere-webapp
    • Parent bundle: ee-bundle

Best practice

Each Magnolia webapp belongs to a bundle. You should always use a webapp within a bundle to ensure that Maven dependencies work. Use one of Magnolia's bundles or create your own. CE bundles are free while EE bundles require a license.

Webapp directory structure

The directory structure is the container that holds the components of a webapp. The first step in creating a Magnolia webapp is creating this structure. The following table describes what each directory should contain.

Path

Contents

cache/

Files with cached content.

docroot/

Files extracted from mgnl-files/docroot in the JAR.

logs/

Magnolia log files.

META-INF/

Meta information files, e.g. from Maven.

repositories/

Repository.

templates/

Templates extracted from mgnl-files/templates in the JAR.

tmp/

Temporary work directory.

WEB-INF/

All resources related to the application that are not in the document root. WEB-INF directory is not part of the public document. No files contained in this directory can be served directly to a client.

WEB-INF/bootstrap

Bootstrap files. Empty by default.

WEB-INF/bootstrap/common

Bootstrapped on author and public instances.

WEB-INF/bootstrap/author

Bootstrapped on author instance only.

WEB-INF/bootstrap/public

Bootstrapped on public instance only.

WEB-INF/classes

Class path for manually deployed classes.

WEB-INF/config

Configuration files for repository and properties.

WEB-INF/config/default

Configuration files.

WEB-INF/config/default/magnolia.properties

Properties such as: repository location, persistence manager to be used, should samples be bootstrapped, should installation be done in unattended mode etc.

WEB-INF/config/default/repositories.xml

Defines repository configuration.

WEB-INF/config/default/log4j.xml

Log4j logging configuration.

WEB-INF/config/magnoliaAuthor

Properties used on author instance only.

WEB-INF/config/magnoliaPublic

Properties used on public instance only.

WEB-INF/config/repo-config/typeOfPM.xml

Persistence manager configuration files.

WEB-INF/config/jaas.config

Configuration for authentication and authorization.

WEB-INF/lib

JAR files.

WEB-INF/web.xml

Deployment descriptor. Describes configuration information for the entire web application.

Adding the Magnolia main filter to the webapp

The Magnolia main filter is registered in the web.xml file. The file only defines one filter:

<filter>
    <display-name>Magnolia global filters</display-name>
    <filter-name>magnoliaFilterChain</filter-name>
    <filter-class>info.magnolia.cms.filters.MgnlMainFilter
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>magnoliaFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

The Magnolia main filter will delegate the request to the Magnolia filter chain. The filter is also mapped to forward requests, which means that the Magnolia filter chain will be re-executed on internal forwards.

Adding the Magnolia context listener

In web.xml we also register one listener:

<listener>
    <listener-class>
    info.magnolia.cms.servlets.MgnlServletContextListener
    </listener-class>
</listener>

The listener initializes the system, starts the repository and modules, while the filter handles all requests.

#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))