【问题标题】:Specs: OSGi HTTP Whiteboard and ServletContextHelper规格:OSGi HTTP 白板和 ServletContextHelper
【发布时间】:2017-12-27 15:14:03
【问题描述】:

当多个包使用相同的 ServletContextHelper 时,我需要一些与 Http Whiteboard 规范相关的 ServletContextHelper 行为的精确度

规范说:

Http Whiteboard 实现必须创建一个单独的 每个 ServletContextHelper 服务的 ServletContext 实例。 白板服务可以与 Servlet 上下文助手相关联 通过使用 osgi.http.whiteboard.context.select 属性。如果这 未设置属性,使用默认的 Servlet 上下文助手。

如果我理解正确,所有使用相同 ServletContextHelper 引用的 Servlet 或过滤器都绑定到相同的“ServletContext”

然后:

可以实现 ServletContextHelper 的一些实现 使用服务工厂,例如从 关联的捆绑包,就像默认实现一样。因此 白板实现必须使用 Servlet Context Helper 注册白板的包的包上下文 服务。

所以如果一个bundle A用ServletContextHelper X注册了一个Servlet,而bundle B用同样的ServletContextHelper引用注册了一个Filter,那么Servlet和Filter注册到同一个ServletContext,但是它们的init方法被两个调用ServletContext 的不同实例(以不同方式实现 getClassLoader() 方法)?

此外,“默认” ServletContextHelper 的行为是什么?是否总是有一个“默认”的 ServletContextHelper 注册?它是在捆绑包之间共享还是捆绑包只有一个实例?

【问题讨论】:

    标签: osgi pax-web osgi-http-service


    【解决方案1】:

    我在 Pax Web 8 上工作,我真的希望在其中正确处理行为。

    OSGi CMPN 规范的140.2.7 Relation to the Servlet Container chapter 显示了一张图片,其中javax.servlet.ServletContext 对象实际上有三个层:

    • ServletContext 特定于真实 Servlet 容器的实现。在 Pax Web 中,它是以下之一:
      • org.eclipse.jetty.servlet.ServletContextHandler.Context
      • org.apache.catalina.core.ApplicationContext
      • io.undertow.servlet.spec.ServletContextImpl
    • ServletContext 实现与 org.osgi.service.http.context.ServletContextHelper OSGi 服务 1:1 关系
    • ServletContext 为每个 Whiteboard 捆绑包实现服务工厂合同,其中除 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

    【讨论】:

    • 谢谢!这个问题有点老了,我在这里问过,以防我误解了规范,然后在你的 JIRA 中写问题:-) 我希望能够尽快使用你的 v8。
    • :) 我收到了关于这个问题的通知。
    猜你喜欢
    • 2016-11-22
    • 2022-09-29
    • 2011-04-02
    • 2013-12-25
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    相关资源
    最近更新 更多