Lightweight HTTP Server 1.0.0.Beta1

org.jboss.sun.net.httpserver
Class HttpServerImpl

java.lang.Object
  extended by org.jboss.com.sun.net.httpserver.HttpHost
      extended by org.jboss.com.sun.net.httpserver.HttpServer
          extended by org.jboss.sun.net.httpserver.HttpServerImpl

public class HttpServerImpl
extends HttpServer


Method Summary
 void bind(InetSocketAddress addr, int backlog)
          Binds a currently unbound HttpServer to the given address and port number.
 org.jboss.sun.net.httpserver.HttpContextImpl createContext(String path)
          Creates a HttpContext without initially specifying a handler.
 org.jboss.sun.net.httpserver.HttpContextImpl createContext(String path, HttpHandler handler)
          Creates a HttpContext.
 InetSocketAddress getAddress()
          returns the address this server is listening on
 Executor getExecutor()
          returns this server's Executor object if one was specified with HttpServer.setExecutor(Executor), or null if none was specified.
 void removeContext(HttpContext context)
          Removes the given context from the server.
 void removeContext(String path)
          Removes the context identified by the given path from the server.
 void setExecutor(Executor executor)
          sets this server's Executor object.
 void start()
          Starts this server in a new background thread.
 void stop(int delay)
          stops this server by closing the listening socket and disallowing any new exchanges from being processed.
 
Methods inherited from class org.jboss.com.sun.net.httpserver.HttpServer
create, create, createVirtualHost, removeVirtualHost, removeVirtualHost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bind

public void bind(InetSocketAddress addr,
                 int backlog)
          throws IOException
Description copied from class: HttpServer
Binds a currently unbound HttpServer to the given address and port number. A maximum backlog can also be specified. This is the maximum number of queued incoming connections to allow on the listening socket. Queued TCP connections exceeding this limit may be rejected by the TCP implementation.

Specified by:
bind in class HttpServer
Parameters:
addr - the address to listen on
backlog - the socket backlog. If this value is less than or equal to zero, then a system default value is used.
Throws:
BindException - if the server cannot bind to the requested address or if the server is already bound.
IOException

start

public void start()
Description copied from class: HttpServer
Starts this server in a new background thread. The background thread inherits the priority, thread group and context class loader of the caller.

Specified by:
start in class HttpServer

setExecutor

public void setExecutor(Executor executor)
Description copied from class: HttpServer
sets this server's Executor object. An Executor must be established before HttpServer.start() is called. All HTTP requests are handled in tasks given to the executor. If this method is not called (before start()) or if it is called with a null Executor, then a default implementation is used, which uses the thread which was created by the HttpServer.start() method.

Specified by:
setExecutor in class HttpServer
Parameters:
executor - the Executor to set, or null for default implementation

getExecutor

public Executor getExecutor()
Description copied from class: HttpServer
returns this server's Executor object if one was specified with HttpServer.setExecutor(Executor), or null if none was specified.

Specified by:
getExecutor in class HttpServer
Returns:
the Executor established for this server or null if not set.

stop

public void stop(int delay)
Description copied from class: HttpServer
stops this server by closing the listening socket and disallowing any new exchanges from being processed. The method will then block until all current exchange handlers have completed or else when approximately delay seconds have elapsed (whichever happens sooner). Then, all open TCP connections are closed, the background thread created by start() exits, and the method returns. Once stopped, a HttpServer cannot be re-used.

Specified by:
stop in class HttpServer
Parameters:
delay - the maximum time in seconds to wait until exchanges have finished.

createContext

public org.jboss.sun.net.httpserver.HttpContextImpl createContext(String path,
                                                                  HttpHandler handler)
Description copied from class: HttpServer
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 HttpHost.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.

Specified by:
createContext in class HttpServer
Parameters:
path - the root URI path to associate the context with
handler - the handler to invoke for incoming requests.

createContext

public org.jboss.sun.net.httpserver.HttpContextImpl createContext(String path)
Description copied from class: HttpServer
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 HttpHost.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.

Specified by:
createContext in class HttpServer
Parameters:
path - the root URI path to associate the context with

removeContext

public void removeContext(String path)
                   throws IllegalArgumentException
Description copied from class: HttpServer
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.

Specified by:
removeContext in class HttpServer
Parameters:
path - the path of the handler to remove
Throws:
IllegalArgumentException - if no handler corresponding to this path exists.

removeContext

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

Specified by:
removeContext in class HttpServer
Parameters:
context - the context to remove
Throws:
IllegalArgumentException - if the given context is not registered on this host

getAddress

public InetSocketAddress getAddress()
Description copied from class: HttpServer
returns the address this server is listening on

Specified by:
getAddress in class HttpServer
Returns:
the address/port number the server is listening on

Lightweight HTTP Server 1.0.0.Beta1

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