Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.eclipse.jetty.server
Class HttpConnection

    java.lang.Object
      org.eclipse.jetty.server.HttpConnection

All Implemented Interfaces:
  Connection

Direct Known Subclasses:
  Ajp13Connection

    public class HttpConnection

extends java.lang.Object
implements Connection

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
`class` | `HttpConnection.Output`
`class` | `HttpConnection.OutputWriter`

Field Summary
`protected Connector` | `_connector`
`protected EndPoint` | `_endp`
`protected Generator` | `_generator`
`protected ServletInputStream` | `_in`
`protected HttpConnection.Output` | `_out`
`protected Parser` | `_parser`
`protected java.io.PrintWriter` | `_printWriter`
`protected Request` | `_request`
`protected HttpFields` | `_requestFields`
`protected Response` | `_response`
`protected HttpFields` | `_responseFields`
`protected Server` | `_server`
`protected HttpURI` | `_uri`
`protected HttpConnection.OutputWriter` | `_writer`

Constructor Summary
`` | `HttpConnection(Connector connector, EndPoint endpoint, Server server)` Constructor
`protected` | `HttpConnection(Connector connector, EndPoint endpoint, Server server, Parser parser, Generator generator, Request request)`

Method Summary
`void` | `cancelTimeout(Timeout.Task task)`
`void` | `closed()`
`void` | `commitResponse(boolean last)`
`void` | `completeResponse()`
`void` | `flushResponse()`
`java.lang.Object` | `getAssociatedObject()`
`Connector` | `getConnector()`
`static HttpConnection` | `getCurrentConnection()`
`EndPoint` | `getEndPoint()`
`Generator` | `getGenerator()`
`ServletInputStream` | `getInputStream()` Get the inputStream from the connection.
`ServletOutputStream` | `getOutputStream()`
`Parser` | `getParser()`
`java.io.PrintWriter` | `getPrintWriter(java.lang.String encoding)`
`Request` | `getRequest()`
`HttpFields` | `getRequestFields()`
`int` | `getRequests()`
`boolean` | `getResolveNames()`
`Response` | `getResponse()`
`HttpFields` | `getResponseFields()`
`Server` | `getServer()`
`long` | `getTimeStamp()`
`Connection` | `handle()` Handle the connection.
`protected void` | `handleRequest()`
`void` | `include()`
`void` | `included()`
`boolean` | `isConfidential(Request request)`
`boolean` | `isExpecting100Continues()`
`boolean` | `isExpecting102Processing()`
`boolean` | `isIdle()`
`boolean` | `isIncluding()`
`boolean` | `isIntegral(Request request)` Find out if the request is INTEGRAL security.
`boolean` | `isResponseCommitted()`
`boolean` | `isSuspended()`
`void` | `reset(boolean returnBuffers)`
`void` | `scheduleTimeout(Timeout.Task task, long timeoutMs)`
`void` | `setAssociatedObject(java.lang.Object associatedObject)`
`protected static void` | `setCurrentConnection(HttpConnection connection)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### _connector

    protected final Connector _connector

### _endp

    protected final EndPoint _endp

### _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 ServletInputStream _in

### _generator

    protected final Generator _generator

### _responseFields

    protected final HttpFields _responseFields

### _response

    protected final Response _response

### _out

    protected HttpConnection.Output _out

### _writer

    protected HttpConnection.OutputWriter _writer

### _printWriter

    protected java.io.PrintWriter _printWriter

Constructor Detail

### HttpConnection

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

  Constructor

### HttpConnection

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

Method Detail

### getCurrentConnection

    public static HttpConnection getCurrentConnection()

### setCurrentConnection

    protected static void setCurrentConnection(HttpConnection connection)

### 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()

### getTimeStamp

    public long getTimeStamp()

  Specified by:
    `getTimeStamp` in interface `Connection`
  Returns:
    The time this connection was established.

### getAssociatedObject

    public java.lang.Object getAssociatedObject()

  Returns:
    Returns the associatedObject.

### setAssociatedObject

    public void setAssociatedObject(java.lang.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)

  Returns:
    The result of calling `getConnector()`.`isCondidential`(request), or false if there is no connector.

### isIntegral

    public boolean isIntegral(Request request)

  Find out if the request is INTEGRAL security.

  Parameters:
    `request` -
  Returns:
    `true` if there is a `connector` and it considers `request` to be `integral`

### getEndPoint

    public EndPoint getEndPoint()

  Returns:
    The `EndPoint` for this connection.

### 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 ServletInputStream getInputStream()
                                      throws java.io.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:
    `java.io.IOException`

### getOutputStream

    public ServletOutputStream getOutputStream()

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

### getPrintWriter

    public java.io.PrintWriter getPrintWriter(java.lang.String encoding)

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

### isResponseCommitted

    public boolean isResponseCommitted()

### handle

    public Connection handle()
                      throws java.io.IOException

  Description copied from interface: `Connection`
  Handle the connection.

  Specified by:
    `handle` in interface `Connection`
  Returns:
    The Connection to use for the next handling of the connection. This allows protocol upgrades and support for CONNECT.
  Throws:
    `java.io.IOException`

### scheduleTimeout

    public void scheduleTimeout(Timeout.Task task,
                                long timeoutMs)

### cancelTimeout

    public void cancelTimeout(Timeout.Task task)

### reset

    public void reset(boolean returnBuffers)

### handleRequest

    protected void handleRequest()
                          throws java.io.IOException

  Throws:
    `java.io.IOException`

### commitResponse

    public void commitResponse(boolean last)
                        throws java.io.IOException

  Throws:
    `java.io.IOException`

### completeResponse

    public void completeResponse()
                          throws java.io.IOException

  Throws:
    `java.io.IOException`

### flushResponse

    public void flushResponse()
                       throws java.io.IOException

  Throws:
    `java.io.IOException`

### getGenerator

    public Generator getGenerator()

### isIncluding

    public boolean isIncluding()

### include

    public void include()

### included

    public void included()

### isIdle

    public boolean isIdle()

  Specified by:
    `isIdle` in interface `Connection`

### isSuspended

    public boolean isSuspended()

  Specified by:
    `isSuspended` in interface `Connection`
  See Also:
    `Connection.isSuspended()`

### closed

    public void closed()

  Specified by:
    `closed` in interface `Connection`

### isExpecting100Continues

    public boolean isExpecting100Continues()

### isExpecting102Processing

    public boolean isExpecting102Processing()

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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