Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Experimental

Name

OSGi Plugin

Publisher

Donald Brown Apache Software Foundation

License

Open Source (ASL2)

Version

0.1-SNAPSHOT

Compatibility

Struts Bundled with Struts from 2.01.9+ 7 on

Homepage

http://cwiki.apache.org/confluence/display/WW/OSGi+Plugin

Yes

Download

SVN

Wiki Markup
{rate:title=Rating|theme=dynamic}

Overview

Note

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

...

This simple demo contains an empty web application and a bundle jar with 2 actions that use FreeMarker, Velocity and Spring. To use it install the war file struts2-osgi-demo-1.0-SNAPSHOT.war in your server and navigate to: http://localhost/struts2-osgi-demo-1.0-SNAPSHOT/Image Removed.

The Struts 2 OSGi plugin

Excerpt

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.

The demo is available here

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

Missing Features

  • Probably can't access application classes from bundles, including Spring classes

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:

No Format

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:

No Format

Import-Package: com.opensymphony.xwork2

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

...


<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" />

...


<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

...


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC 
	"-//SPRING//DTD BEAN//EN" 
	"http://www.springframework.org/dtd/spring-beans.dtd">
<beans></beans>

...


<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>

Using The Convention Plugin

The Convention plugin will discover actions in bundles in the same way that it discovers them in normal applications. The Convention plugin expects result templates to be (by default) stored under /WEB-INF/content. When packaging actions inside bundles, there won't be a WEB-INF folder, so you must let Convention know where the templates are located. There are two ways of doing so(assuming the templates are under /content):

1. Set the templates location constant in struts.xml (in the application struts.xml, not a bundled struts.xml)

...


<constant name="struts.convention.result.path" value="/content/"/>

2. Using the ResultPath annotation

Code Block

@ResultPath("/content")
public class HelloWorldAction extends ActionSupport
...
}

Example

Here is how an example architecture would look:

Gallery

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:
    Code Block
    langxml
    
    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
            <param-name>packageProviders</param-name>
            <param-value>org.apache.struts2.osgi.OsgiConfigurationProvider</param-value>
        </init-param>
    </filter>
    

Building bundles with Maven

See the Maven Bundle Plugin documentation for more details.

Code Block
langxml
titleExample

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <version>1.4.0</version>
            <configuration>
                <instructions>
                    <manifestLocation>META-INF</manifestLocation>
                    <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>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

Resources

Version History

...

Version

...

Date

...

Author

...

plugin

Excerpt

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.