Class HttpContext

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 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.

Since:
1.6
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor for subclasses to call.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Map<String,Object>
    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 Authenticator
    Returns the currently set Authenticator for this context if one exists.
    abstract List<Filter>
    Returns this context's List of filters.
    abstract HttpHandler
    Returns the handler for this context.
    abstract String
    Returns the path this context was created with.
    abstract HttpServer
    Returns the server this context was created with.
    abstract Authenticator
    Sets the Authenticator for this HttpContext.
    abstract void
    Sets the handler for this context, if not already set.

    Methods declared in class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
    Creates and returns a copy of this object.
    boolean
    Indicates whether some other object is "equal to" this one.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Finalization is deprecated and subject to removal in a future release.
    final Class<?>
    Returns the runtime class of this Object.
    int
    Returns a hash code value for this object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
    final void
    wait(long timeoutMillis)
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
    final void
    wait(long timeoutMillis, int nanos)
    Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  • Constructor Details

    • HttpContext

      protected HttpContext()
      Constructor for subclasses to call.
  • Method Details

    • getHandler

      public abstract HttpHandler getHandler()
      Returns the handler for this context.
      Returns:
      the HttpHandler for this context
    • setHandler

      public abstract void setHandler(HttpHandler handler)
      Sets the handler for this context, if not already set.
      Parameters:
      handler - the handler to set for this context
      Throws:
      IllegalArgumentException - if the context for this handler is already set.
      NullPointerException - if handler is null
    • getPath

      public abstract String getPath()
      Returns the path this context was created with.
      Returns:
      the context of this path
    • getServer

      public abstract HttpServer getServer()
      Returns the server this context was created with.
      Returns:
      the context of this 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.

      Returns:
      a Map containing the attributes of 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 handling of exchanges.
      Returns:
      a List containing the filters of this context
    • setAuthenticator

      public abstract Authenticator setAuthenticator(Authenticator auth)
      Sets the 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.
      Parameters:
      auth - the Authenticator to set. If null then any previously set Authenticator is removed, and client authentication will no longer be required.
      Returns:
      the previous Authenticator, if any set, or null otherwise.
    • getAuthenticator

      public abstract Authenticator getAuthenticator()
      Returns the currently set Authenticator for this context if one exists.
      Returns:
      this HttpContext's Authenticator, or null if none is set