...
Code Block |
---|
@ResultPath("/content") public class HelloWorldAction extends ActionSupport ... } |
The OSGi interceptor
The OSGi plugins defines the osgi
interceptor and osgiStack
(defaultStack
plus the osgi
interceptor) in the package osgi-default
. This interceptor will check the action and if it implements org.apache.struts2.osgi.interceptor.BundleContextAware
, it will invoke setBundleContext(BundleContext bundleContext) on the action, passing the BundleContext of the OSGi container. The interceptor also checks if the class implements one or many org.apache.struts2.osgi.interceptor.ServiceAware<T>
interfaces, and for each one, it will call setServices(List<T> services), where T is the type of a service published in the OSGi container. For example, lets assume an installed bundle publishes a service with the interface BookPriceLookup
, to get all the instances of this service, an action would look like:
Code Block |
---|
public class BookPriceAction extends ActionSupport ServiceAware<BookPriceLookup> {
private List<BookPriceLookup> services;
public void setServices(List<BookPriceLookup> services) {
this.services = services;
}
}
|
Warning | |||||||
---|---|---|---|---|---|---|---|
Keep in mind that the interceptor is not defined in the default struts package, so when using Convention, you need to specify the parent package as "osgi-default", either using annotations (@ParentPackage), or XML(this XML fragment must be in the struts XML config file in the application, not the bundle's, this is a current limitation of the OSGi plugin):
|
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 |
The following setting must be set as context parameters in web.xml, because they are used by the StrutsOsgiListener, for example:
Code Block | ||||
---|---|---|---|---|
| ||||
<context-param>
<param-name>struts.osgi.clearBundleCache</param-name>
<param-value>false</param-value>
</context-param>
|
Setting | Description | Default | Possible Values |
---|---|---|---|
| Delete all installed bundles when the container starts | true | true or false |
| Run level to start the container | 3 | >=3 |
| Log level for Apache Felix | 1 (Error) | 1 = error, 2 = warning, 3 = information, and 4 = debug |
Building bundles with Maven
...