Versions Compared

Key

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

...

Note

This plugin is only experimental and can change in the future.

This plugin provides support for starting an instance of Apache Felix inside a web application, and scanning installed bundles for Struts configuration. An admin bundle is also provided. It can be used with Glassfish 3 as well (Glassfish 3 based on Apache Felix as well), but in such a way struts.osgi.host must be defined.

Features

  • GUI for bundle administration
  • Web access to Felix Shell
  • Application packages can be divided into bundles
  • Supports Velocity and FreeMarker templates
  • Supports Struts Spring integration
  • Supports integration with the Convention plugin

...

  • Probably can't access application classes from bundles, including Spring classes
  • constant declarations in the bundled XML config files are ignored, these constants need to be set in the application XML config files (struts.xml)

About Run levels

Application bundles should go under /WEB-INF/classes/bundles. Bundles There are two ways of organizing bundles. If third party bundles will not be used, then the application bundles can just be placed under /WEB-INF/classes/bundles. Bundles in this dir will be started in run level 2, the Apache Felix framework's bundles will be loaded in run level 1. Any other bundle If third parties bundles will be used, or you need to start bundles on different run level, create sub dirs under /WEB-INF/classes/bundles/other with numeric names (starting from "2" because "1" is reserved for Felix), which correspond to the run level number. For example bundles under /WEB-INF/classes/bundles/2 will be started in run level 3.2, and bundles under /WEB-INF/classes/bundles/3 will be started in run level 3.

Simple Usage

Add these lines to MANIFEST.MF:

...

  1. Place your Spring xml files under /META-INF/spring in the bundle jar file
  2. Place your Spring xml files under /spring (they must be in the classpath, if you are using maven, put thme under /src/resources/spring) in the application
  3. Copy all the bundle jar files into /WEB-INF/classes/bundles in your application
  4. Make sure that the following properties are set in struts.xml or struts.properties in your application:
    Code Block
    XML
    XML
    <constant name="struts.objectFactory" value="osgi" />
    <constant name="struts.objectFactory.delegate" value="springOsgi" />
    
  5. Configure your web.xml like:
    Code Block
    XML
    XML
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_9" 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>Struts Blank</display-name>
    
        <filter>
            <filter-name>struts2-prepare</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
        </filter>
    
        <filter>
            <filter-name>struts2-execute</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
        </filter>
    
         <filter-mapping>
            <filter-name>struts2-prepare</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <filter-mapping>
            <filter-name>struts2-execute</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <listener>
            <listener-class>org.apache.struts2.osgi.StrutsOsgiListener</listener-class>
        </listener>
    
        <listener>
            <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
        </listener>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <context-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
        </context-param>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>osgibundle:/META-INF/spring/*.xml</param-value>
        </context-param>
        <context-param>
            <param-name>parentContextKey</param-name>
            <param-value>parent-context-bean</param-value>
        </context-param>
    </web-app>
    
  6. Add the Spring OSGi, and Spring Web dependencies to your web app, if you are using maven:
    Code Block
    xml
    xml
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>2.5.5</version>
    </dependency>
    <dependency>
         <groupId>org.springframework.osgi</groupId>
         <artifactId>spring-osgi-web</artifactId>
         <version>1.1.2</version>
    </dependency>
    
  7. Download Spring OSGi and copy all the required bundles under /classes/bundles/other2. For Struts OSGi 1.1.2, these are the required bundles:
    No Format
    com.springsource.org.aopalliance-1.0.0.jar
    com.springsource.org.apache.commons.logging-1.1.1.jar
    org.springframework.aop-2.5.5.A.jar
    org.springframework.beans-2.5.5.A.jar
    org.springframework.context-2.5.5.A.jar
    org.springframework.core-2.5.5.A.jar
    org.springframework.osgi.core-1.1.2.A.jar
    org.springframework.osgi.extender-1.1.2.A.jar
    org.springframework.osgi.io-1.1.2.A.jar
    org.springframework.osgi.web-1.1.2.A.jar
    org.springframework.web-2.5.5.A.jar
    
  8. Put your bundles under /classes/bundles/3

Using Velocity

If you are going to use Velocity results, then add Velocity and Common Digester jars to your application. Using maven:

...

An admin bundle is distributed with struts, which provides a simple interface to list the installed bundles. Using this interface the bundles can be stopped, started and updated (reloaded from the file system). This interface also provides information on the installed bundles, like OSGi metadata, and a list of packages and actions loaded from each bundle. An interactive AJAX shell is also available, which is just a web interface to the Apache Felix Shell. To use this bundle, just copy the jar file to /bundles (same place where the application bundles are installed) and open http://localhost:PORT/CONTEXT/osgi/admin/Image Removed (replace PORT and context)

...

Setting

Description

Default

Possible Values

struts.objectFactory.delegate

The alias of the ObjectFactory to wrap

struts

struts.objectFactory.delegate

The alias of the ObjectFactory to wrap

struts

Any configured alias

Any configured alias

The following setting must be set as context parameters in web.xml, because they are used by the StrutsOsgiListener, for example:

Code Block
xml
xml

<context-param>
    <param-name>struts.osgi.clearBundleCache</param-name>
    <param-value>false</param-value>
</context-param>

If you are running your application on Glassfish 3 (which already contains Apache Felix) you must specify struts.osgi.host, like belowThe following setting must be set as context parameters in web.xml, because they are used by the StrutsOsgiListener, for example:

Code Block
xml
xml
<context-param>
    <param-name>struts.osgi.clearBundleCache<host</param-name>
    <param-value>false<value>Glassfish</param-value>
</context-param>

...

Building bundles with Maven

See Jar files can be turned into bundles using the Maven Bundle Plugin documentation for more details. like:

Code Block
langxml
titleMaven Bundle Plugin Example
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <version>2.0.0</version>
            <configuration>
                <instructions>
                    <manifestLocation>META-INF</manifestLocation>
                    <Struts2-Enabled>true</Struts2-Enabled>
                    <Export-Package>org.apache.struts2.osgi.demo</Export-Package>
                    <Import-Package>*,com.opensymphony.xwork2</Import-Package>
                    <Bundle-Activator>org.apache.struts2.osgi.StrutsActivator</Bundle-Activator>
                    <Spring-Context>*;create-asynchronously:=false</Spring-Context>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

...