更改KARAF / OSGI蓝图Web应用程序的基本URL /上下文路径

发布于 2025-02-13 23:35:57 字数 1306 浏览 1 评论 0原文

我有一个Web应用程序,它在我的OSGI-INF/blueprint/web-blueprint.xml中使用PAX Web中配置了几个servlet。 Web应用程序由两页 /loginpage.html和 /dashboard.html组成,但是后者支持几种视图,每种视图都与自己的Angular Controller和相关的后端Servlet相关联。

我可以通过URL https://< ip>:< port>/loginpage.html and https:// https:// port; ip> ip> /dashboard.html。访问https://&< ip>:< port>/重定向到https://< ip>:< port>/loginpage.html

如果我们调用https://< ip>:< port>/基本URL,我现在想将此基本URL更改为https:https:https:// ip&lt> ip> ;:< port>/test/,以便

  1. 在下面可用https://< ip>:< port>/test/loginpage.html and https:// https:// port> ip>:< port< /代码>分别
  2. https://&< ip>:< port>/test简单地重定向到https://< ip>: >。

因为文件etc/org.ops4j.pax.web.cfgetc/jetty.xml指定为其配置文件,所以我假设我可以在Jetty中配置它。 XML。当前的Jetty.xml是标准的。码头文档说,可以通过添加以下内容来设置上下文路径:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/test</Set>
</Configure>

但是,将上述简单地添加到标准码头conf文件的末尾,原因是我的网页根本无法访问。我找不到任何进一步的文档或示例我如何获得这项工作...

我非常感谢任何帮助!

I have a Web app with several servlets configured in my OSGI-INF/blueprint/web-blueprint.xml using pax web. The web app consists of two pages /LoginPage.html and /Dashboard.html, but the latter supports several views, each associated with an own angular controller and related backend servlet.

I can reach the two pages by the URLs https://<ip>:<port>/LoginPage.html and https://<ip>:<port>/Dashboard.html. Accessing https://<ip>:<port>/ redirects to https://<ip>:<port>/LoginPage.html.

If we call https://<ip>:<port>/ the base URL, I would like now to change this base URL to something like https://<ip>:<port>/test/ so that

  1. the login and dashboard pages are available under https://<ip>:<port>/test/LoginPage.html and https://<ip>:<port>/test/Dashboard.html respectively, and
  2. https://<ip>:<port>/test simply redirects to https://<ip>:<port>/test/LoginPage.html.

Because the file etc/org.ops4j.pax.web.cfg specifies etc/jetty.xml as its config file, I was assuming that I can configure this in jetty.xml. The current jetty.xml is the standard one. jetty documentation says that one can set the context path by adding the following:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/test</Set>
</Configure>

But, adding simply the above to the end of the standard jetty conf file causes that my web pages are not reachable at all. I cannot find any further documentation or example how I could get this work...

I would appreciate any help very much!

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

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

发布评论

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

评论(1

予囚 2025-02-20 23:35:57

请指定您正在使用的PAX Web版本。在PAX Web 8中,白板上下文配置和选择已完全实现。

蓝图示例这声明了servlet,过滤器,错误页面和欢迎文件,但它不执行您想要的(您要注册servletContexThelper whiteboard service)。

还有白板非蓝图样本使用非标准org.ops4j.pax.web.service.whiteboard.httpcontextmapping 。

因此,我不能指出您适当的示例,但是简而言之,您需要三件事:

  1. org.osgi.service.http.context.servletcontexthelper

您必须扩展此类,因为它是抽象的。您也可以重复使用org.ops4j.pax.web.service.spi.context.defaultservletservletcontexthelper

  1. whiteboard上下文基于上述:
<service interface="org.osgi.service.http.context.ServletContextHelper">
    <service-properties>
        <entry key="osgi.http.whiteboard.context.name" value="my-name" />
        <entry key="osgi.http.whiteboard.context.path" value="/test" />
    </service-properties>
    <bean class="org.ops4j.pax.web.service.spi.context.DefaultServletContextHelper" />
</service>
  1. 涉及上述的服务上下文
<service id="my-servlet" interface="javax.servlet.Servlet">
    <service-properties>
        <entry key="osgi.http.whiteboard.servlet.name" value="my-servlet" />
        <entry key="osgi.http.whiteboard.context.select" value="(osgi.http.whiteboard.context.name=my-context)" />
    </service-properties>
    <bean class="com.example.MyServlet" />
</service>

PAX Web 8使用标准白板服务注册属性正确处理上下文选择

Please specify which Pax Web version you're using. In Pax Web 8, whiteboard context configuration and selection is fully implemented.

There's a blueprint example that declares servlets, filters, error pages and welcome files but it doesn't do what you want (you want to register a ServletContextHelper whiteboard service).

There's also a whiteboard non-blueprint sample that registers a context using non-standard org.ops4j.pax.web.service.whiteboard.HttpContextMapping.

So I can't point you to proper sample, but in short words, you need three things:

  1. an implementation of org.osgi.service.http.context.ServletContextHelper

You have to extend this class, because it's abstract. You could also reuse org.ops4j.pax.web.service.spi.context.DefaultServletContextHelper

  1. a whiteboard context based on the above:
<service interface="org.osgi.service.http.context.ServletContextHelper">
    <service-properties>
        <entry key="osgi.http.whiteboard.context.name" value="my-name" />
        <entry key="osgi.http.whiteboard.context.path" value="/test" />
    </service-properties>
    <bean class="org.ops4j.pax.web.service.spi.context.DefaultServletContextHelper" />
</service>
  1. a servlet referring to the above context:
<service id="my-servlet" interface="javax.servlet.Servlet">
    <service-properties>
        <entry key="osgi.http.whiteboard.servlet.name" value="my-servlet" />
        <entry key="osgi.http.whiteboard.context.select" value="(osgi.http.whiteboard.context.name=my-context)" />
    </service-properties>
    <bean class="com.example.MyServlet" />
</service>

Pax Web 8 correctly handles context selection using standard Whiteboard service registration properties.

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