You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Name

OSGi Plugin

Publisher

Donald Brown

License

Open Source (ASL2)

Version

0.1-SNAPSHOT

Compatibility

Struts 2.0.9+

Homepage

OSGi Plugin

Download

SVN

Overview

This plugin is only experimental and hasn't been released yet. It is not ready to be used in production applications.

The Struts 2 OSGi plugin leverages OSGi to allow Struts 2 applications to be divided into multiple jars (bundles) and managed at runtime. It allows you to separate your application into jars (called bundles), each containing a struts.xml file, Action classes, and Velocity (for now) files.

Features

  • Application packages can be divided into bundles
  • Supports Velocity and FreeMarker templates
  • Supports Struts Spring integration

Missing Features

  • No GUI for bundle administration
  • Probably can't access application classes from bundles, including Spring classes
  • No support for any results other than Velocity

Simple Usage

If your actions do not extend ActionSupport, and you are not using Spring then convert your jar that contains Actions, Velocity files, and a struts.xml file into a bundle, add a few lines in the jar's manifest.mf:

Bundle-Activator: org.apache.struts2.osgi.StrutsActivator
Export-Package: com.mycompany.myapp.actions
Bundle-Version: 1.0.0
Bundle-SymbolicName: foo.actions

Now the jar is ready to be deployed. Drop the jar into the /WEB-INF/classes/bundles directory and it will automatically be installed when the application starts up.

Advanced Usage

If your actions extend ActionSupport, or use other classes distributed with Struts, you will have to list their package names in the jar's manifest.mf:

Import-Package: com.opensymphony.xwork2

If you want to use the Spring as the object factory for your actions, then follow these steps:

  1. Place your Spring xml files under /META-INF/spring in the bundle jar file
  2. Copy all these jar files into /WEB-INF/classes/bundles in your application
  3. Make sure that the following properties are set(with the listed values) or not set at all in struts.xml or struts.properties in your application:
    <constant name="struts.objectFactory" value="osgi" />
    <constant name="struts.objectFactory.delegate" value="spring" />
    <constant name="struts.freemarker.manager.classname" value="org.apache.struts2.osgi.BundleFreemarkerManager" />
    
  4. Install the Struts 2 Spring plugin in your application
  5. Add
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    to web.xml and an empty applicationContext.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC 
    	"-//SPRING//DTD BEAN//EN" 
    	"http://www.springframework.org/dtd/spring-beans.dtd">
    <beans></beans>
    
    under /WEB-INF/ in your application. This is a hack, but the Spring support doesn't work otherwise. TODO: find a way around this dirty hack
  6. If you are going to use Velocity results, then add Velocity and Common Digester jars to your application. Using maven:
<dependency>
    <groupId>velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.5</version>
</dependency>

<dependency>
    <groupId>velocity-tools</groupId>
    <artifactId>velocity-tools</artifactId>
    <version>1.3</version>
</dependency>
        
<dependency>
    <groupId>commons-digester</groupId>
    <artifactId>commons-digester</artifactId>
    <version>1.8</version>
</dependency>

Example

Here is how an example architecture would look:

Settings

The following settings can be customized. See the developer guide.

Setting

Description

Default

Possible Values

struts.objectFactory.delegate

The alias of the ObjectFactory to wrap

struts

Any configured alias

Installation

Follow these steps to use this plugin:

  • Copying the plugin jar into your application's /WEB-INF/lib directory.
  • Modify your web.xml to add the osgi configuration provider to your Struts 2 filter:
    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
            <param-name>configProviders</param-name>
            <param-value>org.apache.struts2.osgi.OsgiConfigurationProvider</param-value>
        </init-param>
    </filter>
    

Resources

Version History

Version

Date

Author

Notes

  • No labels