HttpContext

Syntax

public interface HttpContext

Description

HttpContext defines methods that HttpService may call to get information about a registration. Servlets and resources must be registered with a HttpContext object. Servlets which are registered using the same HttpContext object will share the same ServletContext.

This interface is implemented by users of HttpService.

Member Summary
Methods
public StringgetMimeType(String)
 Map a name to a MIME type.
public URLgetResource(String)
 Map a resource name to a URL.
public booleanhandleSecurity(HttpServletRequest, HttpServletResponse)
 Handle security for a request.

Methods

getMimeType(String)
public java.lang.String getMimeType(java.lang.String name)

Map a name to a MIME type. Called by HttpService to determine the MIME type for the name. For servlet registrations, HttpService will call this method to support the ServletContext method getMimeType. For resource registrations, HttpService will call this method to determine the MIME type for the Content-Type header in the response.

Parameters:

name— determine the MIME type for this name.

Returns: MIME type (e.g., text/html) of the name or null to indicate that HttpService should determine the MIME type.

getResource(String)
public java.net.URL getResource(java.lang.String name)

Map a resource name to a URL. Called by HttpService to map a resource name to a URL. For servlet registrations, HttpService will call this method to support the ServletContext methods getResource and getResourceAsStream. For resource registrations, HttpService 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

this.getClass().getResource(name)

Parameters:

name— the name of the requested resource

Returns: URL that HttpService can use to read the resource or null if the resource does not exist.

handleSecurity(HttpServletRequest, HttpServletResponse)
public boolean handleSecurity(javax.servlet.http.HttpServletRequest
            request,
            javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException

Handle security for a request. HttpService calls this method prior to servicing a request. This method controls whether a request is processed in the normal manner or an error is returned.

If a 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 HTTP Authentication: Basic and Digest Access Authentication (http://www.ietf.org/rfc/rfc2617.txt).

If a 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, HttpService will send the response back to the client completing the request. When this method returns true, HttpService will proceed with servicing the request.

Parameters:

request— the HTTP request

response— the HTTP response

Returns: true if the request should be serviced, false if the request should not be serviced and HttpService will send the response back to the client.

Throws:

java.io.IOException— may be thrown by this method. If this occurs HttpService will terminate the request and close the socket.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.26.108