Filter (Quick)

Skip to end of metadata
Go to start of metadata

Filters are an important part of your web application. In classical applications you register your filters using the web.xml. In an OSGi engine services could come and go as they like. Therefore we need different approaches. For pax-wicket you have two options. Either use the namespaces from spring/blueprint or register them manually.

Expect that you've a simple filter (or a more complex one e.g. from Jetty or somewhere else).

Register a filter using the Pax-Wicket namespace

All you have to do is to register your class. What you see in addition here is a priority. That one is required to execute filters in a specific order. The filters with the highest priority will be executed first then the lower ones. Of cause the priority can change at any time.

Register a filter manually

To be able to register a filter manually you need to provide a filter factory. For our IAmASysoutFilter such a factory could look like the following part. Please notice that the priority in this case is set in the factory instead of in the registry. This has the advantage that it could be changed quite easily from case to case dependent on various outer conditions.

After that we'll simply have to register the service in the OSGi registry:

Full sample

The full sample showing the code above is located here.

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Clicky Web Analytics