Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.mortbay.http
Class HttpConnection  view HttpConnection download HttpConnection.java

java.lang.Object
  extended byorg.mortbay.http.HttpConnection
All Implemented Interfaces:
org.mortbay.util.OutputObserver

public class HttpConnection
extends java.lang.Object
implements org.mortbay.util.OutputObserver

A HTTP Connection. This class provides the generic HTTP handling for a connection to a HTTP server. An instance of HttpConnection is normally created by a HttpListener and then given control in order to run the protocol handling before and after passing a request to the HttpServer of the HttpListener. This class is not synchronized as it should only ever be known to a single thread.

Version:
$Id: HttpConnection.java,v 1.67 2003/11/22 16:06:01 gregwilkins Exp $

Field Summary
private static boolean __2068_Continues
          Support for FRC2068 Continues.
private static java.lang.ThreadLocal __threadConnection
           
private  boolean _close
           
private  java.lang.Object _connection
           
private  int _dotVersion
           
private  boolean _firstWrite
           
private  java.lang.Thread _handlingThread
           
private  HttpServer _httpServer
           
private  HttpInputStream _inputStream
           
protected  boolean _keepAlive
           
private  HttpListener _listener
           
private  java.lang.Object _object
           
private  long _openTime
           
private  HttpOutputStream _outputStream
           
protected  boolean _persistent
           
private  java.lang.String _remoteAddr
           
private  java.lang.String _remoteHost
           
private  java.net.InetAddress _remoteInetAddress
           
private  long _reqTime
           
protected  HttpRequest _request
           
private  int _requests
           
private  boolean _resolveRemoteHost
           
protected  HttpResponse _response
           
private  boolean _statsOn
           
private  boolean _throttled
           
private  long _tmpTime
           
private  HttpTunnel _tunnel
           
private static org.apache.commons.logging.Log log
           
 
Fields inherited from interface org.mortbay.util.OutputObserver
__CLOSED, __CLOSING, __COMMITING, __FIRST_WRITE, __RESET_BUFFER
 
Constructor Summary
HttpConnection(HttpListener listener, java.net.InetAddress remoteAddr, java.io.InputStream in, java.io.OutputStream out, java.lang.Object connection)
          Constructor.
 
Method Summary
protected  void associateThread()
           
 void close()
          Close the connection.
protected  void commit()
           
protected  void destroy()
          Destroy the connection.
protected  void disassociateThread()
           
private  void exception(java.lang.Throwable e)
           
protected  void firstWrite()
          Setup the reponse output stream.
 void forceClose()
          Force the connection to not be persistent.
 java.lang.Object getConnection()
          Get the underlying connection object.
 java.lang.String getDefaultScheme()
          Get the listeners Default scheme.
(package private) static HttpConnection getHttpConnection()
          Get the ThreadLocal HttpConnection.
 HttpServer getHttpServer()
          Get the listeners HttpServer .
 HttpTunnel getHttpTunnel()
           
 HttpInputStream getInputStream()
          Get the connections InputStream.
 HttpListener getListener()
          Get the connections listener.
 java.lang.Object getObject()
          Get associated object.
 HttpOutputStream getOutputStream()
          Get the connections OutputStream.
 java.lang.String getRemoteAddr()
          Get the Remote address.
 java.lang.String getRemoteHost()
          Get the Remote address.
 java.net.InetAddress getRemoteInetAddress()
          Get the Remote address.
 int getRemotePort()
          Get the remote Port .
 HttpRequest getRequest()
          Get the request.
 HttpResponse getResponse()
          Get the response.
 java.lang.String getServerAddr()
          Get the listeners HttpServer.
 java.lang.String getServerName()
          Get the listeners HttpServer.
 int getServerPort()
          Get the listeners Port .
 void handle()
          Handle the connection.
 boolean handleNext()
          Handle next request off the connection.
 boolean isThrottled()
           
 void outputNotify(java.io.OutputStream out, int action, java.lang.Object ignoredData)
          Output Notifications.
protected  void readRequest()
           
protected  void recycle()
          Recycle the connection.
protected  HttpContext service(HttpRequest request, HttpResponse response)
          Service a Request.
 void setHttpTunnel(HttpTunnel tunnel)
          Set a HttpTunnel for the connection.
 void setObject(java.lang.Object o)
          Set associated object.
 void setThrottled(boolean throttled)
           
protected  void statsRequestEnd()
           
protected  void statsRequestStart()
           
private  void verifyHTTP_1_0()
           
private  void verifyHTTP_1_1()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log

__threadConnection

private static java.lang.ThreadLocal __threadConnection

__2068_Continues

private static boolean __2068_Continues
Support for FRC2068 Continues. If true, then 100 Continues will be sent when expected or for POST requests. If false, 100 Continues will only be sent if expected. Can be configured with the org.mortbay.http.HttpConnection.2068Continue system property.


_request

protected HttpRequest _request

_response

protected HttpResponse _response

_persistent

protected boolean _persistent

_keepAlive

protected boolean _keepAlive

_listener

private HttpListener _listener

_inputStream

private HttpInputStream _inputStream

_outputStream

private HttpOutputStream _outputStream

_close

private boolean _close

_dotVersion

private int _dotVersion

_firstWrite

private boolean _firstWrite

_handlingThread

private java.lang.Thread _handlingThread

_remoteInetAddress

private java.net.InetAddress _remoteInetAddress

_remoteAddr

private java.lang.String _remoteAddr

_remoteHost

private java.lang.String _remoteHost

_httpServer

private HttpServer _httpServer

_connection

private java.lang.Object _connection

_throttled

private boolean _throttled

_statsOn

private boolean _statsOn

_tmpTime

private long _tmpTime

_openTime

private long _openTime

_reqTime

private long _reqTime

_requests

private int _requests

_object

private java.lang.Object _object

_tunnel

private HttpTunnel _tunnel

_resolveRemoteHost

private boolean _resolveRemoteHost
Constructor Detail

HttpConnection

public HttpConnection(HttpListener listener,
                      java.net.InetAddress remoteAddr,
                      java.io.InputStream in,
                      java.io.OutputStream out,
                      java.lang.Object connection)
Constructor.

Method Detail

getHttpConnection

static HttpConnection getHttpConnection()
Get the ThreadLocal HttpConnection. The ThreadLocal HttpConnection is set by the handle() method.


getRemoteInetAddress

public java.net.InetAddress getRemoteInetAddress()
Get the Remote address.


getRemoteAddr

public java.lang.String getRemoteAddr()
Get the Remote address.


getRemoteHost

public java.lang.String getRemoteHost()
Get the Remote address.


getInputStream

public HttpInputStream getInputStream()
Get the connections InputStream.


getOutputStream

public HttpOutputStream getOutputStream()
Get the connections OutputStream.


getConnection

public java.lang.Object getConnection()
Get the underlying connection object. This opaque object, most likely a socket. This is not used by HttpConnection other than to make it available via getConnection().


getRequest

public HttpRequest getRequest()
Get the request.


getResponse

public HttpResponse getResponse()
Get the response.


forceClose

public void forceClose()
Force the connection to not be persistent.


close

public void close()
           throws java.io.IOException
Close the connection. This method calls close on the input and output streams and interrupts any thread in the handle method. may be specialized to close sockets etc.


getListener

public HttpListener getListener()
Get the connections listener.


getHttpServer

public HttpServer getHttpServer()
Get the listeners HttpServer . Conveniance method equivalent to getListener().getHttpServer().


getDefaultScheme

public java.lang.String getDefaultScheme()
Get the listeners Default scheme. Conveniance method equivalent to getListener().getDefaultProtocol().


getServerName

public java.lang.String getServerName()
Get the listeners HttpServer. But if the name is 0.0.0.0, then the real interface address is used.


getServerAddr

public java.lang.String getServerAddr()
Get the listeners HttpServer.


getServerPort

public int getServerPort()
Get the listeners Port . Conveniance method equivalent to getListener().getPort().


getRemotePort

public int getRemotePort()
Get the remote Port .


isThrottled

public boolean isThrottled()

setThrottled

public void setThrottled(boolean throttled)

getObject

public java.lang.Object getObject()
Get associated object. Used by a particular HttpListener implementation to associate private datastructures with the connection.


setObject

public void setObject(java.lang.Object o)
Set associated object. Used by a particular HttpListener implementation to associate private datastructures with the connection.


getHttpTunnel

public HttpTunnel getHttpTunnel()

setHttpTunnel

public void setHttpTunnel(HttpTunnel tunnel)
Set a HttpTunnel for the connection. A HTTP tunnel is used if the connection is to be taken over for non-HTTP communications. An example of this is the CONNECT method in proxy handling. If a HttpTunnel is set on a connection, then it's handle method is called bu the next call to handleNext().


verifyHTTP_1_0

private void verifyHTTP_1_0()

verifyHTTP_1_1

private void verifyHTTP_1_1()
                     throws HttpException,
                            java.io.IOException

outputNotify

public void outputNotify(java.io.OutputStream out,
                         int action,
                         java.lang.Object ignoredData)
                  throws java.io.IOException
Output Notifications. Trigger header and/or filters from output stream observations. Also finalizes method of indicating response content length. Called as a result of the connection subscribing for notifications to the HttpOutputStream.

Specified by:
outputNotify in interface org.mortbay.util.OutputObserver

firstWrite

protected void firstWrite()
                   throws java.io.IOException
Setup the reponse output stream. Use the current state of the request and response, to set tranfer parameters such as chunking and content length.


commit

protected void commit()
               throws java.io.IOException

exception

private void exception(java.lang.Throwable e)

service

protected HttpContext service(HttpRequest request,
                              HttpResponse response)
                       throws HttpException,
                              java.io.IOException
Service a Request. This implementation passes the request and response to the service method of the HttpServer for this connections listener. If no HttpServer has been associated, the 503 is returned. This method may be specialized to implement other ways of servicing a request.


handle

public final void handle()
Handle the connection. Once the connection has been created, this method is called to handle one or more requests that may be received on the connection. The method only returns once all requests have been handled, an error has been returned to the requestor or the connection has been closed. The handleNext() is called in a loop until it returns false.


associateThread

protected void associateThread()

disassociateThread

protected void disassociateThread()

readRequest

protected void readRequest()
                    throws java.io.IOException

handleNext

public boolean handleNext()
Handle next request off the connection. The service(request,response) method is called by handle to service each request received on the connection. If the thread is a PoolThread, the thread is set as inactive when waiting for a request.

If a HttpTunnel has been set on this connection, it's handle method is called and when that completes, false is return from this method.

The Connection is set as a ThreadLocal of the calling thread and is available via the getHttpConnection() method.


statsRequestStart

protected void statsRequestStart()

statsRequestEnd

protected void statsRequestEnd()

recycle

protected void recycle()
Recycle the connection. called by handle when handleNext returns true.


destroy

protected void destroy()
Destroy the connection. called by handle when handleNext returns false.