org.mortbay.http

Interface HttpListener

public interface HttpListener extends LifeCycle, 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 StringATTRIBUTE
Method Summary
voidcustomizeRequest(HttpConnection connection, HttpRequest request)
Customize a request for a listener/connection combination.
intgetBufferReserve()
Get the size of the header reserve area.
intgetBufferSize()
Get the size of the buffers used by connections from this listener.
intgetConfidentialPort()
Get the protocol port to use for confidential redirections.
StringgetConfidentialScheme()
Get the protocol scheme to use for confidential redirections.
StringgetDefaultScheme()
Get the default scheme for requests.
StringgetHost()
Get the host or IP of the interface used by this listener.
HttpHandlergetHttpHandler()
Get an optional HttpHandler for the listener.
HttpServergetHttpServer()
Get the HttpServer instance for this HttpListener.
intgetIntegralPort()
Get the protocol port to use for integral redirections.
StringgetIntegralScheme()
Get the protocol scheme to use for integral redirections.
intgetPort()
Get the port number of the listener.
booleanisConfidential(HttpConnection connection)
Get the confidential status of a connection.
booleanisIntegral(HttpConnection connection)
Get the integral status of a connection.
booleanisLowOnResources()
Get the low on resources state of the listener.
booleanisOutOfResources()
Get the out of resources state of the listener.
voidpersistConnection(HttpConnection connection)
Prepare a connection for persistance.
voidsetHost(String host)
Set the host or IP of the interface used by this listener.
voidsetHttpServer(HttpServer server)
Set the HttpServer instance for this HttpListener.
voidsetPort(int port)
Set the port number of the listener.

Field Detail

ATTRIBUTE

public static final String ATTRIBUTE

Method Detail

customizeRequest

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

getBufferReserve

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

getBufferSize

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

Returns: The default buffer size in bytes.

getConfidentialPort

public 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

getConfidentialScheme

public 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"

getDefaultScheme

public 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").

getHost

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

getHttpHandler

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

getHttpServer

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

getIntegralPort

public 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

getIntegralScheme

public 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"

getPort

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

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

isConfidential

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

isIntegral

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

isLowOnResources

public 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

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

persistConnection

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

setHost

public void setHost(String host)
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.

setHttpServer

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

setPort

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

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

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