首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >规范: OSGi HTTP白板和ServletContextHelper

规范: OSGi HTTP白板和ServletContextHelper
EN

Stack Overflow用户
提问于 2017-07-21 14:09:37
回答 1查看 420关注 0票数 1

当多个包使用相同的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?它是在包之间共享,还是只有一个包的实例?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-19 12:10:23

我在Pax 8上工作,在那里我真的很想得到正确的行为。

140.2.7与Servlet容器章节的关系 of OSGi CMPN规范显示了一幅图片,其中实际上有三层javax.servlet.ServletContext对象:

  • 特定于真正Servlet容器的ServletContext实现。在Pax中,有一个是:
    • org.eclipse.jetty.servlet.ServletContextHandler.Context
    • org.apache.catalina.core.ApplicationContext
    • io.undertow.servlet.spec.ServletContextImpl

  • 1:1与org.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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45239850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档