【发布时间】: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