org.mortbay.http
Interface HttpListener

All Superinterfaces:
LifeCycle, java.io.Serializable
All Known Implementing Classes:
AJP13Listener, HostSocketListener, IbmJsseListener, JsseListener, SocketChannelListener, SocketListener, SslListener, SunJsseListener

public interface HttpListener
extends LifeCycle, java.io.Serializable

HTTP Listener. This interface describes the methods of a generic request listener for the HttpServer. This class should probably be called HttpConnector, but it's name predates the EventListener API in java. Once a HttpListener is started, it is responsible for listening for new connections. Once a new connection is accepted it should be handled by creating a HttpConnection instance and calling either the HttpConnection.handle() or HttpConnection.handleNext() methods from a Thread allocated to that connection.

Version:
$Id: HttpListener.java,v 1.17 2005/03/15 10:03:40 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
HttpConnection, HttpServer

Field Summary
static java.lang.String ATTRIBUTE
           
 
Method Summary
 void customizeRequest(HttpConnection connection, HttpRequest request)
          Customize a request for a listener/connection combination.
 int getBufferReserve()
          Get the size of the header reserve area.
 int getBufferSize()
          Get the size of the buffers used by connections from this listener.
 int getConfidentialPort()
          Get the protocol port to use for confidential redirections.
 java.lang.String getConfidentialScheme()
          Get the protocol scheme to use for confidential redirections.
 java.lang.String getDefaultScheme()
          Get the default scheme for requests.
 java.lang.String getHost()
          Get the host or IP of the interface used by this listener.
 HttpHandler getHttpHandler()
          Get an optional HttpHandler for the listener.
 HttpServer getHttpServer()
          Get the HttpServer instance for this HttpListener.
 int getIntegralPort()
          Get the protocol port to use for integral redirections.
 java.lang.String getIntegralScheme()
          Get the protocol scheme to use for integral redirections.
 int getPort()
          Get the port number of the listener.
 boolean isConfidential(HttpConnection connection)
          Get the confidential status of a connection.
 boolean isIntegral(HttpConnection connection)
          Get the integral status of a connection.
 boolean isLowOnResources()
          Get the low on resources state of the listener.
 boolean isOutOfResources()
          Get the out of resources state of the listener.
 void persistConnection(HttpConnection connection)
          Prepare a connection for persistance.
 void setHost(java.lang.String host)
          Set the host or IP of the interface used by this listener.
 void setHttpServer(HttpServer server)
          Set the HttpServer instance for this HttpListener.
 void setPort(int port)
          Set the port number of the listener.
 
Methods inherited from interface org.mortbay.util.LifeCycle
isStarted, start, stop
 

Field Detail

ATTRIBUTE

static final java.lang.String ATTRIBUTE
See Also:
Constant Field Values
Method Detail

setHttpServer

void setHttpServer(HttpServer server)
Set the HttpServer instance for this HttpListener. This method is called by the HttpServer.addListener method. It should not be called directly.

Parameters:
server - The HttpServer instance this HttpListener has been added to.

getHttpServer

HttpServer getHttpServer()
Get the HttpServer instance for this HttpListener.

Returns:
The HttpServer instance this HttpListener has been added to, or null if the listener is not added to any HttpServer.

setHost

void setHost(java.lang.String host)
             throws java.net.UnknownHostException
Set the host or IP of the interface used by this listener.

Parameters:
host - The hostname or IP address of the interface used by this listeners. If null or "0.0.0.0" then all available interfaces are used by this listener.
Throws:
java.net.UnknownHostException

getHost

java.lang.String getHost()
Get the host or IP of the interface used by this listener.

Returns:
The hostname or IP address of the interface used by this listeners. If null or "0.0.0.0" then all available interfaces are used by this listener.

setPort

void setPort(int port)
Set the port number of the listener.

Parameters:
port - The TCP/IP port number to be used by this listener.

getPort

int getPort()
Get the port number of the listener.

Returns:
The TCP/IP port number used by this listener.

getBufferSize

int getBufferSize()
Get the size of the buffers used by connections from this listener.

Returns:
The default buffer size in bytes.

getBufferReserve

int getBufferReserve()
Get the size of the header reserve area. Get the size of the header reserve area within the buffers used by connections from this listener. The header reserve is space reserved in the first buffer of a response to allow a HTTP header to be written in the same packet. The reserve should be large enough to avoid moving data to fit the header, but not too large as to waste memory.

Returns:
The default buffer reserve size in bytes.

getDefaultScheme

java.lang.String getDefaultScheme()
Get the default scheme for requests. If a request is received from a HttpConnection created by this listener, that does not include a scheme in it's request URL, then this method is used to determine the protocol scheme most likely used to connect to this listener.

Returns:
The protocol scheme name (eg "http" or "https").

customizeRequest

void customizeRequest(HttpConnection connection,
                      HttpRequest request)
Customize a request for a listener/connection combination. This method is called by HttpConnection after a request has been read from that connection and before processing that request. Implementations may use this callback to add additional listener and/or connection specific attributes to the request (eg SSL attributes).

Parameters:
connection - The connection the request was received on, which must be a HttpConnection created by this listener.
request - The request to customize.

persistConnection

void persistConnection(HttpConnection connection)
Prepare a connection for persistance. This method is called by the HttpConnection on a persistent connection after each request has been handled and before starting to read for the next connection. Implementations may use this callback to change the parameters or scheduling of the connection.

Parameters:
connection - The perstent connection, which must be a HttpConnection created by this listener.

isLowOnResources

boolean isLowOnResources()
Get the low on resources state of the listener. For most implementations, Threads are the resource reported on by this method.

Returns:
True if the listener is out of resources.

isOutOfResources

boolean isOutOfResources()
Get the out of resources state of the listener. For most implementations, Threads are the resource reported on by this method.

Returns:
True if the listener is out of resources.

isIntegral

boolean isIntegral(HttpConnection connection)
Get the integral status of a connection.

Parameters:
connection - The connection to test.
Returns:
True of the connection checks the integrity of the data. For most implementations this is true for https connections.

getIntegralScheme

java.lang.String getIntegralScheme()
Get the protocol scheme to use for integral redirections. If an INTEGRAL security constraint is not met for a request, the request is redirected to an integral port. This scheme return by this method is used for that redirection.

Returns:
The integral scheme. For most implementations this is "https"

getIntegralPort

int getIntegralPort()
Get the protocol port to use for integral redirections. If an INTEGRAL security constraint is not met for a request, the request is redirected to an integral port. This port return by this method is used for that redirection.

Returns:
The integral port. For most implementations this is 443 for https

isConfidential

boolean isConfidential(HttpConnection connection)
Get the confidential status of a connection.

Parameters:
connection - The connection to test.
Returns:
True of the connection checks the integrity of the data. For most implementations this is true for https connections.

getConfidentialScheme

java.lang.String getConfidentialScheme()
Get the protocol scheme to use for confidential redirections. If an CONFIDENTIAL security constraint is not met for a request, the request is redirected to an confidential port. This scheme return by this method is used for that redirection.

Returns:
The confidential scheme. For most implementations this is "https"

getConfidentialPort

int getConfidentialPort()
Get the protocol port to use for confidential redirections. If an CONFIDENTIAL security constraint is not met for a request, the request is redirected to an confidential port. This port return by this method is used for that redirection.

Returns:
The confidential port. For most implementations this is 443 for https

getHttpHandler

HttpHandler getHttpHandler()
Get an optional HttpHandler for the listener. If Set, then HttpConnection will pass requests from this listener to this handler with an empty context path, before passing the request to the HttpServer. This allows listener specific handling to be added or even a HttpContext (which is a HttpHandler) to be bound directly to HttpListener.



Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.