Pax Wicket - 3.0.0

Pax Wicket - 3.0.0

Release 3.0.0 (Wicket 6, 2013-06-21)

Overview

The 3.0.0 release of Pax Wicket includes quite a ton of enhancements, new features and bug fixes. Just to name a view: Delayed injection using future, Very basic websocket support and JSR330 support. In addition it is no longer required to add some unrelated dependecies manually to your manifests for cglib and pax.wicket.proxy. To finish everything various error messages had been enhanced to make understanding the errors easier and 8 bugs had been fixed.

-Enjoy

The Pax Wicket Team

Noticeable Improvements/New Features compared to 2.x

 This chapter describes all the new goodness compared to the 2.x release.

Aggregation Support for "Plain" Injection

"Regular" OSGi service injection supports now the following new feature:

@Inject private Iterable<PageProvider> iterable;
@Inject private Collection<PageProvider> collection;
@Inject private Set<PageProvider> set;
@Inject private List<PageProvider> list;

You should just take the following implications in mind:

  • For performance and consistency the Iterable Version is preferable in all cases
  • Because of the dynamic nature of the OSGi Framework you should consider each Collection like a "WeakHashmap", items may vanish at any time and methods might return null for objects fetched from the collection if the service has gone away. Even with syncronization a previous fetched size might not reflect reliable the actuall iteration size, so use foreach whenever possible!
  • all higher level collection methods might be rather inefficent (like contains), because they must first make a snapshot and then iterate over all service what involves fetching/unfetching
  • all modification methods throw UnsupportedOperationException
  • the List get() method currently is rather expensive and is hard to master because size can change every time

Besides this, the following OSGi related topics must be considered:

  • As soon as the service is successfully fetched, its is freed, that means the use count is decremented, so users should take care to not keep reference longer than needed to prevent stale references
  • Services that perform cleanup when the usecount reaches zero might behave unespected (you might need a servicetracker then that just trakcs the service to keep it alive)
  • In case of DeclarativeServices it should be keept in mind that components gets activated/deactivated if the have not set immediate=true and no one other is using the service (this is a concrete case for the above point and same solution would be apropriate if immediate=true can't be applied)

For normal operation (framework has settled and service does not change much) all this might not be so relevant, but it should be keept in mind when using this feature.

Different Injection Sources in different Bundles and general improvement of look-up process

The Blueprint and Spring injection provider is now stored in its own bundle and can be installed sepearately with its dependencies if required. The default Injectionprovider is the OSGi Service one. If not specified any further, any provider found is querried for injection, so it is not neccesary anymore to specify an explicit injection source. Beside this, now more than one injectionprovider can be present and the SPI for providers has been improved.

Delayed Injection using Future

You can use the following block of code now...

@Inject
private Future<MyService> myServiceToInject;

This allows you to explicitely check if a service is available already or if it still needs to get injected. If required you can even wait for a service some time, even this is not recommend since it might blocks page-rendering (but might be better than fail).

SuperFilter

A WebApplicationFactory can be annotated with this to provide a hint that the supplied "SuperFilter" must be used with this application. A {@link SuperFilter} is required to allow specifying a global {@link Filter} that is always called before any other custom filters and will be initialized before the {@link WebApplication} is started, thus it is tied to the lifecycle of the underlying Servlet like in a classical WebApplication environment. This allows to enable special features of Wicket like Atmosphere integration, Native Websockets or Shiro.
There is one special case: when the filter (an no more than one is allowed per application!) extends {@link WicketFilter} it is used as the base class of PAX Wickets Wicket integration (this is needed for NativeWebsockets and maybe future Wicket extensions). This feature is a little bit experimental and tied to the wicket development, so be prepared that this might change slightly in the future!

Manual Imports of Various Wicket and CGLib Dependencies is no longer required

Thanks to the weaving support in OSGi R4.3 it is no longer required to manually import the following dependencies:

org.apache.wicket.core.request.mapper,
org.ops4j.pax.wicket.util.proxy,
net.sf.cglib.proxy;version="[2,3)",
net.sf.cglib.core;version="[2,3)",
net.sf.cglib.reflect;version="[2,3)",
javax.servlet;version="2.5.0",
javax.servlet.http;version="2.5.0"

Drop of NoBeanAvailableForInjectionException

There had been some problems to interpret the exception message in the NoBeanAvailableForInjectionException, e.g. the page class was never able to catch this exception and it was used inconsitently in the SPI for injectionprovider. Because of this, the Exception was dropped completely and replace by standard Runntime exceptions with improved error messages to allow easier diagnostic.

Support for JSR330

This Pax Wicket release now supports javax.inject annotations like @Inject and @Named instead of PaxWicketBean.

To support additional and special Pax Wicket features, the follwoing non-standard annotations are supported (all located in org.ops4j.pax.wicket.api package):

  • @PaxWicketBeanInjectionSource - allows to specify an injection source to inforce, if none is specified the default scan mechanism takes place
  • @PaxWicketBeanFilter - this is currently only supported by the OSGi service injection and allows to specify a default service filter String to use when scann for injection candidates
  • @PaxWicketBeanAllowNull - if this is given, injects null if no bean can be injected. Take care with this, since no bean will be injected at any later point, you might consider using the Future<?> feature instead

Required Bundles are auto-scanned too

Previously only the correct imports triggered an autoscanning of your bundles. While this works pretty fine in most cases it would fail if you use requires-bundle instead of import-package. The new version now also supports bundles having requires-bundle to Pax Wicket in their manifest.

Upgrade from 2.x

To upgrade an application from any of the 2.x versions the following steps have to be done

Upgrade to OSGi Spec 4.3

It is now required that your OSGi framework supports at least version 4.3 of the specification. Since all major OSGi Frameworks support 4.3 and it is completely backward compatible for client code you won't have much hassle with that.

PaxWicketBean annotations are no longer supported

This is the most noteable change. You need to change all your @PaxWicketBean annotations with @Inject annotations and all your @PaxWicketBean(name="xxx") annotations by @Inject @Named("xxx").
The second one is only required for Blueprint inject, and optional for Spring-DM and Service injector (as it was before).

FilterFactory interface reworked

The FilterFactory has previously carried redundant information. It has to be specified in the interface as well as service properties. From now on, onyl service properties are required. In most cases you can just remove the obsolete methods, take a look at the javadoc to find out how things are exactly handled if you have done very sophisticated ordering in your code.

Download

The following sections presents where you can retrieve PAX-WICKET from.

Direct Download

The service bundle can be downloaded here, the source reference here and the javadoc here. TBD: add spring & blueprint bundles here

While Maven or Karaf will take care of the dependencies automatically please download the following dependencies manually if you use neither of them:

  • An OSGi Environment that is R4.3 compliant
  • A HTTP Service that is R3 compliant (use Pax Web or Felix HTTP service here)
  • CGLib
  • A SLF4J frontend (e.g. Pax Logging Service (mvn:org.ops4j.pax/pax-logging-api/1.6.4,mvn:org.ops4j.pax/pax-logging-service/1.6.4))
  • Wicket (util, request and core starting from version 6) (warning) Take care that due to a possible Wicket Bug only versions up to 6.7 are fully working!
  • OPS4J Base Lang

Maven

All artifacts are distributed and available via the maven central repository

<!-- Pax Wicket Core -->
<dependency>
  <groupId>org.ops4j.pax.wicket</groupId>
  <artifactId>org.ops4j.pax.wicket.service</artifactId>
  <version>3.0.0-SNAPSHOT</version>
</dependency>
<!-- Pax Wicket Test Utilities -->
<dependency>
  <groupId>org.ops4j.pax.wicket</groupId>
  <artifactId>org.ops4j.pax.wicket.test</artifactId>
  <version>3.0.0-SNAPSHOT</version>
</dependency>

Karaf

Pax Wicket comes with Karaf feature files for the pax-wicket core and for the samples:

features:addurl mvn:org.ops4j.pax.wicket/features/3.0.0-SNAPSHOT/xml/features
features:addurl mvn:org.ops4j.pax.wicket.samples/features/3.0.0-SNAPSHOT/xml/features

We also support the upcoming Karaf 3.0.0 release out of the box. Please keep in mind that the commands are slightly different for that version

feature:url-add mvn:org.ops4j.pax.wicket/features/3.0.0-SNAPSHOT/xml/features
feature:url-add mvn:org.ops4j.pax.wicket.samples/features/3.0.0-SNAPSHOT/xml/features

Source code

You can browse, download and checkout the source code at https://github.com/ops4j/org.ops4j.pax.wicket/master.

Detailed Changelog

In detail we've fixed 33 issues in this release which are:

Sub-task

Bug

  • [PAXWICKET-388] - PaxWicketBundleListener does not recognize Bundles when they are started after the service bundle
  • [PAXWICKET-389] - Inside Eclipse Envoirments BundleDelegatingExtensionTracker can sometimes not resolve the real classname
  • [PAXWICKET-390] - BundleDelegatingPageMounter scans too much bundles
  • [PAXWICKET-397] - pax:provision in samples directory fails
  • [PAXWICKET-398] - More than one Filterfactory causes CC Exception
  • [PAXWICKET-406] - Restarting the HTTPService makes PAX Wicket loose FilterFactory references
  • [PAXWICKET-431] - ServletRequestInvocationHandler Proxy does not handle TargetInvocation exception "right"
  • [PAXWICKET-433] - Pax Wicket is using the bundle-cache to write its sessions

Dependency upgrade

Improvement

  • [PAXWICKET-126] - Find a way to add org.ops4j.pax.wicket.proxy and cglib as imports automatically
  • [PAXWICKET-256] - Move injection source into providers
  • [PAXWICKET-366] - Bundles not importing org.apache.wicket package, but using Require-Bundle org.ops4j.pax.wicket.service are also relevant
  • [PAXWICKET-377] - More detailed exception message for: org.ops4j.pax.wicket.api.NoBeanAvailableForInjectionException: For Component id.co.bippo.web.pub.HomePage 13 could be injected but only 2 had been injected.
  • [PAXWICKET-399] - FilterFactory carry redundant information
  • [PAXWICKET-400] - HttpTracker should be refactored
  • [PAXWICKET-404] - Use the BundleWiring API to decide if a bundle is relevant for PAX Wicket
  • [PAXWICKET-405] - Upgrade to OSGi R4.3
  • [PAXWICKET-409] - SCAN should be the default for injection source
  • [PAXWICKET-410] - pax-wicket feature should include wicket feature
  • [PAXWICKET-426] - Allow delayed injection of PaxWicketBeans via Futures
  • [PAXWICKET-428] - Drop NoBeanAvailableForInjectionException
  • [PAXWICKET-430] - Restructure Package 'util'
  • [PAXWICKET-437] - Injection from service registry should understand aggregation

New Feature

  • [PAXWICKET-152] - automate injection of special beans
  • [PAXWICKET-186] - Replace PaxWicketBean with JSR330
  • [PAXWICKET-351] - The inject mechanism should support Declarative Components or even ordinary services.

Task