Lightweight HTTP Server 1.0.0.Beta1

org.jboss.com.sun.net.httpserver
Class HttpHost

java.lang.Object
  extended by org.jboss.com.sun.net.httpserver.HttpHost
Direct Known Subclasses:
HttpServer

public abstract class HttpHost
extends Object

This class implements a simple HTTP host. A HttpHost may be "real" or "virtual". A "real" host is one which is bound to an IP address and extends the HttpServer subclass. A "virtual" host allows for more than one set of registered contexts per physical server, differentiated by host name, IP address, or other criteria.

One or more HttpHandler objects must be associated with a host in order to process requests. Each such HttpHandler is registered with a root URI path which represents the location of the application or service on this server. The mapping of a handler to a HttpHost is essentially equivalent to the mapping of a handler to a HttpServer.

Since:
1.7

Constructor Summary
HttpHost()
           
 
Method Summary
abstract  HttpContext createContext(String path)
          Creates a HttpContext without initially specifying a handler.
abstract  HttpContext createContext(String path, HttpHandler handler)
          Creates a HttpContext.
abstract  void removeContext(HttpContext context)
          Removes the given context from the server.
abstract  void removeContext(String path)
          Removes the context identified by the given path from the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpHost

public HttpHost()
Method Detail

createContext

public abstract HttpContext createContext(String path,
                                          HttpHandler handler)
Creates a HttpContext. A HttpContext represents a mapping from a URI path to a exchange handler on this HttpHost. Once created, all requests received by the server for the path will be handled by calling the given handler object. The context is identified by the path, and can later be removed from the server using this with the removeContext(String) method.

The path specifies the root URI path for this context. The first character of path must be '/'.

The class overview describes how incoming request URIs are mapped to HttpContext instances.

Parameters:
path - the root URI path to associate the context with
handler - the handler to invoke for incoming requests.
Throws:
IllegalArgumentException - if path is invalid, or if a context already exists for this path
NullPointerException - if either path, or handler are null

createContext

public abstract HttpContext createContext(String path)
Creates a HttpContext without initially specifying a handler. The handler must later be specified using com.sun.net.httpserver.HttpContext#setHandler(com.sun.net.httpserver.HttpHandler). A HttpContext represents a mapping from a URI path to an exchange handler on this HttpHost. Once created, and when the handler has been set, all requests received by the server for the path will be handled by calling the handler object. The context is identified by the path, and can later be removed from the server using this with the removeContext(String) method.

The path specifies the root URI path for this context. The first character of path must be '/'.

The class overview describes how incoming request URIs are mapped to HttpContext instances.

Parameters:
path - the root URI path to associate the context with
Throws:
IllegalArgumentException - if path is invalid, or if a context already exists for this path
NullPointerException - if path is null

removeContext

public abstract void removeContext(String path)
                            throws IllegalArgumentException
Removes the context identified by the given path from the server. Removing a context does not affect exchanges currently being processed but prevents new ones from being accepted.

Parameters:
path - the path of the handler to remove
Throws:
IllegalArgumentException - if no handler corresponding to this path exists.
NullPointerException - if path is null

removeContext

public abstract void removeContext(HttpContext context)
                            throws IllegalArgumentException
Removes the given context from the server. Removing a context does not affect exchanges currently being processed but prevents new ones from being accepted.

Parameters:
context - the context to remove
Throws:
IllegalArgumentException - if the given context is not registered on this host
NullPointerException - if context is null

Lightweight HTTP Server 1.0.0.Beta1

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.