public class HttpExternalResourceContext extends Object implements org.osgi.service.http.HttpContext
Constructor and Description |
---|
HttpExternalResourceContext(String rootDir) |
Modifier and Type | Method and Description |
---|---|
String |
getMimeType(String name)
Maps a name to a MIME type.
|
URL |
getResource(String name)
Maps a resource name to a URL.
|
boolean |
handleSecurity(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handles security for the specified request.
|
public HttpExternalResourceContext(String rootDir)
public boolean handleSecurity(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
false
. See
also RFC 2617: HTTP Authentication: Basic and Digest Access
Authentication (available at http://www.ietf.org/rfc/rfc2617.txt).
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 Http Service will send
the response back to the client, thereby completing the request. When
this method returns true
, the Http Service will proceed with
servicing the request.
If the specified request has been authenticated, this method must set the
HttpContext.AUTHENTICATION_TYPE
request attribute to the type of
authentication used, and the HttpContext.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 HttpContext.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.handleSecurity
in interface org.osgi.service.http.HttpContext
request
- the HTTP requestresponse
- the HTTP responsetrue
if the request should be serviced, false
if the request should not be serviced and Http Service will send
the response back to the client.IOException
- may be thrown by this method. If this
occurs, the Http Service will terminate the request and close
the socket.public URL getResource(String name)
ServletContext
methods getResource
and
getResourceAsStream
. For resource registrations, Http Service
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).toURL()
or to a resource in
the context's bundle via getClass().getResource(name)
getResource
in interface org.osgi.service.http.HttpContext
name
- the name of the requested resourcenull
if the resource does not exist.public String getMimeType(String name)
ServletContext
method getMimeType
. For
resource registrations, the Http Service will call this method to
determine the MIME type for the Content-Type header in the response.getMimeType
in interface org.osgi.service.http.HttpContext
name
- determine the MIME type for this name.null
to
indicate that the Http Service should determine the MIME type
itself.Copyright © 2012-2013 ADELE Research Group. All Rights Reserved.