Skip navigation links

Package org.ops4j.pax.web.service.spi.model

SPI model hierarchy contains classes to internally represent all the information required during registration (adding to running server) of web components (servlets, filters, welcome files, error pages, security constraints, ...).

See: Description

Package org.ops4j.pax.web.service.spi.model Description

SPI model hierarchy contains classes to internally represent all the information required during registration (adding to running server) of web components (servlets, filters, welcome files, error pages, security constraints, ...). Such hierarchy is completely unaware of request mapping and it should be treated purely as static database of registrations.

This package containing classes that try to hold server independent model of components, though it's modelled after actual capabilities of Jetty, Tomcat and Undertow.

In Tomcat, we have these concepts:

Tomcat uses quite straightforward processing: connector - virtual host - context - servlet. In standard conf/server.xml it's not easy to use single context in several virtual hosts, but it's possible to use such configuration in embedded mode.

In Jetty, we have these concepts:

Jetty allows special syntax where virtual host name (or pattern) is followed by @connectorName allowing to filter request based on connector through which the request had arrived.

In Undertow, we have these concepts:

Undertow doesn't do special context mapping and uses io.undertow.server.handlers.PathHandler to do it. found prefix is set using io.undertow.server.HttpServerExchange#setResolvedPath().

Now, the above, server-specific concepts have to be mapped into Pax Web and OSGi specifications (both "102 Http Service" and "140 Whiteboard Service". The mapping starts ... in the middle with a concept of a context.

There are two contexts depending on OSGi CMPN specification considered:

However, these contexts are not mapped 1:1 with single ServletContext representing a web application as seen by actual server implementation. The above are used by some other servlet context which is mapped 1:1 with original one (according to OSGi CMPN R7). But there's still additional ServletContext actually visible by servlets/filters/etc. depending on the HttpContext or ServletContextHelper with which the servlet/filter/etc. was registered to preserve bundle-affinity.

First, original, server-specific ServletContext, identified uniquely by context path is created everytime a HttpContext or ServletContextHelper is tracked from service registry, with specified context path. Such context is represented by ServletContextModel and is agnostic wrt any bundle. When more HttpContext/ServletContextHelper services are registered for a given context path, there's no conflict - simply more OSGi-specific contexts point to server-specific context.

Then, registered servlet/filter/etc. is associated with some OSGi-specific context using context name (osgi.http.whiteboard.context.name or httpContext.id) and when there are more OSGi-specific contexts (even if pointing to different server-specific contexts), service ranking is used to resolve the conflict. Such OSGi-specific context is represented by OsgiContextModel.

Additionally, what servlets, filters see is yet another ServletContext with proper delegation to relevant class loader. Such context has no representation in the model.

When servlet (or filter, or ...) is registered, it is registered with one (or more!) contexts and when actual server implementation is asked to register such element the registration has to be done for all actual ServletContext instances.

There's a requirement, that ServletContextHelper instances have to be available in OSGi registry (including the default one registered by Whiteboard implementation itself). It is not a case with Http Service and HttpContext.

Skip navigation links

Copyright © 2006–2024 OPS4J - Open Participation Software for Java. All rights reserved.