无法从 Karaf 2.2.0 OSGi 容器中的根上下文运行 WAR

发布于 2024-11-02 17:42:01 字数 3946 浏览 4 评论 0原文

我一直在努力让 Web 应用程序在 Karaf 2.2.0 的根应用程序上下文中运行(它在 Karaf 2.1.4 中运行良好)。我已经能够使用 Tomcat 示例 WAR 将问题隔离到可以轻松复制的问题上。

  1. 从 Karaf 运行以下命令:

    osgi:install -s webbundle:http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war?Bundle-SymbolicName=tomcat-sample&Webapp-Context=/anything

  2. 从 Web 浏览器访问该应用程序(http://localhost:8181/anything/index.html)

  3. 卸载示例包
  4. 使用以下命令使用根上下文路径重新安装捆绑包:

    osgi:install -s webbundle:http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war?Bundle-SymbolicName=tomcat-sample&Webapp-Context=/

  5. 尝试从您的 Web 访问该应用程序browser (http://localhost:8181/index.html)

  6. 请注意 404 错误。

查看日志,似乎当 Web 应用程序位于根应用程序上下文中时,它会在任何请求前面添加“/default/”。例如,当尝试访问 /index.html 时,它会在 /default/index.html 中查找,但找不到该页面,并返回未找到错误(有关更多详细信息,请参阅下面的日志输出)。

有谁知道如何解决这个问题?


日志输出

15:14:46,270 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | REQUEST /index.html on org.eclipse.jetty.server.nio.SelectChannelConnector$3@693a1324
15:14:46,270 | DEBUG | 30 - /index.html | ServerModel                      | eb.service.spi.model.ServerModel  268 | 52 - org.ops4j.pax.web.pax-web-spi - 1.0.1 | Matching [/index.html]...
15:14:46,270 | DEBUG | 30 - /index.html | ServerModel                      | eb.service.spi.model.ServerModel  292 | 52 - org.ops4j.pax.web.pax-web-spi - 1.0.1 | Path [/index.html] matched to {pattern=/.*,model=ResourceModel{id=org.ops4j.pax.web.service.spi.model.ResourceModel-22,name=default,urlPatterns=[/],alias=/,servlet=ResourceServlet{context=/,alias=/,name=default},initParams={},context=ContextModel{id=org.ops4j.pax.web.service.spi.model.ContextModel-21,name=,httpContext=org.ops4j.pax.web.extender.war.internal.WebAppWebContainerContext@3942ef25,contextParams={webapp.context=}}}}
15:14:46,270 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | Got Session ID 17kb0ch4hv02w1ennfxju5owpw from cookie
15:14:46,270 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | sessionManager=org.eclipse.jetty.server.session.HashSessionManager@7d8aecf1
15:14:46,271 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | session=null
15:14:46,271 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | servlet=default
15:14:46,271 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | servlet holder=
15:14:46,271 | DEBUG | 30 - /index.html | HttpServiceContext               | etty.internal.HttpServiceContext  115 | 54 - org.ops4j.pax.web.pax-web-jetty - 1.0.1 | Handling request for [/index.html] using http context [org.ops4j.pax.web.extender.war.internal.WebAppWebContainerContext@3942ef25]
15:14:46,271 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | chain=
15:14:46,272 | DEBUG | 30 - /index.html | WebAppWebContainerContext        | r.war.internal.WebAppHttpContext  113 | 64 - org.ops4j.pax.web.pax-web-extender-war - 1.0.1 | Searching bundle [tomcat-sample [97]] for resource [default/index.html], normalized to [default/index.html]
15:14:46,272 | DEBUG | 30 - /index.html | WebAppWebContainerContext        | r.war.internal.WebAppHttpContext  140 | 64 - org.ops4j.pax.web.pax-web-extender-war - 1.0.1 | Resource not found
15:14:46,273 | DEBUG | 30 - /index.html | log     

I have been struggling to get an web application to run in the root application context in Karaf 2.2.0 (it works fine in Karaf 2.1.4). I have been able to isolate the issue to something easily duplicated using the Tomcat sample WAR.

  1. Run the following command from Karaf:

    osgi:install -s webbundle:http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war?Bundle-SymbolicName=tomcat-sample&Webapp-Context=/anything

  2. Access the app from your web browser (http://localhost:8181/anything/index.html)

  3. Uninstall the sample bundle
  4. Reinstall the bundle using the root context path with the following command:

    osgi:install -s webbundle:http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war?Bundle-SymbolicName=tomcat-sample&Webapp-Context=/

  5. Attempt to access the app from your web browser (http://localhost:8181/index.html)

  6. Note the 404 error.

Looking at the logs, it appears that when a web app is in the root application context, it prepends a "/default/" to any request. For example, when trying to access /index.html it looks in /default/index.html, fails to find the page, and returns a not found error (see the log output below for more details).

Does anyone know how to resolve this issue?


LOG OUTPUT

15:14:46,270 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | REQUEST /index.html on org.eclipse.jetty.server.nio.SelectChannelConnector$3@693a1324
15:14:46,270 | DEBUG | 30 - /index.html | ServerModel                      | eb.service.spi.model.ServerModel  268 | 52 - org.ops4j.pax.web.pax-web-spi - 1.0.1 | Matching [/index.html]...
15:14:46,270 | DEBUG | 30 - /index.html | ServerModel                      | eb.service.spi.model.ServerModel  292 | 52 - org.ops4j.pax.web.pax-web-spi - 1.0.1 | Path [/index.html] matched to {pattern=/.*,model=ResourceModel{id=org.ops4j.pax.web.service.spi.model.ResourceModel-22,name=default,urlPatterns=[/],alias=/,servlet=ResourceServlet{context=/,alias=/,name=default},initParams={},context=ContextModel{id=org.ops4j.pax.web.service.spi.model.ContextModel-21,name=,httpContext=org.ops4j.pax.web.extender.war.internal.WebAppWebContainerContext@3942ef25,contextParams={webapp.context=}}}}
15:14:46,270 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | Got Session ID 17kb0ch4hv02w1ennfxju5owpw from cookie
15:14:46,270 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | sessionManager=org.eclipse.jetty.server.session.HashSessionManager@7d8aecf1
15:14:46,271 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | session=null
15:14:46,271 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | servlet=default
15:14:46,271 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | servlet holder=
15:14:46,271 | DEBUG | 30 - /index.html | HttpServiceContext               | etty.internal.HttpServiceContext  115 | 54 - org.ops4j.pax.web.pax-web-jetty - 1.0.1 | Handling request for [/index.html] using http context [org.ops4j.pax.web.extender.war.internal.WebAppWebContainerContext@3942ef25]
15:14:46,271 | DEBUG | 30 - /index.html | log                              | .eclipse.jetty.util.log.Slf4jLog   70 | 43 - org.eclipse.jetty.util - 7.2.2.v20101205 | chain=
15:14:46,272 | DEBUG | 30 - /index.html | WebAppWebContainerContext        | r.war.internal.WebAppHttpContext  113 | 64 - org.ops4j.pax.web.pax-web-extender-war - 1.0.1 | Searching bundle [tomcat-sample [97]] for resource [default/index.html], normalized to [default/index.html]
15:14:46,272 | DEBUG | 30 - /index.html | WebAppWebContainerContext        | r.war.internal.WebAppHttpContext  140 | 64 - org.ops4j.pax.web.pax-web-extender-war - 1.0.1 | Resource not found
15:14:46,273 | DEBUG | 30 - /index.html | log     

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-11-09 17:42:01

此问题现已作为 Karaf Bug 提交。请参阅https://issues.apache.org/jira/browse/KARAF-577

This issue has now been submitted as a Karaf Bug. See https://issues.apache.org/jira/browse/KARAF-577

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文