[英]Felix OSGi Servlet/Resource Filter does not filter
I am trying to filter the web resources of the Jetty HTTP server inside OSGi Apache-Felix. 我正在尝试在OSGi Apache-Felix中过滤Jetty HTTP服务器的Web资源。
I've registered a filter as a OSGi component in the Framework: 我已经在框架中将过滤器注册为OSGi组件:
@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. 当我启动Felix框架并通过浏览器访问资源和servlet时,永远不会调用
Filter#doFilter(...)
方法。
The resources and servlets have been registered using org.osgi.service.http.HttpService#registerServlet(...)
and org.osgi.service.http.HttpService#registerResources(...)
. 资源和servlet已使用
org.osgi.service.http.HttpService#registerServlet(...)
和org.osgi.service.http.HttpService#registerResources(...)
。
I'm sure, the filter gets initialized, since Filter#init(...)
gets called: 我敢肯定,由于
Filter#init(...)
被调用, Filter#init(...)
:
Here the Felix scr info for the component: 这里是组件的Felix scr信息:
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 = .*
In the meantime, thank you for your attention and participation. 同时,感谢您的关注和参与。
The R6 specification is not clear on the interaction between the HttpService et Whiteboard Services. 关于HttpService和Whiteboard Services之间的交互,R6规范尚不清楚。 In fact, the update on RFC 0223 says :
实际上,RFC 0223的更新内容是:
3.1 Whiteboard Services and Http Service (Bug 2872)
3.1白板服务和Http服务(错误2872)
If a Http Whiteboard implementation is also implementing the Http Service, the whiteboard specification does not specify whether the Http contexts for the Http Service are represented as ServletContextHelper services.
如果Http Whiteboard实现也正在实现Http Service,则白板规范不会指定Http Service的Http上下文是否表示为ServletContextHelper服务。 There is no way for a whiteboard service to be registered in a Http Context of the Http Service.
白板服务无法在Http服务的Http上下文中注册。 For example adding a servlet filter for all servlets managed by the Http Service is not possible.
例如,不可能为Http Service管理的所有servlet添加servlet过滤器。
The Felix implementation doesn't share HttpContext and ServletContextHelper: You have to register your servlet with the Http Whiteboard in order to use your Filter. Felix实现不共享HttpContext和ServletContextHelper:必须使用Http Whiteboard注册servlet才能使用Filter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.