- java.lang.Object
-
- com.sun.net.httpserver.HttpContext
-
public abstract class HttpContext extends Object
HttpContext represents a mapping between the root URI path of an application to aHttpHandlerwhich is invoked to handle requests destined for that path on the associated HttpServer or HttpsServer.HttpContext instances are created by the create methods in HttpServer and HttpsServer
A chain of
Filterobjects can be added to a HttpContext. All exchanges processed by the context can be pre- and post-processed by each Filter in the chain.- Since:
- 1.6
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpContext()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract Map<String,Object>getAttributes()returns a mutable Map, which can be used to pass configuration and other data to Filter modules and to the context's exchange handler.abstract AuthenticatorgetAuthenticator()Returns the currently set Authenticator for this context if one exists.abstract List<Filter>getFilters()returns this context's list of Filters.abstract HttpHandlergetHandler()returns the handler for this contextabstract StringgetPath()returns the path this context was created withabstract HttpServergetServer()returns the server this context was created withabstract AuthenticatorsetAuthenticator(Authenticator auth)Sets the Authenticator for this HttpContext.abstract voidsetHandler(HttpHandler h)Sets the handler for this context, if not already set.
-
-
-
Method Detail
-
getHandler
public abstract HttpHandler getHandler()
returns the handler for this context- Returns:
- the HttpHandler for this context
-
setHandler
public abstract void setHandler(HttpHandler h)
Sets the handler for this context, if not already set.- Parameters:
h- the handler to set for this context- Throws:
IllegalArgumentException- if this context's handler is already set.NullPointerException- if handler isnull
-
getPath
public abstract String getPath()
returns the path this context was created with- Returns:
- this context's path
-
getServer
public abstract HttpServer getServer()
returns the server this context was created with- Returns:
- this context's server
-
getAttributes
public abstract Map<String,Object> getAttributes()
returns a mutable Map, which can be used to pass configuration and other data to Filter modules and to the context's exchange handler.Every attribute stored in this Map will be visible to every HttpExchange processed by this context
-
getFilters
public abstract List<Filter> getFilters()
returns this context's list of Filters. This is the actual list used by the server when dispatching requests so modifications to this list immediately affect the the handling of exchanges.
-
setAuthenticator
public abstract Authenticator setAuthenticator(Authenticator auth)
Sets the Authenticator for this HttpContext. Once an authenticator is establised on a context, all client requests must be authenticated, and the given object will be invoked to validate each request. Each call to this method replaces any previous value set.- Parameters:
auth- the authenticator to set. Ifnullthen any previously set authenticator is removed, and client authentication will no longer be required.- Returns:
- the previous Authenticator, if any set, or
nullotherwise.
-
getAuthenticator
public abstract Authenticator getAuthenticator()
Returns the currently set Authenticator for this context if one exists.- Returns:
- this HttpContext's Authenticator, or
nullif none is set.
-
-