Top Description Inners Fields Constructors Methods
org.mortbay.jetty

public Class HttpConnection

extends Object
implements Connection
Class Inheritance
All Implemented Interfaces
org.mortbay.io.Connection
Imports
java.io.IOException, .InputStream, .PrintWriter, javax.servlet.ServletInputStream, .ServletOutputStream, javax.servlet.http.HttpServletResponse, org.mortbay.io.Buffer, .Connection, .EndPoint, .BufferCache.CachedBuffer, org.mortbay.io.nio.SelectChannelEndPoint, org.mortbay.log.Log, org.mortbay.resource.Resource, org.mortbay.thread.Timeout, org.mortbay.util.StringUtil, .URIUtil

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.

Author
gregw

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
public class
private class

Field Summary

Modifier and TypeField and Description
private static ThreadLocal<HttpConnection>
private Object
protected final Connector
private transient boolean
private boolean
protected final EndPoint
private transient int
protected final Generator
private boolean
private transient boolean
private transient boolean
protected ServletInputStream
pack-priv int
protected HttpConnection.Output
protected final Parser
protected PrintWriter
protected final Request
protected final HttpFields
private int
protected final Response
protected final HttpFields
protected final Server
private long
protected final HttpURI
private transient int
protected HttpConnection.OutputWriter
private static int

Constructor Summary

AccessConstructor and Description
public
HttpConnection(Connector connector, EndPoint endpoint, Server server)

Constructor

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

Method Summary

Modifier and TypeMethod and Description
public void
public void
commitResponse(boolean last)

public void
public void
public void
public Object

Returns:

Returns the associatedObject.
getAssociatedObject
()

public Connector

Returns:

Returns the connector.
getConnector
()

public static HttpConnection
public EndPoint

Returns:

The EndPoint for this connection.
getEndPoint
()

public Generator
public ServletInputStream

Returns:

The input stream for this connection. The stream will be created if it does not already exist.
getInputStream
()

public ServletOutputStream

Returns:

The output stream for this connection. The stream will be created if it does not already exist.
getOutputStream
()

public Parser

Returns:

the parser used by this connection
getParser
()

public PrintWriter

Returns:

A PrintWriter wrapping the output stream. The writer is created if it does not already exist.
getPrintWriter
(String encoding)

public Request

Returns:

Returns the request.
getRequest
()

public HttpFields

Returns:

Returns the requestFields.
getRequestFields
()

public int

Returns:

the number of requests handled by this connection
getRequests
()

public boolean

Returns:

false (this method is not yet implemented)
getResolveNames
()

public Response

Returns:

Returns the response.
getResponse
()

public HttpFields

Returns:

Returns the responseFields.
getResponseFields
()

public long

Returns:

The time this connection was established.
getTimeStamp
()

public void
protected void
public void
public void
public boolean

Returns:

The result of calling getConnector.isCondidential(request), or false if there is no connector.
isConfidential
(Request request)

public boolean
public boolean
public boolean

Returns:

true if there is a connector and it considers request to be integral
isIntegral
(Request request)

Find out if the request is INTEGRAL security.

public boolean
public void
reset(boolean returnBuffers)

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

public void
setAssociatedObject(Object
The associatedObject to set.
associatedObject
)

protected static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

__currentConnectionback to summary
private static ThreadLocal<HttpConnection> __currentConnection
_associatedObjectback to summary
private Object _associatedObject
_connectorback to summary
protected final Connector _connector
_delayedHandlingback to summary
private transient boolean _delayedHandling
_destroyback to summary
private boolean _destroy
_endpback to summary
protected final EndPoint _endp
_expectback to summary
private transient int _expect
_generatorback to summary
protected final Generator _generator
_handlingback to summary
private boolean _handling
_headback to summary
private transient boolean _head
_hostback to summary
private transient boolean _host
_inback to summary
protected ServletInputStream _in
_includeback to summary
pack-priv int _include
_outback to summary
protected HttpConnection.Output _out
_parserback to summary
protected final Parser _parser
_printWriterback to summary
protected PrintWriter _printWriter
_requestback to summary
protected final Request _request
_requestFieldsback to summary
protected final HttpFields _requestFields
_requestsback to summary
private int _requests
_responseback to summary
protected final Response _response
_responseFieldsback to summary
protected final HttpFields _responseFields
_serverback to summary
protected final Server _server
_timeStampback to summary
private long _timeStamp
_uriback to summary
protected final HttpURI _uri
_versionback to summary
private transient int _version
_writerback to summary
protected HttpConnection.OutputWriter _writer
UNKNOWNback to summary
private static int UNKNOWN

Constructor Detail

HttpConnectionback to summary
public HttpConnection(Connector connector, EndPoint endpoint, Server server)

Constructor

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

Method Detail

cancelTimeoutback to summary
public void cancelTimeout(Timeout.Task task)
commitResponseback to summary
public void commitResponse(boolean last) throws IOException
completeResponseback to summary
public void completeResponse() throws IOException
destroyback to summary
public void destroy()
flushResponseback to summary
public void flushResponse() throws IOException
getAssociatedObjectback to summary
public Object getAssociatedObject()
Returns:Object

Returns the associatedObject.

getConnectorback to summary
public Connector getConnector()
Returns:Connector

Returns the connector.

getCurrentConnectionback to summary
public static HttpConnection getCurrentConnection()
getEndPointback to summary
public EndPoint getEndPoint()
Returns:EndPoint

The EndPoint for this connection.

getGeneratorback to summary
public Generator getGenerator()
getInputStreamback to summary
public ServletInputStream getInputStream() throws IOException
Returns:ServletInputStream

The input stream for this connection. The stream will be created if it does not already exist.

getOutputStreamback to summary
public ServletOutputStream getOutputStream()
Returns:ServletOutputStream

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

getParserback to summary
public Parser getParser()
Returns:Parser

the parser used by this connection

getPrintWriterback to summary
public PrintWriter getPrintWriter(String encoding)
Returns:PrintWriter

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

getRequestback to summary
public Request getRequest()
Returns:Request

Returns the request.

getRequestFieldsback to summary
public HttpFields getRequestFields()
Returns:HttpFields

Returns the requestFields.

getRequestsback to summary
public int getRequests()
Returns:int

the number of requests handled by this connection

getResolveNamesback to summary
public boolean getResolveNames()
Returns:boolean

false (this method is not yet implemented)

getResponseback to summary
public Response getResponse()
Returns:Response

Returns the response.

getResponseFieldsback to summary
public HttpFields getResponseFields()
Returns:HttpFields

Returns the responseFields.

getTimeStampback to summary
public long getTimeStamp()
Returns:long

The time this connection was established.

handleback to summary
public void handle() throws IOException

Implements org.mortbay.io.Connection.handle.

handleRequestback to summary
protected void handleRequest() throws IOException
includeback to summary
public void include()
includedback to summary
public void included()
isConfidentialback to summary
public boolean isConfidential(Request request)
Returns:boolean

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

isIdleback to summary
public boolean isIdle()

Implements org.mortbay.io.Connection.isIdle.

isIncludingback to summary
public boolean isIncluding()
isIntegralback to summary
public boolean isIntegral(Request request)

Find out if the request is INTEGRAL security.

Returns:boolean

true if there is a connector and it considers request to be integral

isResponseCommittedback to summary
public boolean isResponseCommitted()
resetback to summary
public void reset(boolean returnBuffers)
scheduleTimeoutback to summary
public void scheduleTimeout(Timeout.Task task, long timeoutMs)
setAssociatedObjectback to summary
public void setAssociatedObject(Object associatedObject)
Parameters
associatedObject:Object

The associatedObject to set.

setCurrentConnectionback to summary
protected static void setCurrentConnection(HttpConnection connection)
org.mortbay.jetty back to summary

public Class HttpConnection.Output

extends Output
Class Inheritance

Field Summary

Inherited from org.mortbay.jetty.AbstractGenerator.Output:
_buf_bytes_characterEncoding_chars_closed_converter_generator_maxIdleTime

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides org.mortbay.jetty.AbstractGenerator.Output.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
public void
flush()

Overrides org.mortbay.jetty.AbstractGenerator.Output.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.
public void
print(String
the String to send to the client
s
)

Overrides org.mortbay.jetty.AbstractGenerator.Output.print.

Writes a String to the client, without a carriage return-line feed (CRLF) character at the end.
public void
public void
sendResponse(Buffer response)

Inherited from org.mortbay.jetty.AbstractGenerator.Output:
blockForOutputreopenwritewritewrite

Constructor Detail

Outputback to summary
pack-priv Output()

Method Detail

closeback to summary
public void close() throws IOException

Overrides org.mortbay.jetty.AbstractGenerator.Output.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Exceptions
IOException:
if an I/O error occurs.
flushback to summary
public void flush() throws IOException

Overrides org.mortbay.jetty.AbstractGenerator.Output.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Exceptions
IOException:
if an I/O error occurs.
printback to summary
public void print(String s) throws IOException

Overrides org.mortbay.jetty.AbstractGenerator.Output.print.

Doc from javax.servlet.ServletOutputStream.print.

Writes a String to the client, without a carriage return-line feed (CRLF) character at the end.

Parameters
s:String

the String to send to the client

Exceptions
IOException:
if an input or output exception occurred
sendContentback to summary
public void sendContent(Object content) throws IOException
sendResponseback to summary
public void sendResponse(Buffer response) throws IOException
org.mortbay.jetty back to summary

public Class HttpConnection.OutputWriter

extends OutputWriter
Class Inheritance

Field Summary

Inherited from org.mortbay.jetty.AbstractGenerator.OutputWriter:
_generator_out_surrogate_writeMode

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from org.mortbay.jetty.AbstractGenerator.OutputWriter:
closeflushsetCharacterEncodingwritewrite

Constructor Detail

OutputWriterback to summary
pack-priv OutputWriter()
org.mortbay.jetty back to summary

private Class HttpConnection.RequestHandler

extends EventHandler
Class Inheritance

Field Summary

Modifier and TypeField and Description
private String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
parsedHeader(Buffer name, Buffer value)

Overrides org.mortbay.jetty.HttpParser.EventHandler.parsedHeader.

This is the method called by parser when a HTTP Header name and value is found
public void
startRequest(Buffer method, Buffer uri, Buffer version)

Implements abstract org.mortbay.jetty.HttpParser.EventHandler.startRequest.

This is the method called by parser when the HTTP request line is parsed
public void
startResponse(Buffer version, int status, Buffer reason)

Implements abstract org.mortbay.jetty.HttpParser.EventHandler.startResponse.

This is the method called by parser when the HTTP request line is parsed

Field Detail

_charsetback to summary
private String _charset

Constructor Detail

RequestHandlerback to summary
private RequestHandler()

Method Detail

contentback to summary
public void content(Buffer ref) throws IOException

Implements abstract org.mortbay.jetty.HttpParser.EventHandler.content.

headerCompleteback to summary
public void headerComplete() throws IOException

Overrides org.mortbay.jetty.HttpParser.EventHandler.headerComplete.

messageCompleteback to summary
public void messageComplete(long contextLength) throws IOException

Overrides org.mortbay.jetty.HttpParser.EventHandler.messageComplete.

parsedHeaderback to summary
public void parsedHeader(Buffer name, Buffer value)

Overrides org.mortbay.jetty.HttpParser.EventHandler.parsedHeader.

Doc from org.mortbay.jetty.HttpParser.EventHandler.parsedHeader.

This is the method called by parser when a HTTP Header name and value is found

startRequestback to summary
public void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException

Implements abstract org.mortbay.jetty.HttpParser.EventHandler.startRequest.

Doc from org.mortbay.jetty.HttpParser.EventHandler.startRequest.

This is the method called by parser when the HTTP request line is parsed

startResponseback to summary
public void startResponse(Buffer version, int status, Buffer reason)

Implements abstract org.mortbay.jetty.HttpParser.EventHandler.startResponse.

Doc from org.mortbay.jetty.HttpParser.EventHandler.startResponse.

This is the method called by parser when the HTTP request line is parsed