@ConsumerType public abstract class ServletContextHelper extends Object
This service defines methods that the Http Whiteboard implementation may call to get information for a request when dealing with whiteboard services.
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 with the highest service ranking is active, the others are
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 by service ranking order according to
ServiceReference.compareTo(Object) 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
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
The behavior of the methods on the default
defined as follows:
getMimeType- Always returns
handleSecurity- Always returns
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.getEntrymethod, and returns the appropriate URL to access the resource. On a Java runtime environment that supports permissions, the Http Whiteboard implementation needs to be granted
getResourcePaths- Assumes that the resources are in the bundle of the whiteboard service. This method calls
Bundle.findEntriesmethod, and returns the found entries. On a Java runtime environment that supports permissions, the Http Whiteboard implementation needs to be granted
getRealPath- Always returns
|Modifier and Type||Field and Description|
|Constructor and Description|
Construct a new context helper.
Construct a new context helper associated with the specified bundle.
|Modifier and Type||Method and Description|
Maps a name to a MIME type.
Gets the real path corresponding to the given virtual path.
Maps a resource name to a URL.
Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument.
Handles security for the specified request.
public static final String REMOTE_USER
HttpServletRequestattribute specifying the name of the authenticated user. The value of the attribute can be retrieved by
public static final String AUTHENTICATION_TYPE
HttpServletRequestattribute specifying the scheme used in authentication. The value of the attribute can be retrieved by
public static final String AUTHORIZATION
HttpServletRequestattribute specifying the
Authorizationobject obtained from the
org.osgi.service.useradmin.UserAdminservice. The value of the attribute can be retrieved by
If needed, the subclass will have to handle the association with a specific bundle.
public ServletContextHelper(Bundle bundle)
bundle- The bundle to be associated with this context helper.
public boolean handleSecurity(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
The Http 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
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
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
When this method returns
false, the Http Whiteboard
implementation will send the response back to the client, thereby
completing the request. When this method returns
true, the Http
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
The servlet responsible for servicing the specified request determines
the authentication type and remote user by calling the
getRemoteUser methods, respectively, on
request- The HTTP request.
response- The HTTP response.
trueif the request should be serviced,
falseif the request should not be serviced and Http Whiteboard implementation will send the response back to the client.
IOException- May be thrown by this method. If this occurs, the Http Whiteboard implementation will terminate the request and close the socket.
Called by the Http Whiteboard implementation to map the specified
resource name to a URL. For servlets, the Http Whiteboard implementation
will call this method to support the
getResourceAsStream. For resources, the
Http Whiteboard implementation will call this method to locate the named
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
BundleContext.getDataFile(name).toURI().toURL() or to a
resource in the context's bundle via
name- The name of the requested resource.
nullif the resource does not exist.
Called by the Http Whiteboard implementation to determine the MIME type
for the specified name. For whiteboard services, the Http Whiteboard
implementation will call this method to support the
getMimeType. For resource servlets,
the Http Whiteboard implementation will call this method to determine the
MIME type for the
Content-Type header in the response.
name- The name for which to determine the MIME type.
nullto indicate that the Http Whiteboard implementation should determine the MIME type itself.
Called by the Http Whiteboard implementation to support the
getResourcePaths for whiteboard
path- The partial path used to match the resources, which must start with a /.
nullif there are no resources in the web application whose path begins with the supplied path.
Called by the Http Whiteboard implementation to support the
getRealPath for whiteboard
path- The virtual path to be translated to a real path.
nullif the translation cannot be performed.
Copyright © OSGi Alliance (2000, 2015). All Rights Reserved. Licensed under the OSGi Specification License, Version 2.0