public abstract class HttpContext extends Object
HttpContext
represents a mapping between the root URI
path of an application to a HttpHandler
which 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 Filter
objects can be added to a HttpContext
. All exchanges processed by the context can be pre- and post-processed by each Filter
in the chain.
Modifier | Constructor | Description |
---|---|---|
protected |
Constructor for subclasses to call. |
Modifier and Type | Method | Description |
---|---|---|
abstract Map |
getAttributes() |
|
abstract Authenticator |
getAuthenticator() |
Returns the currently set Authenticator for this context if one exists. |
abstract List |
getFilters() |
|
abstract HttpHandler |
getHandler() |
Returns the handler for this context. |
abstract String |
getPath() |
Returns the path this context was created with. |
abstract HttpServer |
getServer() |
Returns the server this context was created with. |
abstract Authenticator |
setAuthenticator |
Sets the Authenticator for this HttpContext . |
abstract void |
setHandler |
Sets the handler for this context, if not already set. |
protected HttpContext()
public abstract HttpHandler getHandler()
HttpHandler
for this contextpublic abstract void setHandler(HttpHandler handler)
handler
- the handler to set for this contextIllegalArgumentException
- if the context for this handler is already set.NullPointerException
- if handler is null
public abstract String getPath()
public abstract HttpServer getServer()
public abstract Map<String,Object> getAttributes()
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.
Map
containing the attributes of this contextpublic abstract List<Filter> getFilters()
List
of filters. This is the actual list used by the server when dispatching requests so modifications to this list immediately affect the handling of exchanges.List
containing the filters of this contextpublic abstract Authenticator setAuthenticator(Authenticator auth)
Authenticator
for this HttpContext
. Once an authenticator is established 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.auth
- the Authenticator
to set. If null
then any previously set Authenticator
is removed, and client authentication will no longer be required.Authenticator
, if any set, or null
otherwise.public abstract Authenticator getAuthenticator()
Authenticator
for this context if one exists.Authenticator
, or null
if none is set
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.httpserver/com/sun/net/httpserver/HttpContext.html