I am trying to filter the web resources of the Jetty HTTP server inside OSGi Apache-Felix.
I've registered a filter as a OSGi component in the Framework:
@Component(property = { "osgi.http.whiteboard.filter.name=MyFilter",
"osgi.http.whiteboard.filter.regex=.*" },
scope = ServiceScope.PROTOTYPE)
public class MyFilter implements Filter {
...
@Override
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain) {
...
// some logging
}
...
}
When I start the Felix framework, and access resources and servlets via my browser, the Filter#doFilter(...)
method never gets called.
The resources and servlets have been registered using org.osgi.service.http.HttpService#registerServlet(...)
and org.osgi.service.http.HttpService#registerResources(...)
.
I'm sure, the filter gets initialized, since Filter#init(...)
gets called:
Here the Felix scr info for the component:
Component Description:
Name: org.myCompany.MyFilter
Implementation Class: org.myCompany.MyFilter
Default State: enabled
Activation: delayed
Configuration Policy: optional
Activate Method: activate
Deactivate Method: deactivate
Modified Method: -
Configuration Pid: [org.myCompany.MyFilter]
Services:
javax.servlet.Filter
Service Scope: prototype
Component Description Properties:
osgi.http.whiteboard.filter.name = MyFilter
osgi.http.whiteboard.filter.regex = .*
Component Configuration:
ComponentId: 7
State: active
Component Configuration Properties:
component.id = 7
component.name = org.myCompany.MyFilter
osgi.http.whiteboard.filter.name = MyFilter
osgi.http.whiteboard.filter.regex = .*
- Does resource/servlet filtering work within Felix, Jetty and OSGi?
- Did I register the filter properly?
In the meantime, thank you for your attention and participation.