140 Whiteboard Specification for Jakarta™ Servlet

140.1 Introduction

Servlets have become a popular and widely supported mechanism for providing dynamic content on the Internet. While servlets are defined in the [4] Jakarta Servlet 5.0 Specification, the Servlet Whiteboard Specification provides a light and convenient way of using servlets, servlet filters, servlet listeners and web resources in an OSGi environment through the use of the [7] Whiteboard Pattern.

The Servlet Whiteboard Specification supports:

  • Registering Servlets - Registering a servlet in the Service Registry makes it available to be bound to an endpoint to serve content over the network.

  • Registering Servlet Filters - Servlet filters support pre- and post-processing of servlet requests and responses. Servlet filters can be registered in the Service Registry to include them in the handling pipeline.

  • Registering Resources - Resources such as HTML files, JavaScript, image files, and other static resources can be made available over the network by registering resource services.

  • Registering Servlet Listeners - The servlet specification defines a variety of listeners, which receive callbacks when certain events take place.

Implementations of this specification can support the following versions of the HTTP protocol:

Alternatively, implementations of this service can support other protocols if these protocols can conform to the semantics of the Jakarta Servlet API.

Implementations of this specification must support version 5.0 or later of the Jakarta Servlet API.

140.1.1 Entities

This specification defines the following entities:

  • Servlet Whiteboard service - An object registered in the Service Registry under one of the Whiteboard service interfaces defined by this specification.

  • Servlet Whiteboard implementation - An implementation that processes Servlet Whiteboard services.

  • Http Service Runtime service - Service providing runtime introspection into the Servlet Whiteboard implementation.

  • Listener - Various listeners can be registered to receive notifications about servlet or Http Session events.

  • Resource Service - A service thats binds static resources.

  • Servlet - Component that dynamically generates web pages or other resources provided over the network.

  • Servlet Context Helper - A service to control the behavior of the Servlet Context.

  • Servlet Filter - Can be used to augment or transform web resources or for cross-cutting functionality such as security, common widgets or otherwise.

Figure 140.1 Servlet Whiteboard Overview Diagram

Servlet Whiteboard Overview Diagram

140.2 The Servlet Context

The servlet specification defines the ServletContext which is provided to servlets at runtime by the container. Whiteboard services defined by this specification are also provided with a ServletContext. The behavior of this Servlet Context can be influenced by providing a ServletContextHelper service. A custom ServletContextHelper can provide resources, mime-types, handle security and supports a number of methods from the ServletContext.

The Servlet Whiteboard implementation must create a separate ServletContext instance for each ServletContextHelper service. Whiteboard services can be associated with the Servlet Context Helper by using the osgi.http.whiteboard.context.select property. If this property is not set, the default Servlet Context Helper is used.

To achieve the required behavior for ServletContext.getClassLoader each bundle must be provided with a separate Servlet Context instance to serve the class loader of the Whiteboard services for that bundle. For more information see getClassLoader in Table 140.2 on page .

Some implementations of the ServletContextHelper may be implemented using a Service Factory, for example to provide resources from the associated bundle, as the default implementation does. Therefore the Whiteboard implementation must get the Servlet Context Helper using the Bundle Context of the bundle that registered the Whiteboard service.

Some environments may use [8] Core Service Hooks to isolate ServletContextHelper service registrations. The Whiteboard implementation must check that the bundle registering the Whiteboard service has the ability to find the ServletContextHelper service before allowing the Whiteboard service to bind to the Servlet Context Helper. This can be done by calling one of the getServiceReferences methods on the Bundle Context of bundle that registered the Whiteboard service.

Table 140.1 Service registration properties for ServletContextHelper services.

Service Property Type Description

osgi.http.whiteboard.context.name

name

String

required

Name of the Servlet Context Helper. This name can be referred to by Whiteboard services via the osgi.http.whiteboard.context.select property. The syntax of the name is the same as the syntax for a Bundle Symbolic Name. The default Servlet Context Helper is named default. To override the default, register a custom ServletContextHelper service with the name default. If multiple Servlet Context Helper services are registered with the same name, the one that is first in ranking order, as specified in ServiceReference.compareTo, is used.

Registrations with an invalid or unspecified name are not used and reflected in the failure DTOs. See HTTP_WHITEBOARD_CONTEXT_NAME.

osgi.http.whiteboard.context.path

path

String

required

Additional prefix to the context path for servlets. This property is mandatory. Valid characters are specified in IETF RFC 3986, section 3.3. The context path of the default Servlet Context Helper is /. A custom default Servlet Context Helper may use an alternative path. If the path is invalid or unspecified, the service is not used and reflected in the failure DTOs. See HTTP_WHITEBOARD_CONTEXT_PATH.

context.init.*

String

optional

Properties starting with this prefix are provided as init parameters through the ServletContext.getInitParameter and ServletContext.getInitParameterNames methods. The context.init. prefix is removed from the parameter name. See HTTP_WHITEBOARD_CONTEXT_INIT_PARAM_PREFIX.


Multiple ServletContextHelper services can have identical or overlapping osgi.http.whiteboard.context.path values. A matching servlet or resource is located as follows:

  1. The Servlet Context Helper service with the longest matching path is matched first.

  2. In the case of multiple Servlet Context Helper services with the same path, the services are searched in ranking order, as specified in ServiceReference.compareTo, for a match.

For example, if two ServletContextHelper services are registered as follows

osgi.http.whiteboard.context.path = /foo
osgi.http.whiteboard.context.path = /foo/bar

Then a request for http://localhost/foo/bar/someServlet is looked up in the following order:

  1. /foo/bar context looking for a pattern to match /someServlet

  2. /foo context looking for a pattern to match /bar/someServlet

Note that whole path segments must match. Therefore the following request can only be handled by the Servlet Context Helper registered under the /foo path: http://localhost/foo/bars/someOtherServlet.

For details on the association process between servlet, servlet filter, resource and listener services and the ServletContextHelper see Common Whiteboard Properties.

If a Servlet Context Helper can not be used, for example because it is shadowed by another Servlet Context Helper service with the same name but with a higher ranking, this is reflected in the FailedServletContextDTO. Similarly, if an alternative default Servlet Context Helper is provided, the default Servlet Context Helper provided by the Servlet Whiteboard implementation is not used and represented in a failure DTO.

An example Servlet Context Helper defined using Declarative Services annotations can be found below, it prefixes the path with /myapp for any associated whiteboard service. Additionally, it serves static resources from a non-standard location, a content delivery network. Other methods use the default ServletContextHelper implementation.

@Component(service = ServletContextHelper.class, scope = ServiceScope.BUNDLE)
@HttpWhiteboardContext(name = "my-context", path = "/myapp")     
public class CDNServletContextHelper extends ServletContextHelper {
    public URL getResource(String name) {
        try {
            return new URL("http://acmecdn.com/myapp/" + name);
        } catch (MalformedURLException e) {
            return null;
        }
    }
}

The following sections outline the methods a custom ServletContextHelper can override and the behavior of the default implementation.

140.2.1 String getMimeType(String)

Called to provide the MIME type for a resource.

Default Behavior - Always returns null.

140.2.2 String getRealPath(String)

Called to support the ServletContext.getRealPath method.

Default Behavior - Always returns null.

140.2.3 URL getResource(String)

Obtain a URL for a given resource request.

Default Behavior - Assumes the resources are in the bundle registering the Whiteboard service. Its Bundle.getEntry method is called to obtain a URL to the resource. The default Servlet Context Helper implementation assumes the path to be relative to the bundle's root.

140.2.4 Set<String> getResourcePaths(String)

Called to support the ServletContext.getResourcePaths method. Returns all the matching resources for the path.

Default Behavior - Assumes the resources are in the bundle registering the Whiteboard service. Its Bundle.findEntries method is called to obtain the listing.

140.2.5 Security Handling

The handleSecurity method is invoked to handle implementation-defined security on the request. It is invoked before the request is sent to the filter-servlet pipeline.

When the request returns from the filter-servlet pipeline the finishSecurity method is called. This method can be used by the security handling mechanism to clean up any context associated with the current request. finishSecurity is only called if handleSecurity returned true for the specified request. If an exception occurs during processing of the pipeline, finishSecurity is still called. This allows to clean up regardless of the result of the pipeline.

In the case a request is dispatched either using the include or forward method handleSecurity and finishSecurity are called again on this new context. These calls are nested within the originating request. Servlet Context Helpers that implement these methods must be prepared to deal with such nested invocations.

Default Behavior - handleSecurity always returns true. finishSecurity does nothing by default.

140.2.6 Behavior of the Servlet Context

The ServletContext provided to Whiteboard services is based on the associated ServletContextHelper, Whiteboard service registration properties and the underlying servlet container.

Methods to programmatically add servlets, servlet filters and listeners are not supported on the ServletContext. Such functionality is available by registering these entities as Whiteboard services.

Table 140.2 Behavior of ServletContext methods.

ServletContext method Since Description
addFilter(...)

3.0

Throws UnsupportedOperationException.

addListener(...)

3.0

Throws UnsupportedOperationException.

addServlet(...)

3.0

Throws UnsupportedOperationException.

createFilter(Class)

3.0

Throws UnsupportedOperationException.

createListener(Class)

3.0

Throws UnsupportedOperationException.

createServlet(Class)

3.0

Throws UnsupportedOperationException.

declareRoles(String ...)

3.0

Throws UnsupportedOperationException.

getAttribute(String)

2.0

Stored per ServletContextHelper. The Servlet Context keeps a set of attributes per Servlet Context Helper.

getAttributeNames()

2.1

Stored per ServletContextHelper. The Servlet Context keeps a set of attributes per Servlet Context Helper.

getClassLoader()

3.0

Returns the class loader of the bundle that registered the Whiteboard service. An implementation of this specification can achieve this by returning separate façades of the ServletContext to each Whiteboard service. Each façade accesses the Whiteboard service's Bundle Wiring to obtain its class loader.

getContext(String)

2.1

Backed by the Servlet Container.

getContextPath()

2.5

Return the web context path of the Servlet Context. This takes into account the osgi.http.whiteboard.context.path of the Servlet Context Helper and the path of the Http runtime.

getDefaultSessionTrackingModes()

3.0

Backed by the Servlet Container.

getEffectiveMajorVersion()

3.0

Backed by the Servlet Container.

getEffectiveMinorVersion()

3.0

Backed by the Servlet Container.

getEffectiveSessionTrackingModes()

3.0

Backed by the Servlet Container.

getFilterRegistration(String)

3.0

Backed by the Servlet Container.

getFilterRegistrations()

3.0

Backed by the Servlet Container.

getInitParameter(String)

2.2

From context.init.* service registration properties.

getInitParameterNames()

2.2

From context.init.* service registration properties.

getJspConfigDescriptor()

3.0

Returns null.

getMajorVersion()

2.1

Backed by the Servlet Container.

getMimeType(String)

2.1

Backed by the ServletContextHelper.

getMinorVersion()

2.1

Backed by the Servlet Container.

getNamedDispatcher(String)

2.2

Provides the Whiteboard servlet with the specified name, provided through the osgi.http.whiteboard.servlet.name property, if associated with this Servlet Context Helper. If multiple servlets have the same name and are associated with this Servlet Context Helper, then the servlet that is first in ranking order, as specified in ServiceReference.compareTo, is used.

getRealPath(String)

2.0

Backed by the ServletContextHelper.

getResource(String)

2.1

Backed by the ServletContextHelper.

getRequestDispatcher(String)

2.1

If the argument matches a servlet associated with this Servlet Context Helper, this will be returned.

getResourceAsStream(String)

2.1

Backed by the ServletContextHelper.

getResourcePaths(String)

2.3

Backed by the ServletContextHelper.

getServlet(String)

2.0

Deprecated. Backed by the Servlet Container.

getServletContextName()

2.2

The name of the ServletContextHelper provided via the osgi.http.whiteboard.context.name service property.

getServletNames()

2.0

Deprecated. Backed by the Servlet Container.

getServletRegistration(String)

3.0

Backed by the Servlet Container.

getServletRegistrations()

3.0

Backed by the Servlet Container.

getServlets()

2.0

Deprecated. Backed by the Servlet Container.

getServerInfo()

2.0

Backed by the Servlet Container.

getSessionCookieConfig()

3.0

Returns a SessionCookieConfig object. This object is read-only and all setters throw a IllegalStateException.

getVirtualServerName()

3.1

Backed by the Servlet Container.

log(String)

2.0

Backed by the Servlet Container.

log(Exception, String)

2.0

Deprecated. Backed by the Servlet Container.

log(String, Throwable)

2.1

Backed by the Servlet Container.

removeAttribute(String)

2.1

Stored per ServletContextHelper. The Servlet Context keeps a set of attributes per Servlet Context Helper.

setAttribute(String, Object)

2.1

Stored per ServletContextHelper. The Servlet Context keeps a set of attributes per Servlet Context Helper.

setInitParameter(String, String)

3.0

Throws IllegalStateException. The ServletContext has already been initialized.

setSessionTrackingModes(Set)

3.0

Throws IllegalStateException. The ServletContext has already been initialized.


140.2.7 Relation to the Servlet Container

Implementations of this specification will often be backed by existing servlet containers or a Jakarta EE application server. There may also exist implementations which bridge into a servlet container into which the OSGi Framework has been deployed as a Web Application.

In bridged situations the Servlet Whiteboard implementation will live in one servlet context and all Whiteboard services registered by this implementation will be backed by the same underlying Servlet Context. However, to exhibit the behavior described in Table 140.2 on page different Servlet Context objects may be required. Therefore an implementation of this specification may need to create additional ServletContext objects which delegate certain functionality to the ServletContextHelper and other functionality to the Servlet Context of the Web Application, yet further functionality can be obtained otherwise. In such cases the relationship may look like the below figure.

Figure 140.2 Servlet Context entities and their relation

Servlet Context entities and their relation

Where Table 140.2 on page states Backed by the Servlet Container and the Servlet Whiteboard implementation is deployed in bridged mode, the API call can be forwarded to the top-level Servlet Context. If the Servlet Whiteboard implementation is not deployed in bridged mode, it must provide another means to handle these APIs.

In bridged deployments, the implementation needs to ensure the following:

  1. That Whiteboard services are provided with the correct ServletContext keeping in mind that each distinct ServletContextHelper should be associated with a separate ServletContext object, which in turn may delegate certain requests to the underlying shared ServletContext as described in the table above.

  2. That Http Sessions are not shared amongst servlets registered with different ServletContextHelpers. That is, HttpRequest.getSession calls must provide different sessions per associated ServletContextHelper. Http Sessions are defined in chapter 7 of the [4] Jakarta Servlet 5.0 Specification.

140.3 Common Whiteboard Properties

Whiteboard servlet, servlet filter, resource and listener services support common service registration properties to associate them with a ServletContextHelper and/or a Servlet Whiteboard implementation.

Table 140.3 Common properties

Service Property Type Description

osgi.http.whiteboard.context.select

HttpWhiteboardContextSelect

String

optional

An LDAP-style filter to select the associated ServletContextHelper service to use. Any service property of the Servlet Context Helper can be filtered on. If this property is missing the default Servlet Context Helper is used.

For example, to select a Servlet Context Helper with name myCTX provide the following value:

(osgi.http.whiteboard.context.name=myCTX)

To select all Servlet Context Helpers provide the following value:

(osgi.http.whiteboard.context.name=*)

If no matching context exists this is reflected in the failure DTOs. See HTTP_WHITEBOARD_CONTEXT_SELECT.

osgi.http.whiteboard.target

HttpWhiteboardTarget

String

optional

The value of this service property is an LDAP-style filter expression to select the Servlet Whiteboard implementation(s) to handle this Whiteboard service. The LDAP filter is used to match HttpServiceRuntime services. Each Servlet Whiteboard implementation exposes exactly one HttpServiceRuntime service. This property is used to associate the Whiteboard service with the Servlet Whiteboard implementation that registered the HttpServiceRuntime service. If this property is not specified, all Servlet Whiteboard implementations can handle the service. See HTTP_WHITEBOARD_TARGET.


If multiple Servlet Context Helper services match the osgi.http.whiteboard.context.select property the servlet, filter, resource or listener will be registered with all these Servlet Context Helpers. To avoid multiple init and destroy calls on the same instance, servlets and filters should be registered as Prototype Service Factory.

140.4 Registering Servlets

Servlets can be registered with the Servlet Whiteboard implementation by registering them as Whiteboard services. This means that Servlet implementations are registered in the Service Registry under the jakarta.servlet.Servlet interface.

Servlets are registered with one or more pattern through the osgi.http.whiteboard.servlet.pattern service property. Each pattern defines the URL context that will trigger the servlet to handle the request. They are defined by the [4] Jakarta Servlet 5.0 Specification in section 12.2, Specification of Mappings. The mapping rules are:

  • A string beginning with a '/' character and ending with a "/*" suffix is used for path mapping.

  • A string beginning with a "*." prefix is used as an extension mapping.

  • The empty string ("") is a special URL pattern that exactly maps to the application's context root. That is, requests of the form http://host:port/<context-root>/. In this case the path info is "/" and the servlet path and context path are the empty string ("").

  • A string containing only the '/' character indicates the "default" servlet of the application. In this case, the servlet path is the request URI minus the context path and the path info is null.

  • All other strings are used for exact matches only.

Servlet and resource service registrations associated with a single Servlet Context share the same namespace. In case of identical registration patterns, the service that is first in ranking order, as specified in ServiceReference.compareTo, is selected as the service handling a request. That is, Whiteboard servlets that have patterns shadowed by other Whiteboard services associated with the same Servlet Context are represented in the failure DTOs.

The above rules can cause servlets that are already bound becoming unbound if a better match arrives. This ensures a predictable end result regardless of the order in which services are registered.

A servlet may be registered with the property osgi.http.whiteboard.servlet.name which can be used by servlet filters to address this servlet. If the servlet service does not have this property, the servlet name defaults to the fully qualified class name of the service object.

For example, if the Servlet Whiteboard implementation is listening on port 80 on the machine www.acme.com and the Servlet object is registered with the pattern "/servlet", then the Servlet object's service method is called when the following URL is used from a web browser:

http://www.acme.com/servlet

The following table describes the properties that can be used by Servlets registered as Whiteboard services. Additionally, the common properties listed in Table 140.3 on page are supported.

Table 140.4 Service properties for Servlet Whiteboard services.

Service Property Type Description

osgi.http.whiteboard.servlet.«

 asyncSupported

HttpWhiteboardServletAsyncSupported

Boolean | String

optional

Declares whether the servlet supports the asynchronous operation mode. Allowed values are true and false independent of case. Defaults to false. See HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED.

osgi.http.whiteboard.servlet.«

 errorPage

HttpWhiteboardServletErrorPage

String+

optional†

Register the servlet as an error page for the error code and/or exception specified; the value may be a fully qualified exception type name or a three-digit HTTP status code in the range 400-599. Special values 4xx and 5xx can be used to match value ranges. Any value not being a three-digit number is assumed to be a fully qualified exception class name. See HTTP_WHITEBOARD_SERVLET_ERROR_PAGE.

osgi.http.whiteboard.servlet.«

 name

HttpWhiteboardServletName

String

optional†

The name of the servlet. This name is used as the value of the jakarta.servlet.ServletConfig.getServletName method and defaults to the fully qualified class name of the service object. See HTTP_WHITEBOARD_SERVLET_NAME.

osgi.http.whiteboard.servlet.«

 pattern

HttpWhiteboardServletPattern

String+

optional†

Registration pattern(s) for the servlet. See HTTP_WHITEBOARD_SERVLET_PATTERN.

osgi.http.whiteboard.servlet.«

 multipart.enabled

enabled

Boolean | String

optional

Enables support for multipart configuration on the servlet. Allowed values are true and false independent of case. Defaults to false. See HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED.

osgi.http.whiteboard.servlet.«

 multipart.fileSizeThreshold

fileSizeThreshold

Integer

optional

The file size threshold after which the file is stored as a temporary file on disk while uploading. Defaults to 0. Files will be stored in the directory as specified in ...location on the file system. See HTTP_WHITEBOARD_SERVLET_MULTIPART_FILESIZETHRESHOLD.

osgi.http.whiteboard.servlet.«

 multipart.location

location

String

optional

The location where files are stored on disk. Defaults to the value of jakarta.servlet.context.tempdir servlet context attribute. If this attribute is not set, the value of the java.io.tmpdir system property will be used as default. If an absolute path is specified then this path is used as-is. If a relative path is specified, it will be used as relative to the default value. java.io.File.isAbsolute must be used to evaluate whether a path is absolute or relative. See HTTP_WHITEBOARD_SERVLET_MULTIPART_LOCATION.

osgi.http.whiteboard.servlet.«

 multipart.maxFileSize

maxFileSize

Long

optional

The maximum size for an uploaded file. Defaults to unlimited. Files larger than this size will cause a servlet exception. See HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXFILESIZE.

osgi.http.whiteboard.servlet.«

 multipart.maxRequestSize

maxRequestSize

Long

optional

The maximum size of a multipart/form-data request, in bytes. Defaults to unlimited. Requests larger than this value will cause a servlet exception. See HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXREQUESTSIZE.

servlet.init.*

String

optional

Properties starting with this prefix are provided as init parameters to the jakarta.servlet.Servlet.init method. The servlet.init. prefix is removed from the parameter name. See HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX.


Note that at least one of the following properties must be specified on Servlet Whiteboard services:

    osgi.http.whiteboard.servlet.pattern
    osgi.http.whiteboard.servlet.name
    osgi.http.whiteboard.servlet.errorPage

Servlet objects are initialized by a Servlet Whiteboard implementation before they start serving requests. The initialization is done by calling the Servlet object's Servlet.init(ServletConfig) method. The ServletConfig parameter provides access to the initialization parameters specified when the Servlet object was registered. Once the servlet is no longer used by the Servlet Whiteboard implementation the destroy method is called. Failure during Servlet.init will prevent the servlet from being used, which is reflected using a failure DTO. In such a case the system treats the servlet as unusable and attempts to find an alternative servlet matching the request.

If the service properties of the servlet Whiteboard service are modified, the destroy method is called. Subsequently the servlet is re-initialized. If a Prototype Service Factory is used for the servlet this re-initialization is done on a new service object.

When multiple Servlet Whiteboard implementations are present all of them can potentially process the Servlet. In such situations it can be useful to associate the servlet with a specific implementation by specifying the osgi.http.whiteboard.target property on the Servlet service to match its HttpServiceRuntime service.

If more than one Http Service Runtime matches the osgi.http.whiteboard.target property or the property is not set, the Servlet will be processed by all the matching implementations. A Servlet service that is processed by more than one Servlet Whiteboard implementation will have its init method called for each implementation that processes this Servlet. Similarly, the destroy method is called once when the Servlet is shut down once for each implementation that processed it. As multiple init and destroy calls on the same Servlet instance are generally not desirable, Servlet implementations should be registered as Prototype Service Factories as defined in the OSGi Core Release 8. This will ensure that each Servlet Whiteboard implementation processing the Servlet will use a separate instance, ensuring that only one init and destroy call is made per Servlet object. Servlets not registered as a Prototype Service Factory may received init and destroy calls multiple times on the same service object.

The following example code uses Declarative Services annotations to register a servlet whiteboard service.

@HttpWhiteboardServletPattern("/myservlet")
@Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE,
    property = "servlet.init.myname=value")
public class MyServlet extends HttpServlet {
    private String name = "<not set>";

    public void init(ServletConfig config) {
        name = config.getInitParameter("myname");
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
            throws IOException {
        resp.setContentType("text/plain");
        resp.getWriter().println("Servlet name: " + name);
    }
}

This example registers the servlet at: /myservlet. Requests for http://www.acme.com/myservlet map to the servlet, whose service method is called to process the request.

To associate the above example servlet with the example ServletContextHelper in The Servlet Context, add the following service property:

osgi.http.whiteboard.context.select=(osgi.http.whiteboard.context.name=my-context)

This will cause the servlet to move to http://www.acme.com/myapp/myservlet as configured by the custom Servlet Context Handler.

140.4.1 Multipart File Upload

Multipart file uploads are supported by specifying the osgi.http.whiteboard.servlet.multipart.* properties on the Servlet service registration. The following example illustrates this:

@Component(service = Servlet.class)
@HttpWhiteboardServletPattern("/image")
@HttpWhiteboardServletMultipart(enabled = true, maxFileSize = 200000)
public class ImageServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {

        Collection<Part> parts = request.getParts();

        for (Part part : parts) {
            System.out.printf("File %s, %s, %d%n", part.getName(),
                    part.getContentType(), part.getSize());

            try (InputStream is = part.getInputStream()) {
                // ...
            }
        }
    }
}

140.4.2 Error Pages

Servlets can be used to serve Error Pages. These are invoked when an exception is thrown during processing or if a servlet uses the sendError method with a status code between 400 and 599.

For a servlet service to handle error situations the service property osgi.http.whiteboard.servlet.errorPage must be set. This property can have multiple values, allowing a single servlet to handle a variety of error situations. Possible values are 3-digit HTTP error codes and fully qualified exception names.

Two special error code values are recognized. The special value 4xx means every error code in the 400-499 range. The special value 5xx means every error code in the 500-599 range. To override such wildcard error page for a specific error, register an error page with the specific error code and a higher service ranking. Error pages shadowed by other error pages are reported via the failure DTOs. A 4xx/5xx wildcard error page is only reported in the failure DTOs if it is shadowed by another wildcard page.

Matching exceptions follows the exception hierarchy. First the most specific exception class - the actual class of the exception - is looked up. If no matching error page for the most specific exception is found, the error page for the super class of the exception is looked up and so on. The process ends by looking up an error page for the java.lang.Throwable class.

While not being common practice, it is possible to combine the osgi.http.whiteboard.servlet.errorPage and osgi.http.whiteboard.servlet.pattern properties. If a single servlet registration has both these registration properties it is considered both an ordinary servlet as well as an error page.

If an error or exception occurs for which an error page servlet can be matched, it is invoked to render the error page. If the error page servlet causes an error or exception while handling the request, an implementation built-in error page is returned.

For example:

@Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE)
@HttpWhiteboardServletErrorPage(errorPage = {"java.io.IOException", "500"})
public class MyErrorServlet extends HttpServlet {
   ...
}

The example servlet is invoked in case of a 500 error code, or if an IOException (or subclass) occurs. If there is more than one error page registered for the same exception or error code, the service that is first in ranking order, as specified in ServiceReference.compareTo, is selected as the handling servlet.

140.4.3 Asynchronous Request Handling

Servlets can use the asynchronous request handling feature, as defined by the servlet specification.

A servlet or servlet filter supporting the asynchronous mode must declare this with the appropriate service property osgi.http.whiteboard.servlet.asyncSupported or osgi.http.whiteboard.filter.asyncSupported.

An example simple asynchronous servlet that handles the servlet requests in a thread from a custom thread pool rather than in the thread provided by the servlet container:


@Component(service = Servlet.class, scope = ServiceScope.PROTOTYPE)
@HttpWhiteboardServletPattern("/as")
@HttpWhiteboardServletAsyncSupported
public class AsyncServlet extends HttpServlet {
    ExecutorService executor = Executors.newCachedThreadPool(
        r -> new Thread(r, "Pooled Thread"));

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
            throws IOException {
        doGetAsync(req.startAsync());
    }

    private void doGetAsync(AsyncContext asyncContext) {
        executor.submit(() -> {
            try {
                PrintWriter writer = asyncContext.getResponse().getWriter();
                writer.print("Servlet executed async in: " +
                    Thread.currentThread()); // writes 'Pooled Thread'
            } finally {
                asyncContext.complete();
            }
            return null;
        });
    }
}

140.4.4 Annotations

Annotations defined in the Servlet API Specifications are ignored by an implementation of the Servlet Whiteboard Specification. The OSGi service model is used instead by this specification.

Implementations of this specification may support these annotations through a proprietary opt-in mechanism.

140.5 Registering Servlet Filters

Servlet filters provide a mechanism to intercept servlet invocations. They support modifying the ServletRequest and ServletResponse objects and are often used to augment web pages generated by servlets, for example with a common header or footer. Servlet filters can also be used to handle security, do logging or transform the content produced by a servlet to a certain format.

Similar to servlets, servlet filters are registered as Whiteboard services, by registering a jakarta.servlet.Filter instance in the Service Registry. The following table describes the supported service properties. In addition the common properties as described in Table 140.3 on page are supported.

Table 140.5 Service properties for Filter Whiteboard services.

Service Property Type Description

osgi.http.whiteboard.filter.«

 asyncSupported

HttpWhiteboardFilterAsyncSupported

String

optional

Declares whether the servlet filter supports asynchronous operation mode. Allowed values are true and false independent of case. Defaults to false. See HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED.

osgi.http.whiteboard.filter.«

 dispatcher

HttpWhiteboardFilterDispatcher

String+

optional

Select the dispatcher configuration when the servlet filter should be called. Allowed string values are REQUEST, ASYNC, ERROR, INCLUDE, and FORWARD. The default for a filter is REQUEST. See HTTP_WHITEBOARD_FILTER_DISPATCHER.

osgi.http.whiteboard.filter.name

HttpWhiteboardFilterName

String

optional

The name of a servlet filter. This name is used as the value of the FilterConfig.getFilterName method and defaults to the fully qualified class name of the service object. See HTTP_WHITEBOARD_FILTER_NAME.

osgi.http.whiteboard.filter.pattern

HttpWhiteboardFilterPattern

String+

optional†

Apply this servlet filter to the specified URL path patterns. The format of the patterns is specified in the servlet specification. See HTTP_WHITEBOARD_FILTER_PATTERN.

osgi.http.whiteboard.filter.regex

HttpWhiteboardFilterRegex

String+

optional†

Apply this servlet filter to the specified URL paths. The paths are specified as regular expressions following the syntax defined in the java.util.regex.Pattern class. See HTTP_WHITEBOARD_FILTER_REGEX.

osgi.http.whiteboard.filter.servlet

HttpWhiteboardFilterServlet

String+

optional†

Apply this servlet filter to the referenced servlet(s) by name. See HTTP_WHITEBOARD_FILTER_SERVLET.

filter.init.*

String+

optional

Properties starting with this prefix are passed as init parameters to the Filter.init method. The filter.init. prefix is removed from the parameter name. See HTTP_WHITEBOARD_FILTER_INIT_PARAM_PREFIX.


Note that at least one of the following properties must be specified on Filter Whiteboard services:

    osgi.http.whiteboard.filter.pattern
    osgi.http.whiteboard.filter.regex
    osgi.http.whiteboard.filter.servlet

Similar to servlets, Filter objects are initialized by a Servlet Whiteboard implementation before they start filtering requests. The initialization is done by calling the Filter.init(FilterConfig) method. The FilterConfig parameter provides access to filter.init.* properties on the servlet filter service registration. Once the Filter is no longer used by the Servlet Whiteboard implementation, the destroy method is called. When the service properties on the servlet filter are modified, the destroy method is called and the servlet filter is subsequently re-initialized, if it can still be associated with a Servlet Whiteboard implementation after the modification. By default, a servlet filter can be used with any Servlet Context Helper or Servlet Whiteboard implementation. To restrict a servlet filter to a single implementation or a specific Servlet Context Helper, the Common Whiteboard Properties can be used.

To deal with the dynamicity of the Whiteboard service lifecycle, it is recommended to implement a servlet filter as Prototype Service Factory service. This will ensure that one single servlet filter instance only receives one init and one destroy call. Otherwise a single servlet filter instance can receive multiple such calls. This is similar to the behavior recommended for Servlet Whiteboard services.

Multiple servlet filters can process the same servlet request/response. If more than one Filter matches, they are processed in ranking order, as specified in ServiceReference.compareTo. The servlet filter with the highest ranking is processed first in the filter chain, while the servlet filter with the lowest ranking is processed last, before the Servlet.service method is called. After the servlet completes its service method the filter chain is unwound in reverse order.

Servlet filters are only applied to servlet requests if they are bound to the same Servlet Context Helper and the same Servlet Whiteboard implementation.

The example Filter below adds some text before and after the content generated by a servlet:

@Component(scope = ServiceScope.PROTOTYPE)
@HttpWhiteboardFilterPattern("/*")    
public class MyFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {}

    public void doFilter(ServletRequest request, ServletResponse response, 
            FilterChain chain) throws IOException, ServletException {
        response.getWriter().write("before");
        chain.doFilter(request, response);
        response.getWriter().write("after");
    }

    public void destroy() {}
}

140.5.1 Servlet Pre-Processors

Servlet Filters are always run after handleSecurity is called. However in some cases it is necessary to process servlet requests before security is handled. For example if all requests must be logged, even ones that are rejected by security. In other scenarios, requests may need to be prepared for the handleSecurity call.

A whiteboard Preprocessor service can be registered to handle such cases. The Preprocessor service only supports the following service registration properties:

Table 140.6 Service properties for Preprocessor Whiteboard services.

Service Property Type Description

osgi.http.whiteboard.target

HttpWhiteboardTarget

String

optional

The value of this service property is an LDAP-style filter expression to select the Servlet Whiteboard implementation(s) to handle this Whiteboard service. The LDAP filter is used to match HttpServiceRuntime services. Each Servlet Whiteboard implementation exposes exactly one HttpServiceRuntime service. This property is used to associate the Whiteboard service with the Servlet Whiteboard implementation that registered the HttpServiceRuntime service. If this property is not specified, all Servlet Whiteboard implementations can handle the service. See HTTP_WHITEBOARD_TARGET.

preprocessor.init.*

String+

optional

Properties starting with this prefix are passed as init parameters to the Filter.init method. The preprocessor.init. prefix is removed from the parameter name. See HTTP_WHITEBOARD_PREPROCESSOR_INIT_PARAM_PREFIX.


A Preprocessor is invoked before request dispatching is performed. If multiple pre-processors are registered they are invoked in the order as described for servlet filters.

The Preprocessor has the same API as the servlet Filter and is handled in the same way, the init and destroy are called at the appropriate life-cycle events. However, as pre-processors are called before dispatching, the targeted servlet context is not yet know. Therefore the FilterConfig.getServletContext returns the servlet context of the backing implementation, the same context as returned by the request. As a pre-processor instance is not associated with a specific servlet context, it is safe to implement it as a singleton.

When called in the doFilter method, the pre-processor can use the FilterChain to invoke the next pre-processor, or if the end of the chain is reached, start processing the request. The pre-processor can also terminate the processing and generate a response directly. Before request processing returns to the pre-processors finishSecurity is called. If an exception is thrown during request processing, the exception is propagated through the pre-processors.

The example Preprocessor below logs a message before and after request processing:

@Component
public class MyPreprocessor implements Preprocessor {

    @Reference(service=LoggerFactory.class)
    private Logger logger;
    
    public void init(FilterConfig filterConfig) throws ServletException {}

    public void doFilter(ServletRequest request, ServletResponse response, 
            FilterChain chain) throws IOException, ServletException {
        logger.debug("Request processing starts");
        chain.doFilter(request, response);
        logger.debug("Request processing ends");
    }

    public void destroy() {}
}

140.6 Registering Resources

A resource is a file containing images, static HTML pages, JavaScript, CSS, sounds, movies, etc. Resources do not require any handling from the bundle. They are transferred directly from their source - usually the JAR file that contains the code for the bundle - to the requester.

Resources can be served by registering a service of any type with a service registration property that marks it as a resource service: osgi.http.whiteboard.resource.pattern. The actual service object registered is not used to serve resources, it is merely used to inform the Servlet Whiteboard implementation to serve resources from a certain source.

The following table describes the supported service properties. In addition the common properties as described in Table 140.3 on page are supported.

Table 140.7 Service properties for resource services.

Service Property Type Description

osgi.http.whiteboard.resource.pattern

pattern

String+

required

The pattern(s) to be used to serve resources. As defined by the [4] Jakarta Servlet 5.0 Specification in section 12.2, Specification of Mappings.

This property marks the service as a resource service.

See HTTP_WHITEBOARD_RESOURCE_PATTERN.

osgi.http.whiteboard.resource.prefix

prefix

String

required

The prefix used to map a requested resource to the bundle's entries. If the request's path info is not null, it is appended to this prefix. The resulting string is passed to the getResource(String) method of the associated Servlet Context Helper.

See HTTP_WHITEBOARD_RESOURCE_PREFIX.


The examples below use Declarative Services annotations to register a resources service. Note that this service is purely used to convey information to the Servlet Whiteboard implementation and is never invoked.

@Component(service = MyResourceService.class)
@HttpWhiteboardResource(pattern = "/files/*", prefix = "/www")
public class MyResourceService {}

A Servlet Whiteboard implementation configured on port 80 will serve a request for http://localhost/files/cheese.html from the location /www/cheese.html.

The following example maps requests for /favicon.ico to serve the /logo.png resource. Note that the pattern is not appended to the prefix as the path info in this case is null.

@Component(service = SomeResourceService.class)
@HttpWhiteboardResource(pattern = "/favicon.ico", prefix = "/logo.png")
public class SomeResourceService {}

The above examples use the default ServletContextHelper implementation, which loads these resources from the bundle that registered the resource service. For more control around serving resources, a resources service can be associated to a custom ServletContextHelper. For example, a custom Servlet Context Helper can serve resources from locations other than the current bundle.

140.6.1 Overlapping Resource and Servlet Registrations

Resources and servlets registered with the same Servlet Context share a single URI namespace. This means that the value specified in osgi.http.whiteboard.resource.pattern competes with the osgi.http.whiteboard.servlet.pattern property specified on servlets. If these values overlap, the rules as outlined in Registering Servlets are used to resolve conflicts, where resource services are treated just like servlets. Shadowed resource patterns are reported as FailedResourceDTO.

140.7 Registering Listeners

The servlet specification defines listener interfaces that can be implemented to receive a variety of servlet-related events. When using the Servlet Whiteboard implementation these listeners can be registered as Whiteboard services.

  • ServletContextListener - Receive notifications when Servlet Contexts are initialized and destroyed.

  • ServletContextAttributeListener - Receive notifications for Servlet Context attribute changes.

  • ServletRequestListener - Receive notifications for servlet requests coming in and being destroyed.

  • ServletRequestAttributeListener - Receive notifications when servlet Request attributes change.

  • HttpSessionListener - Receive notifications when Http Sessions are created or destroyed.

  • HttpSessionAttributeListener - Receive notifications when Http Session attributes change.

  • HttpSessionIdListener - Receive notifications when Http Session ID changes.

Events are sent to listeners registered in the Service Registry with the osgi.http.whiteboard.listener service property set to true, independent of case. Listeners can be associated with a ServletContextHelper as described in Common Whiteboard Properties. Listeners not specifically associated with a Servlet Context Helper will receive events relating to the default Servlet Context Helper.

Multiple listeners of the same type registered with a given Servlet Context Helper are invoked in ranking order, as specified in ServiceReference.compareTo.

Table 140.8 Service properties for listener services.

Service Property Type Description

osgi.http.whiteboard.listener

HttpWhiteboardListener

Boolean | String

required

When set to true this listener service is handled by the Servlet Whiteboard implementation. When not set or set to false the service is ignored. Any other value is invalid and will be reflected in a FailedListenerDTO. Note the property value is case independent. See HTTP_WHITEBOARD_LISTENER.


An example listener that reports on client requests being initialized and destroyed is listed below:

@Component
@HttpWhiteboardListener    
public class MyServletRequestListener implements ServletRequestListener {
    public void requestInitialized(ServletRequestEvent sre) {
        System.out.println("Request initialized for client: " + 
            sre.getServletRequest().getRemoteAddr());
    }

    public void requestDestroyed(ServletRequestEvent sre) {
        System.out.println("Request destroyed for client: " + 
            sre.getServletRequest().getRemoteAddr());
    }
}

For more details on the behavior of the listeners see the [4] Jakarta Servlet 5.0 Specification.

140.8 Life Cycle

If a Whiteboard service is used by a Servlet Whiteboard implementation, the following order of actions are performed:

  1. The service is obtained from the service registry.

  2. For servlets and servlet filters, init is called.

When the service is not used anymore, these actions are performed:

  1. For servlets and servlet filters, destroy is called.

  2. The service is released.

Note that some of the above actions may not be performed immediately, allowing an implementation to utilize lazy or asynchronous behavior.

As servlets and servlet filters services might come and go as well as ServletContextHelper services might come and go, use of the Whiteboard services can be very dynamic. Therefore servlet and servlet filter services might transition between bound to a Servlet Whiteboard implementation to being unbound and back to be bound. For example, when a matching Servlet Context Helper with the same name arrives with a higher ranking than the currently bound Servlet Context Helper, the servlet will be destroyed and re-initialized, bound to this better matching Servlet Context Helper. This is to ensure that timing issues cannot dictate the topology of the system.

As init and destroy are called each time the service life cycle changes, the recommended way to register services is to use the Prototype Service scope as defined in the OSGi Core Release 8. This ensures a new instance is created for each time such service is re-initialized. If the prototype scope is not used, the service should be prepared that after a call to destroy a new initialization through init might follow.

140.8.1 Whiteboard Service Dynamics and Active Requests

When the Servlet Whiteboard implementation receives a network request it establishes the processing pipeline based on the available Whiteboard services (servlets, servlet filters and resource services) and executes this pipeline. Between establishing the pipeline and finishing the processing, services used in this pipeline might become unregistered. It is up to the Servlet Whiteboard implementation whether it completes the active request or throws a Servlet Exception in this case.

140.9 The Http Service Runtime Service

The HttpServiceRuntime service represents the runtime state information of a Servlet Whiteboard implementation. This information is provided through Data Transfer Objects (DTOs). The architecture of OSGi DTOs is described in OSGi Core Release 8.

Each Servlet Whiteboard implementation registers exactly one HttpServiceRuntime service which can be used to target Whiteboard services defined in this specification to a specific Http Whiteboard implementation.

The HttpServiceRuntime provides service registration properties to declare its underlying Servlet Whiteboard implementation. These service properties can include implementation-specific key-value pairs. They also include the following:

Table 140.9 Service properties for the HttpServiceRuntime service

Service Property Type Description
osgi.http.endpoint String+

Endpoint(s) where this Servlet Whiteboard implementation is listening. Registered Whiteboard services are made available here. Values could be provided as URLs e.g. http://192.168.1.10:8080/ or relative paths, e.g. /myapp/. Relative paths may be used if the scheme and authority parts of the URLs are not known such as in a bridged Servlet Whiteboard implementation. If the Servlet Whiteboard implementation is serving the root context and scheme and authority are not known, the value of the property is /. Each entry must end with a slash.

See HTTP_SERVICE_ENDPOINT.

service.changecount Long

Whenever the DTOs available from the Http Service Runtime service change, the value of this property will increase by an amount of 1 or more.

This allows interested parties to be notified of changes to the DTOs by observing Service Events of type MODIFIED for the HttpServiceRuntime service. See org.osgi.framework.Constants.SERVICE_CHANGECOUNT in OSGi Core Release 8.


The Http Service Runtime service provides information on registered Whiteboard services through the RuntimeDTO and RequestInfoDTO. The RuntimeDTO provides information on services that have been successfully registered as well as information about the Whiteboard services that were not successfully registered. Whiteboard services that have the required properties set but cannot be processed, are reflected in the failure DTOs. Whiteboard services of interfaces described in this specification that do not have the required properties set are ignored and not reflected in the failure DTOs.

The Runtime DTO can be obtained using the getRuntimeDTO() method. The Runtime DTO provided has the following structure:

Figure 140.3 Runtime DTO Overview Diagram

Runtime DTO Overview Diagram

Handlers for a given request path can be found with the calculateRequestInfoDTO(String) method. This method returns a RequestInfoDTO with the following structure:

Figure 140.4 Request Info DTO Overview Diagram

Request Info DTO Overview Diagram

140.10 Configuration Properties

If the Servlet Whiteboard implementation does not have its port values configured through some other means, the implementation should use the following Framework properties to determine the port values to listen on.

  • org.osgi.service.http.port - This property specifies the port used for servlets and resources accessible via HTTP. The default value for this property is 80.

  • org.osgi.service.http.port.secure - This property specifies the port used for servlets and resources accessible via HTTPS. The default value for this property is 443.

140.11 Capabilities

140.11.1 osgi.implementation Capability

The Servlet Whiteboard implementation bundle must provide the osgi.implementation capability with name osgi.http. This capability can be used by provisioning tools and during resolution to ensure that a Servlet Whiteboard implementation is present to process the Whiteboard services defined in this specification. The capability must also declare a uses constraint for the Servlet and OSGi Servlet Whiteboard packages and provide the version of this specification:

Provide-Capability: osgi.implementation;
       osgi.implementation="osgi.http";
       uses:="jakarta.servlet, jakarta.servlet.http,
              org.osgi.service.servlet.context,
              org.osgi.service.servlet.whiteboard";
       version:Version="2.0"

This capability must follow the rules defined for the osgi.implementation Namespace.

Bundles registering services to be picked up by the Http Whiteboard implementation should require the osgi.implementation capability. For example:

Require-Capability: osgi.implementation;
       filter:="(&(osgi.implementation=osgi.http)
                 (version>=2.0)(!(version>=2.0)))"
      

To simplify the creation of this requirement, the RequireHttpWhiteboard annotation can be used.

140.11.2 osgi.contract Capability

The Servlet Whiteboard implementation must provide a capability in the osgi.contract namespace with name JakartaServlet if it exports the jakarta.servlet and jakarta.servlet.http packages. See [5] Portable Java Contract Definitions.

Providing the osgi.contract capability enables developer to build portable bundles for packages that are not versioned under OSGi Semantic Versioning rules. For more details see osgi.contract Namespace.

If the Servlet API is provided by another bundle, the Servlet Whiteboard implementation must be a consumer of the API and require the contract.

140.11.3 osgi.service Capability

The bundle providing the HttpServiceRuntime service must provide a capability in the osgi.service namespace representing this service. This capability must also declare a uses constraint for the org.osgi.service.servlet.runtime and org.osgi.service.servlet.runtime.dto packages:

Provide-Capability: osgi.service;
  objectClass:List<String>="org.osgi.service.servlet.runtime.HttpServiceRuntime";
  uses:="org.osgi.service.servlet.runtime,org.osgi.service.servlet.runtime.dto"

This capability must follow the rules defined for the osgi.service Namespace.

140.12 Security

This section only applies when executing in an OSGi environment which is enforcing Java permissions.

140.12.1 Service Permissions

Bundles that need to register Servlet Whiteboard services must be granted ServicePermission[interfaceName, REGISTER] where interface name is the Servlet Whiteboard service interface name.

The Servlet Whiteboard implementation must be granted ServicePermission[interfaceName, GET] to retrieve the Http Whiteboard services from the service registry.

140.12.2 Introspection

Bundles that need to introspect the state of the Http runtime will need ServicePermission[org.osgi.service.servlet.runtime.HttpServiceRuntime, GET] to obtain the HttpServiceRuntime service and access the DTO types.

140.12.3 Accessing Resources with the Default Servlet Context Helper Implementation

The Servlet Whiteboard implementation must be granted AdminPermission[*,RESOURCE] so that bundles may use the default ServletContextHelper implementation. This is necessary because the implementation of the default ServletContextHelper must call Bundle.getEntry to access the resources of a bundle and this method requires the caller to have AdminPermission[bundle,RESOURCE].

Any bundle may access resources in its own bundle by calling Class.getResource. This operation is privileged. The resulting URL object may then be passed to the Http Whiteboard implementation as the result of a ServletContextHelper.getResource call. No further permission checks are performed when accessing bundle entry or resource URL objects, so the Servlet Whiteboard implementation does not need to be granted any additional permissions.

140.12.4 Accessing Other Types of Resources

In order to access resources that were not returned from the default ServletContextHelper implementation, the Servlet Whiteboard implementation must be granted sufficient privileges to access these resources. For example, if the getResource method of a ServletContextHelper service returns a file URL, the Servlet Whiteboard implementation requires the corresponding FilePermission to read the file. Similarly, if the getResource method of a ServletContextHelper service returns an HTTP URL, the Servlet Whiteboard implementation requires the corresponding SocketPermission to connect to the resource.

Therefore, in most cases, the Servlet Whiteboard implementation should be a privileged service that is granted sufficient permission to serve any bundle's resources, no matter where these resources are located. Therefore, the Servlet Whiteboard implementation must capture the AccessControlContext object of the bundle registering a ServletContextHelper service, and then use the captured AccessControlContext object when accessing resources returned by the ServletContextHelper service. This situation prevents a bundle from supplying resources that it does not have permission to access.

Therefore, the Servlet Whiteboard implementation should follow a scheme like the following example. When using a ServletContextHelper service, it should capture the context.

ServiceReference<ServletContextHelper> servletContextHelperReference = ...
AccessControlContext acc = servletContextHelperReference.getBundle()
    .adapt(AccessControlContext.class);

When a URL returned by the getResource method of a ServletContextHelper service is used by the Servlet Whiteboard implementation, the implementation must use the URL in a doPrivileged construct using the AccessControlContext object of the registering bundle:

AccessController.doPrivileged(
    new PrivilegedExceptionAction() {
        public Object run() throws Exception {
        ...
        }
    }, acc);

This ensures the Servlet Whiteboard implementation can only use the URL if the bundle registering the ServletContextHelper service that returned the URL also has permission to use the URL. The use of a captured AccessControlContext only applies when accessing URL objects returned by the getResource method of the ServletContextHelper service.

140.12.5 Calling Servlet Whiteboard Services

This specification does not require that the Servlet Whiteboard implementation is granted All Permission or wraps calls to the Http Whiteboard services in a doPrivileged block. Therefore, it is the responsibility of the Servlet Whiteboard service implementations to use a doPrivileged block when performing privileged operations.

140.12.6 Multipart Upload

If multipart upload is enabled for a servlet, the uploaded data is usually temporarily written to a file. Therefore if security is enabled file permissions must be granted accordingly.

If a servlet is using the default path to store uploaded data, the Servlet Whiteboard implementation needs FilePermission[path, "read,write,delete"] for that path. As the servlet is reading the data, the bundle containing the servlet needs FilePermission[path, "read"] for that path.

If a servlet is providing the path to store uploaded data, the bundle containing the servlet needs FilePermission[path, "read,write,delete"] for that path. The Servlet Whiteboard implementation needs the same permissions for that path. Therefore, it is the responsibility of the Servlet Whiteboard service implementations to use a doPrivileged block when performing the write operation.

If security is enabled and any of the above required permissions is not granted, the multipart handling servlet is regarded invalid and will not be registered. This state is reflected in the error DTOs.

140.13 org.osgi.service.servlet.context

Version 2.0

Http Context Package Version 2.0.

Bundles wishing to use this package must list the package in the Import-Package header of the bundle's manifest. This package has two types of users: the consumers that use the API in this package and the providers that implement the API in this package.

Example import for consumers using the API in this package:

Import-Package: org.osgi.service.servlet.context; version="[2.0,3.0)"

Example import for providers implementing the API in this package:

Import-Package: org.osgi.service.servlet.context; version="[2.0,2.1)"

140.13.1 Summary

  • ServletContextHelper - Helper service for a servlet context used by a Servlet Whiteboard implementation to serve HTTP requests.

140.13.2 public abstract class ServletContextHelper

Helper service for a servlet context used by a Servlet Whiteboard implementation to serve HTTP requests.

This service defines methods that the Servlet Whiteboard implementation may call to get information for a request when dealing with whiteboard services.

Each ServletContextHelper is registered with a "osgi.http.whiteboard.context.name" service property containing a name to reference by servlets, servlet filters, resources, and listeners. If there is more than one ServletContextHelper registered with the same context name, the one that is first in the ranking order is active, the others are inactive.

A context is registered with the "osgi.http.whiteboard.context.path" service property to define a path under which all services registered with this context are reachable. If there is more than one ServletContextHelper registered with the same path, each duplicate context path is searched in ranking order until a matching servlet or resource is found.

Servlets, servlet filters, resources, and listeners services may be associated with a ServletContextHelper service with the "osgi.http.whiteboard.context.select" service property. If the referenced ServletContextHelper service does not exist or is currently not active, the whiteboard services for that ServletContextHelper are not active either.

If no ServletContextHelper service is associated, that is no "osgi.http.whiteboard.context.select" service property is configured for a whiteboard service, a default ServletContextHelper is used.

Those whiteboard services that are associated with the same ServletContextHelper object will share the same ServletContext object.

The behavior of the methods on the default ServletContextHelper is defined as follows:

  • getMimeType - Always returns null.

  • handleSecurity - Always returns true.

  • getResource - Assumes the named resource is in the bundle of the whiteboard service, addressed from the root. This method calls the whiteboard service bundle's Bundle.getEntry method, and returns the appropriate URL to access the resource. On a Java runtime environment that supports permissions, the Servlet Whiteboard implementation needs to be granted org.osgi.framework.AdminPermission[*,RESOURCE].

  • getResourcePaths - Assumes that the resources are in the bundle of the whiteboard service. This method calls Bundle.findEntries method, and returns the found entries. On a Java runtime environment that supports permissions, the Servlet Whiteboard implementation needs to be granted org.osgi.framework.AdminPermission[*,RESOURCE].

  • getRealPath - Always returns null.

HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH

Thread-safe

140.13.2.1 public static final String AUTHENTICATION_TYPE = "org.osgi.service.http.authentication.type"

HttpServletRequest attribute specifying the scheme used in authentication. The value of the attribute can be retrieved by HttpServletRequest.getAuthType.

140.13.2.2 public static final String AUTHORIZATION = "org.osgi.service.useradmin.authorization"

HttpServletRequest attribute specifying the Authorization object obtained from the org.osgi.service.useradmin.UserAdmin service. The value of the attribute can be retrieved by HttpServletRequest.getAttribute(ServletContextHelper.AUTHORIZATION) .

140.13.2.3 public static final String REMOTE_USER = "org.osgi.service.http.authentication.remote.user"

HttpServletRequest attribute specifying the name of the authenticated user. The value of the attribute can be retrieved by HttpServletRequest.getRemoteUser.

140.13.2.4 public ServletContextHelper()

Construct a new context helper.

If needed, the subclass will have to handle the association with a specific bundle.

140.13.2.5 public ServletContextHelper(Bundle bundle)

The bundle to be associated with this context helper.

Construct a new context helper associated with the specified bundle.

140.13.2.6 public void finishSecurity(HttpServletRequest request, HttpServletResponse response)

The HTTP request.

The HTTP response.

Finishes the security context for the specified request.

Implementations of this service can implement this method to clean up resources which have been setup in handleSecurity(HttpServletRequest, HttpServletResponse).

This method is only called if handleSecurity(HttpServletRequest, HttpServletResponse) returned true for the specified request. This method is called once the pipeline finishes processing or if an exception is thrown from within the pipeline execution.

The default implementation of this method does nothing.

handleSecurity(HttpServletRequest, HttpServletResponse)

140.13.2.7 public String getMimeType(String name)

The name for which to determine the MIME type.

Maps a name to a MIME type.

Called by the Servlet Whiteboard implementation to determine the MIME type for the specified name. For whiteboard services, the Servlet Whiteboard implementation will call this method to support the ServletContext method getMimeType. For resource servlets, the Servlet Whiteboard implementation will call this method to determine the MIME type for the Content-Type header in the response.

The MIME type (e.g. text/html) of the specified name or null to indicate that the Servlet Whiteboard implementation should determine the MIME type itself.

140.13.2.8 public String getRealPath(String path)

The virtual path to be translated to a real path.

Gets the real path corresponding to the given virtual path.

Called by the Servlet Whiteboard implementation to support the ServletContext method getRealPath for whiteboard services.

The real path, or null if the translation cannot be performed.

140.13.2.9 public URL getResource(String name)

The name of the requested resource.

Maps a resource name to a URL.

Called by the Servlet Whiteboard implementation to map the specified resource name to a URL. For servlets, the Servlet Whiteboard implementation will call this method to support the ServletContext methods getResource and getResourceAsStream. For resources, the Servlet Whiteboard implementation will call this method to locate the named resource.

The context can control from where resources come. For example, the resource can be mapped to a file in the bundle's persistent storage area via BundleContext.getDataFile(name).toURI().toURL() or to a resource in the context's bundle via getClass().getResource(name)

A URL that a Servlet Whiteboard implementation can use to read the resource or null if the resource does not exist.

140.13.2.10 public Set<String> getResourcePaths(String path)

The partial path used to match the resources, which must start with a /.

Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument.

Called by the Servlet Whiteboard implementation to support the ServletContext method getResourcePaths for whiteboard services.

A Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.

140.13.2.11 public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException

The HTTP request.

The HTTP response.

Handles security for the specified request.

The Servlet Whiteboard implementation calls this method prior to servicing the specified request. This method controls whether the request is processed in the normal manner or an error is returned.

If the request requires authentication and the Authorization header in the request is missing or not acceptable, then this method should set the WWW-Authenticate header in the response object, set the status in the response object to Unauthorized(401) and return false. See also RFC 2617: HTTP Authentication: Basic and Digest Access Authentication.

If the request requires a secure connection and the getScheme method in the request does not return 'https' or some other acceptable secure protocol, then this method should set the status in the response object to Forbidden(403) and return false.

When this method returns false, the Servlet Whiteboard implementation will send the response back to the client, thereby completing the request. When this method returns true, the Servlet Whiteboard implementation will proceed with servicing the request.

If the specified request has been authenticated, this method must set the AUTHENTICATION_TYPE request attribute to the type of authentication used, and the REMOTE_USER request attribute to the remote user (request attributes are set using the setAttribute method on the request). If this method does not perform any authentication, it must not set these attributes.

If the authenticated user is also authorized to access certain resources, this method must set the AUTHORIZATION request attribute to the Authorization object obtained from the org.osgi.service.useradmin.UserAdmin service.

The servlet responsible for servicing the specified request determines the authentication type and remote user by calling the getAuthType and getRemoteUser methods, respectively, on the request.

If there is the need to clean up resources at the end of the request, the method finishSecurity(HttpServletRequest, HttpServletResponse) can be implemented. That method is only called if this method returns true.

true if the request should be serviced, false if the request should not be serviced and Servlet Whiteboard implementation will send the response back to the client.

IOException– May be thrown by this method. If this occurs, the Servlet Whiteboard implementation will terminate the request and close the socket.

finishSecurity(HttpServletRequest, HttpServletResponse)

140.14 org.osgi.service.servlet.runtime

Version 2.0

Http Runtime Package Version 2.0.

Bundles wishing to use this package must list the package in the Import-Package header of the bundle's manifest. This package has two types of users: the consumers that use the API in this package and the providers that implement the API in this package.

Example import for consumers using the API in this package:

Import-Package: org.osgi.service.servlet.runtime; version="[2.0,3.0)"

Example import for providers implementing the API in this package:

Import-Package: org.osgi.service.servlet.runtime; version="[2.0,2.1)"

140.14.1 Summary

140.14.2 public interface HttpServiceRuntime

The HttpServiceRuntime service represents the runtime information of a Servlet Whiteboard implementation.

It provides access to DTOs representing the current state of the service.

The HttpServiceRuntime service must be registered with the HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT service property.

Thread-safe

Consumers of this API must not implement this type

140.14.2.1 public RequestInfoDTO calculateRequestInfoDTO(String path)

The request path, relative to the root of the Servlet Whiteboard implementation.

Return a request info DTO containing the services involved with processing a request for the specified path.

The request info DTO for the specified path.

140.14.2.2 public RuntimeDTO getRuntimeDTO()

Return the runtime DTO representing the current state.

The runtime DTO.

140.14.3 public final class HttpServiceRuntimeConstants

Defines standard names for Http Runtime Service constants.

140.14.3.1 public static final String HTTP_SERVICE_ENDPOINT = "osgi.http.endpoint"

Http Runtime Service service property specifying the endpoints upon which the Servlet Whiteboard implementation is listening.

An endpoint value is a URL or a relative path, to which the Servlet Whiteboard implementation is listening. For example, http://192.168.1.10:8080/ or /myapp/. A relative path may be used if the scheme and authority parts of the URL are not known, e.g. in a bridged Servlet Whiteboard implementation. If the Servlet Whiteboard implementation is serving the root context and neither scheme nor authority is known, the value of the property is "/". Both, a URL and a relative path, must end with a slash.

An Servlet Whiteboard implementation can be listening on multiple endpoints.

The value of this service property must be of type String, String[], or Collection<String>.

140.15 org.osgi.service.servlet.runtime.dto

Version 2.0

Http Runtime DTO Package Version 2.0.

Bundles wishing to use this package must list the package in the Import-Package header of the bundle's manifest. This package has two types of users: the consumers that use the API in this package and the providers that implement the API in this package.

Example import for consumers using the API in this package:

Import-Package: org.osgi.service.servlet.runtime.dto; version="[2.0,3.0)"

Example import for providers implementing the API in this package:

Import-Package: org.osgi.service.servlet.runtime.dto; version="[2.0,3.1)"

140.15.1 Summary

  • BaseServletDTO - Represents common information about a jakarta.servlet.Servlet service.

  • DTOConstants - Defines standard constants for the DTOs.

  • ErrorPageDTO - Represents a jakarta.servlet.Servlet for handling errors and currently being used by a servlet context.

  • FailedErrorPageDTO - Represents a jakarta.servlet.Servlet service registered as an error page but currently not being used by a servlet context due to a problem.

  • FailedFilterDTO - Represents a servlet Filter service which is currently not being used by a servlet context due to a problem.

  • FailedListenerDTO - Represents a listener service which is currently not being used by a servlet context due to a problem.

  • FailedPreprocessorDTO - Represents a preprocessor service which is currently not being used due to a problem.

  • FailedResourceDTO - Represents a resource definition which is currently not being used by a servlet context due to a problem.

  • FailedServletContextDTO - Represents a servlet context that is currently not used due to some problem.

  • FailedServletDTO - Represents a jakarta.servlet.Servlet service which is currently not being used by a servlet context due to a problem.

  • FilterDTO - Represents a servlet jakarta.servlet.Filter service currently being used for by a servlet context.

  • ListenerDTO - Represents a listener currently being used by a servlet context.

  • PreprocessorDTO - Represents a preprocessor org.osgi.service.servlet.whiteboard.Preprocessor service currently being used during request processing.

  • RequestInfoDTO - Represents the services used to process a specific request.

  • ResourceDTO - Represents a resource definition currently being used by a servlet context.

  • RuntimeDTO - Represents the state of a Http Service Runtime.

  • ServletContextDTO - Represents a jakarta.servlet.ServletContext created for servlets, resources, servlet Filters, and listeners associated with that servlet context.

  • ServletDTO - Represents a jakarta.servlet.Servlet currently being used by a servlet context.

140.15.2 public abstract class BaseServletDTO
extends DTO

Represents common information about a jakarta.servlet.Servlet service.

Not Thread-safe

140.15.2.1 public boolean asyncSupported

Specifies whether the servlet supports asynchronous processing.

140.15.2.2 public Map<String, String> initParams

The servlet initialization parameters as provided during registration of the servlet. Additional parameters like the Http Service Runtime attributes are not included. If the service has no initialization parameters, the map is empty.

140.15.2.3 public String name

The name of the servlet. This value is never null, unless this object represents a FailedServletDTO or a FailedErrorPageDTO where the value might be null.

140.15.2.4 public long serviceId

Service property identifying the servlet. In the case of a servlet registered in the service registry and picked up by a Servlet Whiteboard Implementation, this value is not negative and corresponds to the service id in the registry. If the servlet has not been registered in the service registry, the value is negative and a unique negative value is generated by the Http Service Runtime in this case.

140.15.2.5 public long servletContextId

The service id of the servlet context for the servlet represented by this DTO.

140.15.2.6 public String servletInfo

The information string from the servlet.

This is the value returned by the Servlet.getServletInfo() method. For a FailedServletDTO or a FailedErrorPageDTO this is always null.

140.15.2.7 public BaseServletDTO()

140.15.3 public final class DTOConstants

Defines standard constants for the DTOs.

140.15.3.1 public static final int FAILURE_REASON_EXCEPTION_ON_INIT = 4

An exception occurred during initializing of the service.

This reason can only happen for servlets and servlet filters.

140.15.3.2 public static final int FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING = 1

No matching org.osgi.service.servlet.context.ServletContextHelper.

140.15.3.3 public static final int FAILURE_REASON_SERVICE_IN_USE = 7

The service is not registered as a prototype scoped service and is already in use with a servlet context and therefore can't be used with another servlet context.

140.15.3.4 public static final int FAILURE_REASON_SERVICE_NOT_GETTABLE = 5

The service is registered in the service registry but getting the service fails as it returns null.

140.15.3.5 public static final int FAILURE_REASON_SERVLET_CONTEXT_FAILURE = 2

Matching org.osgi.service.servlet.context.ServletContextHelper, but the context is not used due to a problem with the context.

140.15.3.6 public static final int FAILURE_REASON_SERVLET_READ_FROM_DEFAULT_DENIED = 10

The servlet is not registered as it is configured to have multipart enabled, but the bundle containing the servlet has no read permission to the default location for the uploaded files.

140.15.3.7 public static final int FAILURE_REASON_SERVLET_WRITE_TO_LOCATION_DENIED = 8

The servlet is not registered as it is configured to have multipart enabled, but the bundle containing the servlet has no write permission to the provided location for the uploaded files.

140.15.3.8 public static final int FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE = 3

Service is shadowed by another service.

For example, another service with the same service properties but having a higher service ranking. See org.osgi.framework.ServiceReference.compareTo(Object).

140.15.3.9 public static final int FAILURE_REASON_UNKNOWN = 0

Failure reason is unknown.

140.15.3.10 public static final int FAILURE_REASON_VALIDATION_FAILED = 6

The service is registered in the service registry but the service properties are invalid.

140.15.3.11 public static final int FAILURE_REASON_WHITEBOARD_WRITE_TO_DEFAULT_DENIED = 9

The servlet is not registered as it is configured to have multipart enabled, but the whiteboard implementation has no write permission to the default location for the uploaded files.

140.15.3.12 public static final int FAILURE_REASON_WHITEBOARD_WRITE_TO_LOCATION_DENIED = 11

The servlet is not registered as it is configured to have multipart enabled, but the whiteboard implementation has no write permission to the provided location for the uploaded files.

140.15.4 public class ErrorPageDTO
extends BaseServletDTO

Represents a jakarta.servlet.Servlet for handling errors and currently being used by a servlet context.

Not Thread-safe

140.15.4.1 public long[] errorCodes

The error codes the error page is used for. This array might be empty.

140.15.4.2 public String[] exceptions

The exceptions the error page is used for. This array might be empty.

140.15.4.3 public ErrorPageDTO()

140.15.5 public class FailedErrorPageDTO
extends ErrorPageDTO

Represents a jakarta.servlet.Servlet service registered as an error page but currently not being used by a servlet context due to a problem.

As the servlet represented by this DTO is not used due to a failure, the field FailedErrorPageDTO.servletContextId always returns 0 and does not point to an existing org.osgi.service.servlet.context.ServletContextHelper.

Not Thread-safe

140.15.5.2 public FailedErrorPageDTO()

140.15.6 public class FailedFilterDTO
extends FilterDTO

Represents a servlet Filter service which is currently not being used by a servlet context due to a problem.

As the service represented by this DTO is not used due to a failure, the field FailedFilterDTO.servletContextId always returns 0 and does not point to an existing servlet context.

Not Thread-safe

140.15.6.2 public FailedFilterDTO()

140.15.7 public class FailedListenerDTO
extends ListenerDTO

Represents a listener service which is currently not being used by a servlet context due to a problem.

As the listener represented by this DTO is not used due to a failure, the field FailedErrorPageDTO.servletContextId always returns 0 and does not point to an existing servlet context.

Not Thread-safe

140.15.7.2 public FailedListenerDTO()

140.15.8 public class FailedPreprocessorDTO
extends PreprocessorDTO

Represents a preprocessor service which is currently not being used due to a problem.

Not Thread-safe

140.15.8.1 public int failureReason

The reason why the preprocessor represented by this DTO is not used.

DTOConstants.FAILURE_REASON_UNKNOWN, DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT, DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE

140.15.8.2 public FailedPreprocessorDTO()

140.15.9 public class FailedResourceDTO
extends ResourceDTO

Represents a resource definition which is currently not being used by a servlet context due to a problem.

As the resource represented by this DTO is not used due to a failure, the field FailedResourceDTO.servletContextId always returns 0 and does not point to an existing servlet context.

Not Thread-safe

140.15.9.2 public FailedResourceDTO()

140.15.10 public class FailedServletContextDTO
extends ServletContextDTO

Represents a servlet context that is currently not used due to some problem. The following fields return an empty array for a FailedServletContextDTO:

The method ServletContextDTO.attributes returns an empty map for a FailedServletContextDTO.

Not Thread-safe

140.15.10.2 public FailedServletContextDTO()

140.15.11 public class FailedServletDTO
extends ServletDTO

Represents a jakarta.servlet.Servlet service which is currently not being used by a servlet context due to a problem.

As the servlet represented by this DTO is not used due to a failure, the field FailedServletDTO.servletContextId always returns 0 and does not point to an existing servlet context.

Not Thread-safe

140.15.11.2 public FailedServletDTO()

140.15.12 public class FilterDTO
extends DTO

Represents a servlet jakarta.servlet.Filter service currently being used for by a servlet context.

Not Thread-safe

140.15.12.1 public boolean asyncSupported

Specifies whether the servlet filter supports asynchronous processing.

140.15.12.2 public String[] dispatcher

The dispatcher associations for the servlet filter.

The specified names are used to determine in what occasions the servlet filter is called. This array is never null.

140.15.12.3 public Map<String, String> initParams

The servlet filter initialization parameters as provided during registration of the servlet filter. Additional parameters like the Http Service Runtime attributes are not included. If the servlet filter has not initialization parameters, this map is empty.

140.15.12.4 public String name

The name of the servlet filter. This field is never null.

140.15.12.5 public String[] patterns

The request mappings for the servlet filter.

The specified patterns are used to determine whether a request is mapped to the servlet filter. This array might be empty.

140.15.12.6 public String[] regexs

The request mappings for the servlet filter.

The specified regular expressions are used to determine whether a request is mapped to the servlet filter. This array might be empty.

140.15.12.7 public long serviceId

Service property identifying the servlet filter. In the case of a servlet filter registered in the service registry and picked up by a Servlet Whiteboard Implementation, this value is not negative and corresponds to the service id in the registry. If the servlet filter has not been registered in the service registry, the value is negative and a unique negative value is generated by the Http Service Runtime in this case.

140.15.12.8 public long servletContextId

The service id of the servlet context for the servlet filter represented by this DTO.

140.15.12.9 public String[] servletNames

The servlet names for the servlet filter.

The specified names are used to determine the servlets whose requests are mapped to the servlet filter. This array might be empty.

140.15.12.10 public FilterDTO()

140.15.13 public class ListenerDTO
extends DTO

Represents a listener currently being used by a servlet context.

Not Thread-safe

140.15.13.1 public long serviceId

Service property identifying the listener. In the case of a Listener registered in the service registry and picked up by a Servlet Whiteboard Implementation, this value is not negative and corresponds to the service id in the registry. If the listener has not been registered in the service registry, the value is negative and a unique negative value is generated by the Http Service Runtime in this case.

140.15.13.2 public long servletContextId

The service id of the servlet context for the listener represented by this DTO.

140.15.13.3 public String[] types

The fully qualified type names the listener. This array is never empty.

140.15.13.4 public ListenerDTO()

140.15.14 public class PreprocessorDTO
extends DTO

Represents a preprocessor org.osgi.service.servlet.whiteboard.Preprocessor service currently being used during request processing.

Not Thread-safe

140.15.14.1 public Map<String, String> initParams

The preprocessor initialization parameters as provided during registration of the preprocessor. Additional parameters like the Http Service Runtime attributes are not included. If the preprocessor has not initialization parameters, this map is empty.

140.15.14.2 public long serviceId

Service property identifying the preprocessor. In the case of a preprocessor registered in the service registry and picked up by a Servlet Whiteboard Implementation, this value is not negative and corresponds to the service id in the registry. If the preprocessor has not been registered in the service registry, the value is negative and a unique negative value is generated by the Http Service Runtime in this case.

140.15.14.3 public PreprocessorDTO()

140.15.15 public class RequestInfoDTO
extends DTO

Represents the services used to process a specific request.

Not Thread-safe

140.15.15.1 public FilterDTO[] filterDTOs

The servlet filters processing this request. If no servlet filters are called for processing this request, an empty array is returned.

140.15.15.2 public String path

The path of the request relative to the root.

140.15.15.3 public ResourceDTO resourceDTO

The resource processing this request. If the request is processed by a resource, this field points to the DTO of the resource. If the request is processed by another type of component like a servlet, this field is null.

140.15.15.4 public long servletContextId

The service id of the servlet context processing the request represented by this DTO.

140.15.15.5 public ServletDTO servletDTO

The servlet processing this request. If the request is processed by a servlet, this field points to the DTO of the servlet. If the request is processed by another type of component like a resource, this field is null.

140.15.15.6 public RequestInfoDTO()

140.15.16 public class ResourceDTO
extends DTO

Represents a resource definition currently being used by a servlet context.

Not Thread-safe

140.15.16.1 public String[] patterns

The request mappings for the resource.

The specified patterns are used to determine whether a request is mapped to the resource. This value is never null.

140.15.16.2 public String prefix

The prefix of the resource.

140.15.16.3 public long serviceId

Service property identifying the resource. In the case of a resource registered in the service registry and picked up by a Servlet Whiteboard Implementation, this value is not negative and corresponds to the service id in the registry. If the resource has not been registered in the service registry, the value is negative and a unique negative value is generated by the Http Service Runtime in this case.

140.15.16.4 public long servletContextId

The service id of the servlet context for the resource represented by this DTO.

140.15.16.5 public ResourceDTO()

140.15.17 public class RuntimeDTO
extends DTO

Represents the state of a Http Service Runtime.

Not Thread-safe

140.15.17.1 public FailedErrorPageDTO[] failedErrorPageDTOs

Returns the representations of the error page jakarta.servlet.Servlet services associated with this runtime but currently not used due to some problem. The returned array may be empty.

140.15.17.2 public FailedFilterDTO[] failedFilterDTOs

Returns the representations of the jakarta.servlet.Filter services associated with this runtime but currently not used due to some problem. The returned array may be empty.

140.15.17.3 public FailedListenerDTO[] failedListenerDTOs

Returns the representations of the listeners associated with this runtime but currently not used due to some problem. The returned array may be empty.

140.15.17.4 public FailedPreprocessorDTO[] failedPreprocessorDTOs

Returns the representations of the servlet org.osgi.service.servlet.whiteboard.Preprocessor services associated with this runtime but currently not used due to some problem. The returned array may be empty.

140.15.17.5 public FailedResourceDTO[] failedResourceDTOs

Returns the representations of the resources associated with this runtime but currently not used due to some problem. The returned array may be empty.

140.15.17.6 public FailedServletContextDTO[] failedServletContextDTOs

Returns the representations of the jakarta.servlet.ServletContext objects currently not used by the Http service runtime due to some problem. The returned array may be empty.

140.15.17.7 public FailedServletDTO[] failedServletDTOs

Returns the representations of the jakarta.servlet.Servlet services associated with this runtime but currently not used due to some problem. The returned array may be empty.

140.15.17.8 public PreprocessorDTO[] preprocessorDTOs

Returns the representations of the org.osgi.service.servlet.whiteboard.Preprocessor objects used by the Http Service Runtime. The returned array may be empty if the Http Service Runtime is currently not using any org.osgi.service.servlet.whiteboard.Preprocessor objects.

140.15.17.9 public ServiceReferenceDTO serviceDTO

The DTO for the corresponding org.osgi.service.servlet.runtime.HttpServiceRuntime. This value is never null.

140.15.17.10 public ServletContextDTO[] servletContextDTOs

Returns the representations of the jakarta.servlet.ServletContext objects used by the Http Service Runtime. The returned array may be empty if the Http Service Runtime is currently not using any jakarta.servlet.ServletContext objects.

140.15.17.11 public RuntimeDTO()

140.15.18 public class ServletContextDTO
extends DTO

Represents a jakarta.servlet.ServletContext created for servlets, resources, servlet Filters, and listeners associated with that servlet context. The Servlet Context is usually backed by a ServletContextHelper service.

Not Thread-safe

140.15.18.1 public Map<String, Object> attributes

The servlet context attributes.

The value type must be a numerical type, Boolean, String, DTO or an array of any of the former. Therefore this method will only return the attributes of the servlet context conforming to this constraint. Other attributes are omitted. If there are no attributes conforming to the constraint, an empty map is returned.

140.15.18.2 public String contextPath

The servlet context path. This is the value returned by the ServletContext.getContextPath() method.

140.15.18.3 public ErrorPageDTO[] errorPageDTOs

Returns the representations of the error page Servlet services associated with this context. The representations of the error page Servlet services associated with this context. The returned array may be empty if this context is currently not associated with any error pages.

140.15.18.4 public FilterDTO[] filterDTOs

Returns the representations of the servlet Filter services associated with this context. The representations of the servlet Filter services associated with this context. The returned array may be empty if this context is currently not associated with any servlet Filter services.

140.15.18.5 public Map<String, String> initParams

The servlet context initialization parameters. This is the set of parameters provided when registering this context. Additional parameters like the Http Service Runtime attributes are not included. If the context has no initialization parameters, this map is empty.

140.15.18.6 public ListenerDTO[] listenerDTOs

Returns the representations of the listener services associated with this context. The representations of the listener services associated with this context. The returned array may be empty if this context is currently not associated with any listener services.

140.15.18.7 public String name

The name of the servlet context. The name of the corresponding ServletContextHelper.

This is the value returned by the ServletContext.getServletContextName() method.

140.15.18.8 public ResourceDTO[] resourceDTOs

Returns the representations of the resource services associated with this context. The representations of the resource services associated with this context. The returned array may be empty if this context is currently not associated with any resource services.

140.15.18.9 public long serviceId

Service property identifying the servlet context. In the case of a servlet context backed by a org.osgi.service.servlet.context.ServletContextHelper registered in the service registry and picked up by a Servlet Whiteboard Implementation, this value is not negative and corresponds to the service id in the registry. If the servlet context is not backed by a service registered in the service registry, the value is negative and a unique negative value is generated by the Http Service Runtime in this case.

140.15.18.10 public ServletDTO[] servletDTOs

Returns the representations of the Servlet services associated with this context. The representations of the Servlet services associated with this context. The returned array may be empty if this context is currently not associated with any Servlet services.

140.15.18.11 public ServletContextDTO()

140.15.19 public class ServletDTO
extends BaseServletDTO

Represents a jakarta.servlet.Servlet currently being used by a servlet context.

Not Thread-safe

140.15.19.1 public boolean multipartEnabled

Specifies whether multipart support is enabled.

140.15.19.2 public int multipartFileSizeThreshold

Specifies the size threshold after which the file will be written to disk. If multipart is not enabled for this servlet, 0 is returned.

multipartEnabled

140.15.19.3 public String multipartLocation

Specifies the location where the files can be stored on disk. If multipart is not enabled for this servlet, null is returned.

multipartEnabled

140.15.19.4 public long multipartMaxFileSize

Specifies the maximum size of a file being uploaded. If multipart is not enabled for this servlet, 0 is returned.

multipartEnabled

140.15.19.5 public long multipartMaxRequestSize

Specifies the maximum request size. If multipart is not enabled for this servlet, 0 is returned.

multipartEnabled

140.15.19.6 public String[] patterns

The request mappings for the servlet.

The specified patterns are used to determine whether a request is mapped to the servlet. This array is never null. It might be empty for named servlets.

140.15.19.7 public ServletDTO()

140.16 org.osgi.service.servlet.whiteboard

Version 2.0

Servlet Whiteboard Package Version 2.0.

Bundles wishing to use this package must list the package in the Import-Package header of the bundle's manifest. This package has two types of users: the consumers that use the API in this package and the providers that implement the API in this package.

Example import for consumers using the API in this package:

Import-Package: org.osgi.service.servlet.whiteboard; version="[2.0,3.0)"

Example import for providers implementing the API in this package:

Import-Package: org.osgi.service.servlet.whiteboard; version="[2.0,2.1)"

140.16.1 Summary

  • HttpWhiteboardConstants - Defines standard constants for the Servlet Whiteboard services.

  • Preprocessor - Services registered as a Preprocessor using a whiteboard pattern are executed for every request before the dispatching is performed.

140.16.2 public final class HttpWhiteboardConstants

Defines standard constants for the Servlet Whiteboard services.

140.16.2.1 public static final String DISPATCHER_ASYNC = "ASYNC"

Possible value for the HTTP_WHITEBOARD_FILTER_DISPATCHER property indicating the servlet filter is applied in the asynchronous context.

Jakarta Servlet Specification Version 5.0, Filters and the RequestDispatcher

140.16.2.2 public static final String DISPATCHER_ERROR = "ERROR"

Possible value for the HTTP_WHITEBOARD_FILTER_DISPATCHER property indicating the servlet filter is applied when an error page is called.

Jakarta Servlet Specification Version 5.0, Filters and the RequestDispatcher

140.16.2.3 public static final String DISPATCHER_FORWARD = "FORWARD"

Possible value for the HTTP_WHITEBOARD_FILTER_DISPATCHER property indicating the servlet filter is applied to forward calls to the dispatcher.

Jakarta Servlet Specification Version 5.0, Filters and the RequestDispatcher

140.16.2.4 public static final String DISPATCHER_INCLUDE = "INCLUDE"

Possible value for the HTTP_WHITEBOARD_FILTER_DISPATCHER property indicating the servlet filter is applied to include calls to the dispatcher.

Jakarta Servlet Specification Version 5.0, Filters and the RequestDispatcher

140.16.2.5 public static final String DISPATCHER_REQUEST = "REQUEST"

Possible value for the HTTP_WHITEBOARD_FILTER_DISPATCHER property indicating the servlet filter is applied to client requests.

Jakarta Servlet Specification Version 5.0, Filters and the RequestDispatcher

140.16.2.6 public static final String HTTP_WHITEBOARD_CONTEXT_INIT_PARAM_PREFIX = "context.init."

Service property prefix referencing a ServletContextHelper service.

For ServletContextHelper services this prefix can be used for service properties to mark them as initialization parameters which can be retrieved from the associated servlet context. The prefix is removed from the service property name to build the initialization parameter name.

For ServletContextHelper services, the value of each initialization parameter service property must be of type String.

140.16.2.7 public static final String HTTP_WHITEBOARD_CONTEXT_NAME = "osgi.http.whiteboard.context.name"

Service property specifying the name of an ServletContextHelper service.

For ServletContextHelper services, this service property must be specified. Context services without this service property are ignored.

Servlet, listener, servlet filter, and resource services might refer to a specific ServletContextHelper service referencing the name with the HTTP_WHITEBOARD_CONTEXT_SELECT property.

For ServletContextHelper services, the value of this service property must be of type String. The value must follow the "symbolic-name" specification from Section 1.3.2 of the OSGi Core Specification.

HTTP_WHITEBOARD_CONTEXT_PATH, HTTP_WHITEBOARD_CONTEXT_SELECT, HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME

140.16.2.8 public static final String HTTP_WHITEBOARD_CONTEXT_PATH = "osgi.http.whiteboard.context.path"

Service property specifying the path of an ServletContextHelper service.

For ServletContextHelper services this service property is required. Context services without this service property are ignored.

This property defines a context path under which all whiteboard services associated with this context are registered. Having different contexts with different paths allows to separate the URL space.

For ServletContextHelper services, the value of this service property must be of type String. The value is either a slash for the root or it must start with a slash but not end with a slash. Valid characters are defined in rfc3986#section-3.3. Contexts with an invalid path are ignored.

HTTP_WHITEBOARD_CONTEXT_NAME, HTTP_WHITEBOARD_CONTEXT_SELECT

140.16.2.9 public static final String HTTP_WHITEBOARD_CONTEXT_SELECT = "osgi.http.whiteboard.context.select"

Service property referencing a ServletContextHelper service.

For servlet, listener, servlet filter, or resource services, this service property refers to the associated ServletContextHelper service. The value of this property is a filter expression which is matched against the service registration properties of the ServletContextHelper service. If this service property is not specified, the default context is used. If there is no context service matching, the servlet, listener, servlet filter, or resource service is ignored.

For example, if a whiteboard service wants to select a servlet context helper with the name "Admin" the expression would be "(osgi.http.whiteboard.context.name=Admin)". Selecting all contexts could be done with "(osgi.http.whiteboard.context.name=*)".

For servlet, listener, servlet filter, or resource services, the value of this service property must be of type String.

HTTP_WHITEBOARD_CONTEXT_NAME, HTTP_WHITEBOARD_CONTEXT_PATH

140.16.2.10 public static final String HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME = "default"

The name of the default ServletContextHelper. If a service is registered with this property, it is overriding the default context with a custom provided context.

HTTP_WHITEBOARD_CONTEXT_NAME

140.16.2.11 public static final String HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED = "osgi.http.whiteboard.filter.asyncSupported"

Service property specifying whether a servlet Filter service supports asynchronous processing.

By default servlet filters services do not support asynchronous processing.

The value of this service property must be of type Boolean.

Jakarta Servlet Specification Version 5.0, Asynchronous Processing

140.16.2.12 public static final String HTTP_WHITEBOARD_FILTER_DISPATCHER = "osgi.http.whiteboard.filter.dispatcher"

Service property specifying the dispatcher handling of a servlet Filter.

By default servlet filter services are associated with client requests only (see value DISPATCHER_REQUEST).

The value of this service property must be of type String, String[], or Collection<String>. Allowed values are DISPATCHER_ASYNC, DISPATCHER_ERROR, DISPATCHER_FORWARD, DISPATCHER_INCLUDE, DISPATCHER_REQUEST.

Jakarta Servlet Specification Version 5.0, Filters and the RequestDispatcher

140.16.2.13 public static final String HTTP_WHITEBOARD_FILTER_INIT_PARAM_PREFIX = "filter.init."

Service property prefix referencing a Filter service.

For Filter services this prefix can be used for service properties to mark them as initialization parameters which can be retrieved from the associated filter config. The prefix is removed from the service property name to build the initialization parameter name.

For Filter services, the value of each initialization parameter service property must be of type String.

140.16.2.14 public static final String HTTP_WHITEBOARD_FILTER_NAME = "osgi.http.whiteboard.filter.name"

Service property specifying the servlet filter name of a Filter service.

This name is used as the value for the FilterConfig.getFilterName() method. If this service property is not specified, the fully qualified name of the service object's class is used as the servlet filter name.

Servlet filter names should be unique among all servlet filter services associated with a single ServletContextHelper.

The value of this service property must be of type String.

140.16.2.15 public static final String HTTP_WHITEBOARD_FILTER_PATTERN = "osgi.http.whiteboard.filter.pattern"

Service property specifying the request mappings for a Filter service.

The specified patterns are used to determine whether a request should be mapped to the servlet filter. Filter services without this service property or the HTTP_WHITEBOARD_FILTER_SERVLET or the HTTP_WHITEBOARD_FILTER_REGEX service property are ignored.

The value of this service property must be of type String, String[], or Collection<String>.

Jakarta Servlet Specification Version 5.0, Specification of Mappings

140.16.2.16 public static final String HTTP_WHITEBOARD_FILTER_REGEX = "osgi.http.whiteboard.filter.regex"

Service property specifying the request mappings for a servlet Filter service.

The specified regular expressions are used to determine whether a request should be mapped to the servlet filter. The regular expressions must follow the syntax defined in java.util.regex.Pattern. Servlet filter services without this service property or the HTTP_WHITEBOARD_FILTER_SERVLET or the HTTP_WHITEBOARD_FILTER_PATTERN service property are ignored.

The value of this service property must be of type String, String[], or Collection<String>.

java.util.regex.Pattern

140.16.2.17 public static final String HTTP_WHITEBOARD_FILTER_SERVLET = "osgi.http.whiteboard.filter.servlet"

Service property specifying the servlet names for a servlet Filter service.

The specified names are used to determine the servlets whose requests should be mapped to the servlet filter. Servlet filter services without this service property or the HTTP_WHITEBOARD_FILTER_PATTERN or the HTTP_WHITEBOARD_FILTER_REGEX service property are ignored.

The value of this service property must be of type String, String[], or Collection<String>.

140.16.2.18 public static final String HTTP_WHITEBOARD_IMPLEMENTATION = "osgi.http"

The name of the implementation capability for the Servlet Whiteboard specification

140.16.2.19 public static final String HTTP_WHITEBOARD_LISTENER = "osgi.http.whiteboard.listener"

Service property to mark a Listener service as a Whiteboard service. Listener services with this property set to the string value "true" will be treated as Whiteboard services opting in to being handled by the Servlet Whiteboard implementation. If the value "false" is specified, the service is opting out and this case is treated exactly the same as if this property is missing. If an invalid value is specified this is treated as a failure.

The value of this service property must be of type String. Valid values are "true" and "false" ignoring case.

140.16.2.20 public static final String HTTP_WHITEBOARD_PREPROCESSOR_INIT_PARAM_PREFIX = "preprocessor.init."

Service property prefix referencing a Preprocessor service.

For Preprocessor services this prefix can be used for service properties to mark them as initialization parameters which can be retrieved from the associated filter configuration. The prefix is removed from the service property name to build the initialization parameter name.

For Preprocessor services, the value of each initialization parameter service property must be of type String.

140.16.2.21 public static final String HTTP_WHITEBOARD_RESOURCE_PATTERN = "osgi.http.whiteboard.resource.pattern"

Service property specifying the request mappings for resources.

The specified patterns are used to determine whether a request should be mapped to resources. Resource services without this service property are ignored.

The value of this service property must be of type String, String[], or Collection<String>.

Jakarta Servlet Specification Version 5.0, Specification of Mappings, HTTP_WHITEBOARD_RESOURCE_PREFIX

140.16.2.22 public static final String HTTP_WHITEBOARD_RESOURCE_PREFIX = "osgi.http.whiteboard.resource.prefix"

Service property specifying the resource entry prefix for a resource service.

If a resource service is registered with this property, requests are served with bundle resources.

This prefix is used to map a requested resource to the bundle's entries. The value must not end with slash ("/") with the exception that a name of the form "/" is used to denote the root of the bundle. See the specification text for details on how HTTP requests are mapped.

The value of this service property must be of type String.

HTTP_WHITEBOARD_RESOURCE_PATTERN

140.16.2.23 public static final String HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED = "osgi.http.whiteboard.servlet.asyncSupported"

Service property specifying whether a Servlet service supports asynchronous processing.

By default servlet services do not support asynchronous processing.

The value of this service property must be of type Boolean.

Jakarta Servlet Specification Version 5.0, Asynchronous Processing

140.16.2.24 public static final String HTTP_WHITEBOARD_SERVLET_ERROR_PAGE = "osgi.http.whiteboard.servlet.errorPage"

Service property specifying whether a Servlet service acts as an error page.

The service property values may be the name of a fully qualified exception class, a three digit HTTP status code, the value "4xx" for all error codes in the 400 range, or the value "5xx" for all error codes in the 500 range. Any value that is not a three digit number, or one of the two special values is considered to be the name of a fully qualified exception class.

The value of this service property must be of type String, String[], or Collection<String>.

140.16.2.25 public static final String HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX = "servlet.init."

Service property prefix referencing a Servlet service.

For Servlet services this prefix can be used for service properties to mark them as initialization parameters which can be retrieved from the associated servlet config. The prefix is removed from the service property name to build the initialization parameter name.

For Servlet services, the value of each initialization parameter service property must be of type String.

140.16.2.26 public static final String HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED = "osgi.http.whiteboard.servlet.multipart.enabled"

Service property specifying whether a Servlet service has enabled multipart request processing.

By default servlet services do not have multipart request processing enabled.

The value of this service property must be of type Boolean.

Jakarta Servlet Specification Version 5.0, @MultipartConfig

140.16.2.27 public static final String HTTP_WHITEBOARD_SERVLET_MULTIPART_FILESIZETHRESHOLD = "osgi.http.whiteboard.servlet.multipart.fileSizeThreshold"

Service property specifying the size threshold after which the file will be written to disk.

When not set or when the value is not valid, the default threshold is determined by the implementation. This property is only evaluated if HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED is set to true .

The value of this service property must be of type Integer.

Jakarta Servlet Specification Version 5.0, Deployment Descriptor Schema

140.16.2.28 public static final String HTTP_WHITEBOARD_SERVLET_MULTIPART_LOCATION = "osgi.http.whiteboard.servlet.multipart.location"

Service property specifying the location where the files can be stored on disk.

When not set the default location is defined by the value of the system property "java.io.tmpdir". This property is only evaluated if HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED is set to true .

The value of this service property must be of type String.

Jakarta Servlet Specification Version 5.0, Deployment Descriptor Schema

140.16.2.29 public static final String HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXFILESIZE = "osgi.http.whiteboard.servlet.multipart.maxFileSize"

Service property specifying the maximum size of a file being uploaded.

When not set or when the value is not valid, the default maximum size is [@code -1} (no maximum size). This property is only evaluated if HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED is set to true .

The value of this service property must be of type Long.

Jakarta Servlet Specification Version 5.0, Deployment Descriptor Schema

140.16.2.30 public static final String HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXREQUESTSIZE = "osgi.http.whiteboard.servlet.multipart.maxRequestSize"

Service property specifying the maximum request size.

When not set or when the value is not valid, the default maximum request size is -1 (no maximum size). This property is only evaluated if HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED is set to true .

The value of this service property must be of type Long.

Jakarta Servlet Specification Version 5.0, Deployment Descriptor Schema

140.16.2.31 public static final String HTTP_WHITEBOARD_SERVLET_NAME = "osgi.http.whiteboard.servlet.name"

Service property specifying the servlet name of a Servlet service.

The servlet is registered with this name and the name can be used as a reference to the servlet for filtering or request dispatching.

This name is in addition used as the value for the ServletConfig.getServletName() method. If this service property is not specified, the fully qualified name of the service object's class is used as the servlet name. Filter services may refer to servlets by this name in their HTTP_WHITEBOARD_FILTER_SERVLET service property to apply the filter to the servlet.

Servlet names should be unique among all servlet services associated with a single ServletContextHelper.

The value of this service property must be of type String.

140.16.2.32 public static final String HTTP_WHITEBOARD_SERVLET_PATTERN = "osgi.http.whiteboard.servlet.pattern"

Service property specifying the request mappings for a Servlet service.

The specified patterns are used to determine whether a request should be mapped to the servlet. Servlet services without this service property, HTTP_WHITEBOARD_SERVLET_ERROR_PAGE or HTTP_WHITEBOARD_SERVLET_NAME are ignored.

The value of this service property must be of type String, String[], or Collection<String>.

Jakarta Servlet Specification Version 5.0, Specification of Mappings

140.16.2.33 public static final String HTTP_WHITEBOARD_SPECIFICATION_VERSION = "2.0"

The version of the implementation capability for the Servlet Whiteboard specification

140.16.2.34 public static final String HTTP_WHITEBOARD_TARGET = "osgi.http.whiteboard.target"

Service property specifying the target filter to select the Servlet Whiteboard implementation to process the service.

An Servlet Whiteboard implementation can define any number of service properties which can be referenced by the target filter. The service properties should always include the osgi.http.endpoint service property if the endpoint information is known.

If this service property is not specified, then all Servlet Whiteboard implementations can process the service.

The value of this service property must be of type String and be a valid filter string.

140.16.3 public interface Preprocessor
extends Filter

Services registered as a Preprocessor using a whiteboard pattern are executed for every request before the dispatching is performed.

If there are several services of this type, they are run in ranking order, the one with the highest ranking is used first.

The preprocessor is handled in the same way as filters. When a preprocessor is put into service Filter.init(jakarta.servlet.FilterConfig) is called, when it is not used anymore Filter.destroy() is called. As these preprocessors are run before dispatching and therefore the targeted servlet context is not known yet, jakarta.servlet.FilterConfig.getServletContext() returns the servlet context of the backing implementation. The same context is returned by the request object. The context path is the context path of this underlying servlet context. The passed in chain can be used to invoke the next preprocessor in the chain, or if the end of that chain is reached to start dispatching of the request. A preprocessor might decide to terminate the processing and directly generate a response.

Service properties with the prefix HttpWhiteboardConstants#HTTP_WHITEBOARD_PREPROCESSOR_INIT_PARAM_PREFIX are passed as init parameters to this service.

Thread-safe

140.17 org.osgi.service.servlet.whiteboard.annotations

Version 2.0

Servlet Whiteboard Annotations Package Version 2.0.

This package contains annotations that can be used to require the Servlet Whiteboard implementation.

Bundles should not normally need to import this package as the annotations are only used at build-time.

140.17.1 Summary

140.17.2 @RequireHttpWhiteboard

This annotation can be used to require the Servlet Whiteboard implementation. It can be used directly, or as a meta-annotation.

This annotation is applied to several of the Servlet Whiteboard component property annotations meaning that it does not normally need to be applied to Declarative Services components which use the Servlet Whiteboard.

CLASS

TYPE, PACKAGE

140.18 org.osgi.service.servlet.whiteboard.propertytypes

Version 2.0

Servlet Whiteboard Property Types Package Version 2.0.

When used as annotations, component property types are processed by tools to generate Component Descriptions which are used at runtime.

Bundles wishing to use this package at runtime must list the package in the Import-Package header of the bundle's manifest.

Example import for consumers using the API in this package:

Import-Package: org.osgi.service.servlet.whiteboard.propertytypes; version="[2.0,3.0)"

140.18.1 Summary

140.18.2 @HttpWhiteboardContext

Component Property Type for the osgi.http.whiteboard.context.name and osgi.http.whiteboard.context.path service properties.

This annotation can be used on a ServletContextHelper to declare the values of the HTTP_WHITEBOARD_CONTEXT_NAME and HTTP_WHITEBOARD_CONTEXT_PATH service properties.

Component Property Types

CLASS

TYPE

140.18.2.1 String name

Service property identifying a servlet context helper name.

The context name.

HTTP_WHITEBOARD_CONTEXT_NAME

140.18.2.2 String path

Service property identifying a servlet context helper path.

The context path.

HTTP_WHITEBOARD_CONTEXT_PATH

140.18.2.3 String PREFIX_ = "osgi.http.whiteboard.context."

Prefix for the property name. This value is prepended to each property name.

140.18.3 @HttpWhiteboardContextSelect

Component Property Type for the osgi.http.whiteboard.context.select service property.

This annotation can be used on a Servlet Whiteboard component to declare the value of the HTTP_WHITEBOARD_CONTEXT_SELECT service property.

Component Property Types

CLASS

TYPE

140.18.3.1 String value

Service property identifying the select property of a Servlet Whiteboard component.

The filter expression.

HTTP_WHITEBOARD_CONTEXT_SELECT

140.18.3.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.4 @HttpWhiteboardFilterAsyncSupported

Component Property Type for the osgi.http.whiteboard.filter.asyncSupported service property.

This annotation can be used on a jakarta.servlet.Filter to declare the value of the HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED service property.

Component Property Types

CLASS

TYPE

140.18.4.1 boolean asyncSupported default true

Service property identifying the asynchronous support of a filter.

Whether the filter supports asynchronous processing.

HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED

140.18.4.2 String PREFIX_ = "osgi.http.whiteboard.filter."

Prefix for the property name. This value is prepended to each property name.

140.18.5 @HttpWhiteboardFilterDispatcher

Component Property Type for the osgi.http.whiteboard.filter.dispatcher service property.

This annotation can be used on a jakarta.servlet.Filter to declare the value of the HTTP_WHITEBOARD_FILTER_DISPATCHER service property.

Component Property Types

CLASS

TYPE

140.18.5.1 DispatcherType[] value default jakarta.servlet.DispatcherType.REQUEST

Service property identifying dispatcher values for the filter.

The dispatcher values for the filter.

HTTP_WHITEBOARD_FILTER_DISPATCHER

140.18.5.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.6 @HttpWhiteboardFilterName

Component Property Type for the osgi.http.whiteboard.filter.name service property.

This annotation can be used on a jakarta.servlet.Filter to declare the value of the HTTP_WHITEBOARD_FILTER_NAME service property.

Component Property Types

CLASS

TYPE

140.18.6.1 String value

Service property identifying a filter name.

The filter name.

HTTP_WHITEBOARD_FILTER_NAME

140.18.6.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.7 @HttpWhiteboardFilterPattern

Component Property Type for the osgi.http.whiteboard.filter.pattern service property.

This annotation can be used on a jakarta.servlet.Filter to declare the value of the HTTP_WHITEBOARD_FILTER_PATTERN service property.

Component Property Types

CLASS

TYPE

140.18.7.1 String[] value

Service property identifying filter patterns.

The filter patterns.

HTTP_WHITEBOARD_FILTER_PATTERN

140.18.7.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.8 @HttpWhiteboardFilterRegex

Component Property Type for the osgi.http.whiteboard.filter.regex service property.

This annotation can be used on a jakarta.servlet.Filter to declare the value of the HTTP_WHITEBOARD_FILTER_REGEX service property.

Component Property Types

CLASS

TYPE

140.18.8.1 String[] value

Service property identifying filter regular expressions.

The regular expressions for the filter.

HTTP_WHITEBOARD_FILTER_REGEX

140.18.8.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.9 @HttpWhiteboardFilterServlet

Component Property Type for the osgi.http.whiteboard.filter.servlet service property.

This annotation can be used on a jakarta.servlet.Filter to declare the value of the HTTP_WHITEBOARD_FILTER_SERVLET service property.

Component Property Types

CLASS

TYPE

140.18.9.1 String[] value

Service property identifying the servlets for the filter.

The servlet names.

HTTP_WHITEBOARD_FILTER_SERVLET

140.18.9.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.10 @HttpWhiteboardListener

Component Property Type for the osgi.http.whiteboard.listener service property.

This annotation can be used on a Servlet Whiteboard listener to declare the value of the HTTP_WHITEBOARD_LISTENER service property as being Boolean.TRUE.

Component Property Types

CLASS

TYPE

140.18.10.1 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.11 @HttpWhiteboardResource

Component Property Type for the osgi.http.whiteboard.resource.pattern and osgi.http.whiteboard.resource.prefix service properties.

This annotation can be used on any service to declare the values of the HTTP_WHITEBOARD_RESOURCE_PATTERN and HTTP_WHITEBOARD_RESOURCE_PREFIX service properties.

Component Property Types

CLASS

TYPE

140.18.11.1 String[] pattern

Service property specifying the request mappings for resources. The specified patterns are used to determine whether a request should be mapped to resources.

The resource patterns.

HTTP_WHITEBOARD_RESOURCE_PATTERN

140.18.11.2 String prefix

Service property specifying the resource entry prefix for a resource service. This prefix is used to map a requested resource to the bundle's entries. The value must not end with slash ("/") with the exception that a name of the form "/" is used to denote the root of the bundle.

The resource prefix.

HTTP_WHITEBOARD_RESOURCE_PREFIX

140.18.11.3 String PREFIX_ = "osgi.http.whiteboard.resource."

Prefix for the property name. This value is prepended to each property name.

140.18.12 @HttpWhiteboardServletAsyncSupported

Component Property Type for the osgi.http.whiteboard.servlet.asyncSupported service property.

This annotation can be used on a jakarta.servlet.Servlet to declare the value of the HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED service property.

Component Property Types

CLASS

TYPE

140.18.12.1 boolean asyncSupported default true

Service property identifying the asynchronous support of a servlet.

Whether the servlet supports asynchronous processing.

HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED

140.18.12.2 String PREFIX_ = "osgi.http.whiteboard.servlet."

Prefix for the property name. This value is prepended to each property name.

140.18.13 @HttpWhiteboardServletErrorPage

Component Property Type for the osgi.http.whiteboard.servlet.errorPage service property.

This annotation can be used on a jakarta.servlet.Servlet to declare the value of the HTTP_WHITEBOARD_SERVLET_ERROR_PAGE service property.

Component Property Types

CLASS

TYPE

140.18.13.1 String[] errorPage

Service property identifying the error pages of a servlet.

The servlet error pages.

HTTP_WHITEBOARD_SERVLET_ERROR_PAGE

140.18.13.2 String PREFIX_ = "osgi.http.whiteboard.servlet."

Prefix for the property name. This value is prepended to each property name.

140.18.14 @HttpWhiteboardServletMultipart

Component Property Type for the osgi.http.whiteboard.servlet.multipart.enabled, osgi.http.whiteboard.servlet.multipart.fileSizeThreshold, osgi.http.whiteboard.servlet.multipart.location, osgi.http.whiteboard.servlet.multipart.maxFileSize, and osgi.http.whiteboard.servlet.multipart.maxRequestSize service properties.

This annotation can be used on a jakarta.servlet.Servlet to declare the values of the HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED, HTTP_WHITEBOARD_SERVLET_MULTIPART_FILESIZETHRESHOLD, HTTP_WHITEBOARD_SERVLET_MULTIPART_LOCATION, HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXFILESIZE, and HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXREQUESTSIZE service properties.

Component Property Types

CLASS

TYPE

140.18.14.1 boolean enabled default true

Service property identifying the multipart handling of a servlet.

Whether the servlet supports multipart handling.

HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED

140.18.14.2 int fileSizeThreshold default 0

Service property identifying the file size threshold for a multipart request handled by a servlet.

The file size threshold for a multipart request..

HTTP_WHITEBOARD_SERVLET_MULTIPART_FILESIZETHRESHOLD

140.18.14.3 String location default ""

Service property identifying the location for a multipart request handled by a servlet.

The location for a multipart request..

HTTP_WHITEBOARD_SERVLET_MULTIPART_LOCATION

140.18.14.4 long maxFileSize default -1L

Service property identifying the max file size for a multipart request handled by a servlet.

The max file size for a multipart request..

HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXFILESIZE

140.18.14.5 long maxRequestSize default -1L

Service property identifying the max request size for a multipart request handled by a servlet.

The max request size for a multipart request..

HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXREQUESTSIZE

140.18.14.6 String PREFIX_ = "osgi.http.whiteboard.servlet.multipart."

Prefix for the property name. This value is prepended to each property name.

140.18.15 @HttpWhiteboardServletName

Component Property Type for the osgi.http.whiteboard.servlet.name service property.

This annotation can be used on a jakarta.servlet.Servlet to declare the value of the HTTP_WHITEBOARD_SERVLET_NAME service property.

Component Property Types

CLASS

TYPE

140.18.15.1 String value

Service property identifying a servlet name.

The servlet name.

HTTP_WHITEBOARD_SERVLET_NAME

140.18.15.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.16 @HttpWhiteboardServletPattern

Component Property Type for the osgi.http.whiteboard.servlet.pattern service property.

This annotation can be used on a jakarta.servlet.Servlet to declare the value of the HTTP_WHITEBOARD_SERVLET_PATTERN service property.

Component Property Types

CLASS

TYPE

140.18.16.1 String[] value

Service property identifying servlet patterns.

The servlet patterns.

HTTP_WHITEBOARD_SERVLET_PATTERN

140.18.16.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.18.17 @HttpWhiteboardTarget

Component Property Type for the osgi.http.whiteboard.target service property.

This annotation can be used on a Servlet Whiteboard service to declare the value of the HTTP_WHITEBOARD_TARGET service property.

Component Property Types

CLASS

TYPE

140.18.17.1 String value

Service property identifying the Servlet Whiteboard target.

The Servlet Whiteboard target filter expression.

HTTP_WHITEBOARD_TARGET

140.18.17.2 String PREFIX_ = "osgi."

Prefix for the property name. This value is prepended to each property name.

140.19 References

[1]HTTP 1.0 Specification RFC-1945https://www.ietf.org/rfc/rfc1945.txt, May 1996

[3]HTTP/2 Specificationshttps://http2.github.io

[4]Jakarta Servlet 5.0 Specificationhttps://jakarta.ee/specifications/servlet/5.0/

[6]RFC 2617: HTTP Authentication: Basic and Digest Access Authenticationhttps://www.ietf.org/rfc/rfc2617.txt

[8]Core Service HooksOSGi Core, Chapter 55 Service Hook Service Specification

140.20 Changes

  • This specification is providing the same functionality as its predecessor, [9] Http Whiteboard Specification, with the switch from the Java Servlet API to the Jakarta Servlet API.

  • Removed the reference to the [10] Http Service Specification specying the behaviour if an implementation is also implementing that specification.