Reputation: 1
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
https://<ip>:<port>/test/LoginPage.html
and https://<ip>:<port>/test/Dashboard.html
respectively, andhttps://<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!
Upvotes: 0
Views: 425
Reputation: 6237
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:
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
<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>
<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.
Upvotes: 0