gpt4 book ai didi

servlets - Tomcat Apache ServiceMix 集成问题

转载 作者:行者123 更新时间:2023-12-01 05:53:38 25 4
gpt4 key购买 nike

我们正在尝试使用 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;
}

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

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

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

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

任何帮助都受到高度赞赏。
提前致谢。

最佳答案

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

  • 将 javax.servlet;javax.servlet.http;version=3.1.0 添加到 OSGi 系统包(config.properties 中的 org.osgi.framework.system.packages 属性)
  • 将 javax.servlet-api-3.1.0.jar 添加到 ServiceMix 的 lib\ext 文件夹中。

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

    关于servlets - Tomcat Apache ServiceMix 集成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51423923/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com