【问题标题】:Tomcat Apache ServiceMix integration issueTomcat Apache ServiceMix 集成问题
【发布时间】:2018-12-27 16:00:15
【问题描述】:

我们正在尝试使用 Apache Felix 桥 (org.apache.felix.http.bridge-4.0.0.jar) 将在 Apache Tomcat 8.5.3 上运行的 Web 应用程序与 Apache ServiceMix 7.0.1 集成。 此处列出的所有步骤都已完成http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html

但我们现在收到 503 服务不可用错误。

在调试时,我们发现这个错误是通过 org.apache.felix.http.proxy.ProxyServlet (org.apache.felix.http.proxy-3.0.2.jar) 抛出的

final HttpServlet dispatcher = this.tracker.getDispatcher();
if (dispatcher != null) {
    final HttpServletRequest r = (this.servletContext == null ? req : new BridgeHttpServletRequest(req, this.servletContext));
    dispatcher.service(r, res);
} else {
    res.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
}

现在 'dispatcher' 为空的原因是因为在跟踪器 (org.apache.felix.http.proxy.DispatcherTracker) 中,它没有被设置。

@Override
public Object addingService(ServiceReference ref)
{
    Object service = super.addingService(ref);
    if (service instanceof HttpServlet) {
        setDispatcher((HttpServlet)service);
    }
    return service;
}

所以(HttpServlet 的服务实例)返回为假。 我们追溯了“服务”的来源,发现它在 org.apache.felix.http.bridge.jar 类 - org.apache.felix.http.bridge.internal.BridgeActivator 'service' 被实例化为 HttpServlet 的匿名子类,因此 instanceof 应该为真。

一个观察 - 我注意到这 2 个类的类加载器是不同的。

“服务”的类加载器是 org.eclipse.osgi.internal.loader.EquinoxClassLoader(因为它是在 OSGI 包中加载的) HttpServlet 的类加载器是 java.net.URLClassLoader

这可能是 instanceof 返回 false 的原因吗?如果是这样,解决这个问题的解决方案是什么。

非常感谢任何帮助。 提前致谢。

【问题讨论】:

    标签: servlets tomcat8 apache-felix instanceof karaf


    【解决方案1】:

    通过执行以下步骤解决了问题:

    1. 将 javax.servlet;javax.servlet.http;version=3.1.0 添加到 OSGi 系统包(config.properties 中的 org.osgi.framework.system.packages 属性)

    2. 将 javax.servlet-api-3.1.0.jar 添加到 ServiceMix 的 lib\ext 文件夹中。

    通过添加到系统包中,HttpServlet 类通过 System Bundle 从框架类加载器中导出,因此 instanceof 返回 true。

    【讨论】:

      猜你喜欢
      • 2016-06-05
      • 2014-02-07
      • 2018-05-07
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2011-10-15
      • 1970-01-01
      相关资源
      最近更新 更多