...
Notice the pattern for filters is using regular expressions. So .*
is the same as a simple
using standard servlet patterns.
*
Using the Whiteboard
The whiteboard implementation simplifies the task of registering servlets and filters. A servlet (or filter) can be registered by exporting it as a service. The whiteboard implementation detects all javax.servlet.Servlet
, javax.servlet.Filter
and org.osgi.service.http.HttpContext
services with the right service properties. Let us illustrate the usage by registering a servlet:
Code Block |
---|
public class Activator implements BundleActivator
{
private ServiceRegistration registration;
public void start(BundleContext context) throws Exception
{
Hashtable props = new Hashtable();
props.put("alias", "/hello");
props.put("init.message", "Hello World!");
this.registration = context.registerService(Servlet.class.getName(), new HelloWorldServlet(), props);
}
public void stop(BundleContext context) throws Exception
{
this.registration.unregister();
}
}
|
Servlet service properties:
alias
- Servlet alias to register with.contextId
- Id of context to register with.init.*
- Servlet initialization values.
Filter service properties:
pattern
- Regular expression pattern to register filter with.contextId
- Id of context to register with.service.ranking
- Where in the chain this filter should be placed.init.*
- Filter initialization values.
HttpContext service properties:
contextId
- Id of context to be referenced by a servlet or filter service.
Using the Servlet Bridge
Configuration Properties
The service can both be configured using OSGi environment properties and using Configuration Admin. The service PID for this service is "org.apache.felix.http"
. If you use both methods, Configuration Admin takes precedence. The following properties can be used (some legacy property names still exist but are not documented here on purpose):
...