【问题标题】:HttpServletRequest is not visible from class loaderHttpServletRequest 在类加载器中不可见
【发布时间】:2013-05-22 20:48:33
【问题描述】:

我正在尝试在 OSGI 中运行 Apache Wink 并使用 Felix Whiteboard 注册资源作为服务。在简约的 OSGI 环境中,捆绑包按预期工作。但是,然后我将包移到了 Eclipse Equinox 环境中,我正在开发一个依赖它的插件。我开始收到此错误。

May 22, 2013 11:19:59 AM org.apache.wink.server.internal.application.ApplicationProcessor processWinkApplication
SEVERE: An exception occurred during processing of the com.yarcdata.rest.Repositories instance. This instance is ignored.
 java.lang.IllegalArgumentException: interface javax.servlet.http.HttpServletRequest is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:461)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:690)
at org.apache.wink.common.internal.registry.ContextAccessor.getContextFromAccessor(ContextAccessor.java:92)

我想我已经安装了所有必需的包,如果我开始寻找导出 HttpServletRequest 的包,我会看到:

g! lb | grep ervlet
311|Resolved   |    4|Servlet API Bundle (3.0.0.v201112011016)
394|Starting   |    4|Http Services Servlet (1.1.300.v20120912-130548)
444|Resolved   |    4|Jetty :: Servlet Handling (8.1.3.v20120522)
578|Resolved   |    4|jersey-servlet (1.12.0)
580|Resolved   |    4|jersey-servlet (1.17.1)
588|Active     |    4|Java Servlet API (3.0.1)
589|Resolved   |    4|javax.servlet.api (2.5.0)
590|Resolved   |    4|javax.servlet.jstl (1.1.2)
622|Active     |    4|Servlet Specification API (2.5.0)
678|Resolved   |    4|Spring Web Servlet (2.5.6)

g! bundle 588
javax.servlet-api_3.0.1 [588]
Id=588, Status=ACTIVE      Data Root=/wspaces/tbcPlugin/.metadata/.plugins/org.eclipse.pde.core/Eclipse Application/org.eclipse.osgi/bundles/588/data
"No registered services."
No services in use.
Exported packages
  javax.servlet; version="3.0.0"[exported]
  javax.servlet.descriptor; version="3.0.0"[exported]
  javax.servlet.annotation; version="3.0.0"[exported]
  javax.servlet.http; version="3.0.0"[exported]
No imported packages
No fragment bundles
Named class space
  javax.servlet-api; bundle-version="3.0.1"[provided]
No required bundles

所以,由于 HttpServletRequest 的完整包是javax.servlet.http.HttpServletRequest,我希望捆绑包 588 处于活动状态以解决 Wink 的问题。它是活动的,它会导出包,还有什么需要的吗?让我们看看它在寻找什么版本:

g! lb | grep mdatu
  595|Resolved   |    4|Amdatu Web - JAX RS (1.0.0)
  596|Active     |    4|Amdatu Web - Apache Wink Application (1.0.1)

g! bundle 596
  org.amdatu.web.rest.wink_1.0.1 [596]
  Id=596, Status=ACTIVE      Data Root=/wspaces/tbcPlugin/.metadata/.plugins/org.eclipse.pde.core/Eclipse Application/org.eclipse.osgi/bundles/596/data
  "Registered Services"
    {org.amdatu.web.rest.jaxrs.JaxRsSpi}={service.id=139}
    {javax.servlet.Servlet}={init.applicationConfigLocation=/conf/application.properties, alias=/myresource, service.id=140}
    {javax.servlet.Servlet}={init.applicationConfigLocation=/conf/application.properties, alias=/protocol, service.id=141}
    {javax.servlet.Servlet}={init.applicationConfigLocation=/conf/application.properties, alias=/repositories, service.id=142}
    {org.osgi.service.cm.ManagedService}={service.pid=org.amdatu.web.rest.wink, org.amdatu.tenant.pid=org.amdatu.tenant.PLATFORM, service.id=143}
 Services in use:
    {java.lang.Object}={osgi.command.function=[confapply], osgi.command.scope=equinox, service.id=110}
 ...
  No exported packages
  Imported packages
    javax.activation; version="0.0.0"<org.eclipse.osgi_3.8.2.v20130124-134944 [0]>
    javax.annotation; version="0.0.0"<org.eclipse.osgi_3.8.2.v20130124-134944 [0]>
    javax.servlet; version="3.0.0"<javax.servlet-api_3.0.1 [588]>
    javax.servlet.http; version="3.0.0"<javax.servlet-api_3.0.1 [588]>

【问题讨论】:

    标签: eclipse-plugin osgi jax-rs apache-wink amdatu


    【解决方案1】:

    看起来您有多个导出 Servlet API 包的包(例如 588、589 622,可能还有其他包)。因此,您的包导入的包可能与 Apache Wink 包导入的包不同。在正常的 Java 类加载规则下,只有同名 AND 被同一个类加载器加载的两个包才被认为是“相同的”;这在 OSGi 下意味着它们需要由同一个包导出。

    Wink 报告说您无法查看 servlet 包...真正的意思是您无法查看它正在使用的同一个 servlet 包。

    虽然 OSGi 可以处理同一个包的多个版本的导出,但如果您尝试从一个包中导出每个包,您的生活会大大更轻松。所以首先你应该摆脱所有这些冗余的 API 包。

    【讨论】:

    • 这是有道理的,可以帮助我集中注意力。有没有办法询问 OSGI 当前运行的捆绑包导出给定包?
    • 如果您只有 Gogo 附带的非常基本的命令,这并不容易。您必须执行inspect c osgi.wiring.package... 这将列出所有捆绑包的所有导出,然后您可以对结果进行文本搜索。如果您使用的是扩展外壳,那么您可能可以访问更强大的包列表命令...尝试内置帮助。
    【解决方案2】:

    可以在 ContextAccessor.java:92 找到以下代码 sn-p

    (T)Proxy.newProxyInstance(Injectable.class.getClassLoader(),
                                      new Class[] {contextClass},
    ...
    

    如您所见,使用了 Injectable 类的类加载器,该类加载器也在 wink-common.jar 中。但是,如果您查看 wink-commons.jar 的 MANIFEST.MF 文件,您会发现该模块未导入包 javax.servlet.http。

    我不知道这门课的真正逻辑。如果程序员没有很好的理由使用加载 Injectable 的类加载器,最好使用 contextClass 的类加载器来生成代理。你可以向 wink 开发者询问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多