org.eclipse.jetty.server

## Class AbstractHttpConnection

- java.lang.Object
- - org.eclipse.jetty.io.AbstractConnection
  - - org.eclipse.jetty.server.AbstractHttpConnection

- All Implemented Interfaces:
    Connection
  Direct Known Subclasses:
    AsyncHttpConnection, BlockingHttpConnection, NestedConnection

      public abstract class AbstractHttpConnection
      extends AbstractConnection

  A HttpConnection represents the connection of a HTTP client to the server and is created by an instance of a `Connector`. It's prime function is to associate `Request` and `Response` instances with a `EndPoint`.

  A connection is also the prime mechanism used by jetty to recycle objects without pooling. The `Request`, `Response`, `HttpParser`, `HttpGenerator` and `HttpFields` instances are all recycled for the duraction of a connection. Where appropriate, allocated buffers are also kept associated with the connection via the parser and/or generator.

  The connection state is held by 3 separate state machines: The request state, the response state and the continuation state. All three state machines must be driven to completion for every request, and all three can complete in any order.

  The HttpConnection support protocol upgrade. If on completion of a request, the response code is 101 (switch protocols), then the org.eclipse.jetty.io.Connection request attribute is checked to see if there is a new Connection instance. If so, the new connection is returned from `handle()` and is used for future handling of the underlying connection. Note that for switching protocols that don't use 101 responses (eg CONNECT), the response should be sent and then the status code changed to 101 before returning from the handler. Implementors of new Connection types should be careful to extract any buffered data from (HttpParser)http.getParser()).getHeaderBuffer() and (HttpParser)http.getParser()).getBodyBuffer() to initialise their new connection.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `AbstractHttpConnection.Output`
    `class` | `AbstractHttpConnection.OutputWriter`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Connector` | `_connector`
    `protected Generator` | `_generator`
    `protected javax.servlet.ServletInputStream` | `_in`
    `protected AbstractHttpConnection.Output` | `_out`
    `protected Parser` | `_parser`
    `protected PrintWriter` | `_printWriter`
    `protected Request` | `_request`
    `protected HttpFields` | `_requestFields`
    `protected Response` | `_response`
    `protected HttpFields` | `_responseFields`
    `protected Server` | `_server`
    `protected HttpURI` | `_uri`
    `protected AbstractHttpConnection.OutputWriter` | `_writer`

    - ### Fields inherited from class org.eclipse.jetty.io.AbstractConnection

      `_endp`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server)`
    `protected` | `AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server, Parser parser, Generator generator, Request request)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `commitResponse(boolean last)`
    `void` | `completeResponse()`
    `protected void` | `content(Buffer buffer)`
    `void` | `earlyEOF()`
    `void` | `flushResponse()`
    `Object` | `getAssociatedObject()`
    `Connector` | `getConnector()`
    `static AbstractHttpConnection` | `getCurrentConnection()`
    `Generator` | `getGenerator()`
    `javax.servlet.ServletInputStream` | `getInputStream()` Get the inputStream from the connection.
    `int` | `getMaxIdleTime()`
    `javax.servlet.ServletOutputStream` | `getOutputStream()`
    `Parser` | `getParser()`
    `PrintWriter` | `getPrintWriter(String encoding)`
    `Request` | `getRequest()`
    `HttpFields` | `getRequestFields()`
    `int` | `getRequests()`
    `boolean` | `getResolveNames()`
    `Response` | `getResponse()`
    `HttpFields` | `getResponseFields()`
    `Server` | `getServer()`
    `abstract Connection` | `handle()` Handle the connection.
    `protected void` | `handleRequest()`
    `protected void` | `headerComplete()`
    `void` | `include()`
    `void` | `included()`
    `boolean` | `isConfidential(Request request)` Find out if the request supports CONFIDENTIAL security.
    `boolean` | `isEarlyEOF()`
    `boolean` | `isExpecting100Continues()`
    `boolean` | `isExpecting102Processing()`
    `boolean` | `isIdle()`
    `boolean` | `isIncluding()`
    `boolean` | `isIntegral(Request request)` Find out if the request supports INTEGRAL security.
    `boolean` | `isResponseCommitted()`
    `boolean` | `isSuspended()` The semantic of this method is to return true to indicate interest in further reads, or false otherwise, but it is misnamed and should be really called `isReadInterested()`.
    `void` | `messageComplete(long contentLength)`
    `protected HttpGenerator` | `newHttpGenerator(Buffers responseBuffers, EndPoint endPoint)`
    `protected HttpParser` | `newHttpParser(Buffers requestBuffers, EndPoint endpoint, HttpParser.EventHandler requestHandler)`
    `void` | `onClose()` Called after the connection is closed
    `protected void` | `parsedHeader(Buffer name, Buffer value)`
    `void` | `reset()`
    `void` | `setAssociatedObject(Object associatedObject)`
    `protected static void` | `setCurrentConnection(AbstractHttpConnection connection)`
    `protected void` | `startRequest(Buffer method, Buffer uri, Buffer version)`
    `String` | `toString()`

    - ### Methods inherited from class org.eclipse.jetty.io.AbstractConnection

      `getEndPoint, getTimeStamp, onIdleExpired`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### _connector

          protected final Connector _connector

    - #### _server

          protected final Server _server

    - #### _uri

          protected final HttpURI _uri

    - #### _parser

          protected final Parser _parser

    - #### _requestFields

          protected final HttpFields _requestFields

    - #### _request

          protected final Request _request

    - #### _in

          protected volatile javax.servlet.ServletInputStream _in

    - #### _generator

          protected final Generator _generator

    - #### _responseFields

          protected final HttpFields _responseFields

    - #### _response

          protected final Response _response

    - #### _out

          protected volatile AbstractHttpConnection.Output _out

    - #### _writer

          protected volatile AbstractHttpConnection.OutputWriter _writer

    - #### _printWriter

          protected volatile PrintWriter _printWriter

  - ### Constructor Detail

    - #### AbstractHttpConnection

          public AbstractHttpConnection(Connector connector,
                                EndPoint endpoint,
                                Server server)

    - #### AbstractHttpConnection

          protected AbstractHttpConnection(Connector connector,
                                EndPoint endpoint,
                                Server server,
                                Parser parser,
                                Generator generator,
                                Request request)

  - ### Method Detail

    - #### getCurrentConnection

          public static AbstractHttpConnection getCurrentConnection()

    - #### setCurrentConnection

          protected static void setCurrentConnection(AbstractHttpConnection connection)

    - #### newHttpParser

          protected HttpParser newHttpParser(Buffers requestBuffers,
                                 EndPoint endpoint,
                                 HttpParser.EventHandler requestHandler)

    - #### newHttpGenerator

          protected HttpGenerator newHttpGenerator(Buffers responseBuffers,
                                       EndPoint endPoint)

    - #### getParser

          public Parser getParser()

      Returns:
        the parser used by this connection

    - #### getRequests

          public int getRequests()

      Returns:
        the number of requests handled by this connection

    - #### getServer

          public Server getServer()

    - #### getAssociatedObject

          public Object getAssociatedObject()

      Returns:
        Returns the associatedObject.

    - #### setAssociatedObject

          public void setAssociatedObject(Object associatedObject)

      Parameters:
        `associatedObject` - The associatedObject to set.

    - #### getConnector

          public Connector getConnector()

      Returns:
        Returns the connector.

    - #### getRequestFields

          public HttpFields getRequestFields()

      Returns:
        Returns the requestFields.

    - #### getResponseFields

          public HttpFields getResponseFields()

      Returns:
        Returns the responseFields.

    - #### isConfidential

          public boolean isConfidential(Request request)

      Find out if the request supports CONFIDENTIAL security.
      Parameters:
        `request` - the incoming HTTP request
      Returns:
        the result of calling `Connector.isConfidential(Request)`, or false if there is no connector

    - #### isIntegral

          public boolean isIntegral(Request request)

      Find out if the request supports INTEGRAL security.
      Parameters:
        `request` - the incoming HTTP request
      Returns:
        the result of calling `Connector.isIntegral(Request)`, or false if there is no connector

    - #### getResolveNames

          public boolean getResolveNames()

      Returns:
        `false` (this method is not yet implemented)

    - #### getRequest

          public Request getRequest()

      Returns:
        Returns the request.

    - #### getResponse

          public Response getResponse()

      Returns:
        Returns the response.

    - #### getInputStream

          public javax.servlet.ServletInputStream getInputStream()
                                                          throws IOException

      Get the inputStream from the connection.

      If the associated response has the Expect header set to 100 Continue, then accessing the input stream indicates that the handler/servlet is ready for the request body and thus a 100 Continue response is sent.

      Returns:
        The input stream for this connection. The stream will be created if it does not already exist.
      Throws:
        `IOException` - if the input stream cannot be retrieved

    - #### getOutputStream

          public javax.servlet.ServletOutputStream getOutputStream()

      Returns:
        The output stream for this connection. The stream will be created if it does not already exist.

    - #### getPrintWriter

          public PrintWriter getPrintWriter(String encoding)

      Parameters:
        `encoding` - the PrintWriter encoding
      Returns:
        A `PrintWriter` wrapping the `output stream`. The writer is created if it does not already exist.

    - #### isResponseCommitted

          public boolean isResponseCommitted()

    - #### isEarlyEOF

          public boolean isEarlyEOF()

    - #### reset

          public void reset()

    - #### handleRequest

          protected void handleRequest()
                                throws IOException

      Throws:
        `IOException`

    - #### handle

          public abstract Connection handle()
                                     throws IOException

      Description copied from interface: `Connection`
      Handle the connection.
      Returns:
        The Connection to use for the next handling of the connection. This allows protocol upgrades and support for CONNECT.
      Throws:
        `IOException` - if the handling of I/O operations fail

    - #### commitResponse

          public void commitResponse(boolean last)
                              throws IOException

      Throws:
        `IOException`

    - #### completeResponse

          public void completeResponse()
                                throws IOException

      Throws:
        `IOException`

    - #### flushResponse

          public void flushResponse()
                             throws IOException

      Throws:
        `IOException`

    - #### getGenerator

          public Generator getGenerator()

    - #### isIncluding

          public boolean isIncluding()

    - #### include

          public void include()

    - #### included

          public void included()

    - #### isIdle

          public boolean isIdle()

      Returns:
        whether this connection is idle, that is not parsing and not generating
      See Also:
        `Connection.onIdleExpired(long)`

    - #### isSuspended

          public boolean isSuspended()

      Description copied from interface: `Connection`

      The semantic of this method is to return true to indicate interest in further reads, or false otherwise, but it is misnamed and should be really called `isReadInterested()`.

      Returns:
        true to indicate interest in further reads, false otherwise
      See Also:
        `Connection.isSuspended()`

    - #### onClose

          public void onClose()

      Description copied from interface: `Connection`
      Called after the connection is closed

    - #### isExpecting100Continues

          public boolean isExpecting100Continues()

    - #### isExpecting102Processing

          public boolean isExpecting102Processing()

    - #### getMaxIdleTime

          public int getMaxIdleTime()

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `AbstractConnection`

    - #### startRequest

          protected void startRequest(Buffer method,
                          Buffer uri,
                          Buffer version)
                               throws IOException

      Throws:
        `IOException`

    - #### parsedHeader

          protected void parsedHeader(Buffer name,
                          Buffer value)
                               throws IOException

      Throws:
        `IOException`

    - #### headerComplete

          protected void headerComplete()
                                 throws IOException

      Throws:
        `IOException`

    - #### content

          protected void content(Buffer buffer)
                          throws IOException

      Throws:
        `IOException`

    - #### messageComplete

          public void messageComplete(long contentLength)
                               throws IOException

      Throws:
        `IOException`

    - #### earlyEOF

          public void earlyEOF()

Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.