Name |
OSGi Plugin |
---|---|
Publisher |
|
License |
Open Source (ASL2) |
Version |
0.1-SNAPSHOT |
Compatibility |
Struts 2.0.9+ |
Homepage |
|
Experimental |
Yes |
Download |
Overview
This plugin is only experimental and hasn't been released yet. It is not ready to be used in production applications.
Demo
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/.
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.
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
Add these lines to MANIFEST.MF:
Bundle-Activator: org.apache.struts2.osgi.StrutsActivator Export-Package: com.mycompany.myapp.actions Bundle-Version: 1.0.0 Bundle-SymbolicName: foo.actions Import-Package: com.opensymphony.xwork2
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.
Using Spring
If you want to use the Spring as the object factory for your actions, then follow these steps:
- Place your Spring xml files under
/META-INF/spring
in the bundle jar file - Copy all the bundle jar files into
/WEB-INF/classes/bundles
in your application - Make sure that the following properties are set in struts.xml or struts.properties in your application:
<constant name="struts.objectFactory" value="osgi" /> <constant name="struts.objectFactory.delegate" value="springOsgi" /> <constant name="struts.freemarker.manager.classname" value="org.apache.struts2.osgi.BundleFreemarkerManager" />
- Install the Struts 2 Spring plugin in your application, like in normal Struts 2 applications.
- Configure your web.xml like:
<listener> <?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-execute</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class> </filter> <filter> <filter-name>struts2-prepare</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</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.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> </web-app> </listener> # Add the Spring OSGi dependency to your web app, if you are using maven: {code:xml} <dependency> <groupId>org.springframework.osgi</groupId> <artifactId>spring-osgi-web</artifactId> <version>1.1.2</version> </dependency>
- Download Spring OSGi and copy all the required bundles under /classes/bundles/other. For Struts OSGi 1.1.2, these are the required bundles:
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
Using Velocity
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>
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
@ResultPath("/content") public class HelloWorldAction extends ActionSupport ... }
Settings
The following settings can be customized. See the developer guide.
Setting |
Description |
Default |
Possible Values |
---|---|---|---|
|
The alias of the ObjectFactory to wrap |
|
Any configured alias |
|
Delete all installed bundles when the container starts |
true or false |
|
|
Rul level to start the container |
>=3 |
Building bundles with Maven
See the Maven Bundle Plugin documentation for more details.
<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 |
Notes |
---|