当多个包使用相同的ServletContextHelper时,我需要一些与Http白板规范相关的ServletContextHelper行为的精确性
说明书上写着:
Http白板实现必须为每个ServletContext服务创建一个单独的ServletContextHelper实例。通过使用osgi.http.whiteboard.context.select属性,可以将白板服务与Servlet上下文帮助器关联起来。如果未设置此属性,则将使用默认的Servlet上下文帮助程序。
如果我正确理解,使用相同ServletContextHelper引用的所有Servlet或过滤器都绑定到相同的“ServletContext”
然后:
可以使用Service实现ServletContextHelper的某些实现,例如,像默认实现那样从关联的包中提供资源。因此,白板实现必须使用注册白板服务的Bundle的bundle上下文获得Servlet上下文帮助。
因此,如果包A向ServletContextHelper X注册Servlet,而bundle B使用相同的ServletContextHelper引用注册过滤器,那么Servlet和Filter将注册到相同的ServletContext,但是它们的init方法是用两个ServletContext的不同实例调用的(为了以不同的方式实现getClassLoader()方法)?
此外,“默认”ServletContextHelper的行为是什么?是否总是有“默认”注册的ServletContextHelper?它是在包之间共享,还是只有一个包的实例?
发布于 2021-02-19 12:10:23
我在Pax 8上工作,在那里我真的很想得到正确的行为。
140.2.7与Servlet容器章节的关系 of OSGi CMPN规范显示了一幅图片,其中实际上有三层javax.servlet.ServletContext对象:
ServletContext实现。在Pax中,有一个是:org.eclipse.jetty.servlet.ServletContextHandler.Contextorg.apache.catalina.core.ApplicationContextio.undertow.servlet.spec.ServletContextImplorg.osgi.service.http.context.ServletContextHelper OSGi服务的关系中的OSGi实现ServletContext,其中除getClassLoader()方法外,所有方法都委托给上面的SCH,getClassLoader()返回bundle.adapt(BundleWiring.class).getClassLoader()这一问题与org.osgi.service.http.context.ServletContextHelper假定的双重责任原则有关.它既用于实现功能方面(handleSecurity()),也用于资源分离方面(getResource())。
所以您是对的--如果Bundle A注册一个servlet,而Bundle B注册一个过滤器,两者都将使用相同的ServletContext实例(由引用的ServletContextHelper支持),但是它们的init()方法将提供不同的、特定于绑定的ServletContext实例。
这是由委托实现的,有两种实现:
org.ops4j.pax.web.service.spi.servlet.OsgiServletContext实现了1:1行为org.ops4j.pax.web.service.spi.servlet.OsgiScopedServletContext实现了getClassLoader()和委托所有其他方法到上面的OsgiServletContext。https://stackoverflow.com/questions/45239850
复制相似问题