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

Quick Search    Search Deep

org.apache.http.impl
Class DefaultHttpClientConnection  view DefaultHttpClientConnection download DefaultHttpClientConnection.java

java.lang.Object
  extended byorg.apache.http.impl.AbstractHttpConnection
      extended byorg.apache.http.impl.DefaultHttpClientConnection
All Implemented Interfaces:
org.apache.http.HttpClientConnection, org.apache.http.HttpConnection
Direct Known Subclasses:
DefaultHttpProxyConnection

public class DefaultHttpClientConnection
extends AbstractHttpConnection
implements org.apache.http.HttpClientConnection

Default implementation of a client-side HTTP connection.

Since:
4.0
Version:
$Revision: 411100 $

Field Summary
private  org.apache.http.io.CharArrayBuffer buffer
           
protected  org.apache.http.io.HttpDataReceiver datareceiver
           
protected  org.apache.http.io.HttpDataTransmitter datatransmitter
           
private  org.apache.http.entity.EntityDeserializer entitydeserializer
           
private  org.apache.http.entity.EntitySerializer entityserializer
           
private  java.net.InetAddress localAddress
           
private  int maxHeaderCount
           
protected  boolean open
           
private  org.apache.http.HttpResponseFactory responsefactory
           
protected  java.net.Socket socket
           
private  org.apache.http.HttpHost targethost
           
 
Constructor Summary
DefaultHttpClientConnection()
           
DefaultHttpClientConnection(org.apache.http.HttpHost targethost)
           
DefaultHttpClientConnection(org.apache.http.HttpHost targethost, java.net.InetAddress localAddress)
           
 
Method Summary
protected  void assertNotOpen()
           
protected  void assertOpen()
           
protected  void bind(java.net.Socket socket, org.apache.http.params.HttpParams params)
           
 void close()
          This method will gracefully close the connection.
 void flush()
          Writes out all pending buffered data over the open connection.
 java.net.InetAddress getLocalAddress()
          The local address the connection is or will be bound to as set by
 org.apache.http.HttpHost getTargetHost()
          Returns the current target host as set by @link #setTargetHost(HttpHost).
 boolean isOpen()
          Checks if this connection is open.
 boolean isResponseAvailable(int timeout)
          Checks if response data is available from the connection.
 boolean isStale()
          Network connections may get closed during some time of inactivity for several reasons.
 void open(org.apache.http.params.HttpParams params)
          Opens the connection.
protected  void readResponseHeaders(org.apache.http.HttpResponse response)
           
protected  org.apache.http.HttpResponse readResponseStatusLine(org.apache.http.params.HttpParams params)
           
 void receiveResponseEntity(org.apache.http.HttpResponse response)
          Receives the next response entity available from this connection and attaches it to an existing HttpResponse object.
 org.apache.http.HttpResponse receiveResponseHeader(org.apache.http.params.HttpParams params)
          Receives the request line and headers of the next response available from this connection.
 void sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest request)
          Sends the request entity over the connection.
 void sendRequestHeader(org.apache.http.HttpRequest request)
          Sends the request line and all headers over the connection.
protected  void sendRequestHeaders(org.apache.http.HttpRequest request)
           
protected  void sendRequestLine(org.apache.http.HttpRequest request)
           
 void setEntityDeserializer(org.apache.http.entity.EntityDeserializer entitydeserializer)
           
 void setEntitySerializer(org.apache.http.entity.EntitySerializer entityserializer)
           
 void setLocalAddress(java.net.InetAddress localAddress)
          Sets the local address the connection will be bound to upon opening.
 void setReceiverFactory(org.apache.http.io.HttpDataReceiverFactory rcvfactory)
           
 void setResponseFactory(org.apache.http.HttpResponseFactory responsefactory)
           
 void setTargetHost(org.apache.http.HttpHost targethost)
          Provides the implementation with the host it is supposed to connect to.
 void setTransmitterFactory(org.apache.http.io.HttpDataTransmitterFactory trxfactory)
           
 void shutdown()
          This method will force close the connection.
private static boolean startsWithHTTP(org.apache.http.io.CharArrayBuffer buffer)
          Tests if the string starts with 'HTTP' signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.http.HttpConnection
close, isOpen, isStale, shutdown
 

Field Detail

targethost

private org.apache.http.HttpHost targethost

localAddress

private java.net.InetAddress localAddress

maxHeaderCount

private int maxHeaderCount

buffer

private final org.apache.http.io.CharArrayBuffer buffer

responsefactory

private org.apache.http.HttpResponseFactory responsefactory

entityserializer

private org.apache.http.entity.EntitySerializer entityserializer

entitydeserializer

private org.apache.http.entity.EntityDeserializer entitydeserializer

open

protected volatile boolean open

socket

protected java.net.Socket socket

datatransmitter

protected org.apache.http.io.HttpDataTransmitter datatransmitter

datareceiver

protected org.apache.http.io.HttpDataReceiver datareceiver
Constructor Detail

DefaultHttpClientConnection

public DefaultHttpClientConnection(org.apache.http.HttpHost targethost,
                                   java.net.InetAddress localAddress)

DefaultHttpClientConnection

public DefaultHttpClientConnection(org.apache.http.HttpHost targethost)

DefaultHttpClientConnection

public DefaultHttpClientConnection()
Method Detail

setResponseFactory

public void setResponseFactory(org.apache.http.HttpResponseFactory responsefactory)

setEntityDeserializer

public void setEntityDeserializer(org.apache.http.entity.EntityDeserializer entitydeserializer)

setEntitySerializer

public void setEntitySerializer(org.apache.http.entity.EntitySerializer entityserializer)

open

public void open(org.apache.http.params.HttpParams params)
          throws java.io.IOException
Description copied from interface: org.apache.http.HttpClientConnection
Opens the connection. Implementations may use additional settings from the HttpParams hierarchy.

Specified by:
open in interface org.apache.http.HttpClientConnection

getTargetHost

public org.apache.http.HttpHost getTargetHost()
Description copied from interface: org.apache.http.HttpClientConnection
Returns the current target host as set by @link #setTargetHost(HttpHost).

Specified by:
getTargetHost in interface org.apache.http.HttpClientConnection

getLocalAddress

public java.net.InetAddress getLocalAddress()
Description copied from interface: org.apache.http.HttpClientConnection
The local address the connection is or will be bound to as set by

Specified by:
getLocalAddress in interface org.apache.http.HttpClientConnection

setTargetHost

public void setTargetHost(org.apache.http.HttpHost targethost)
Description copied from interface: org.apache.http.HttpClientConnection
Provides the implementation with the host it is supposed to connect to. The host must be set prior to a call to

Specified by:
setTargetHost in interface org.apache.http.HttpClientConnection

setLocalAddress

public void setLocalAddress(java.net.InetAddress localAddress)
Description copied from interface: org.apache.http.HttpClientConnection
Sets the local address the connection will be bound to upon opening. The local address can not only be set as long as the connection is not open. If no local address is specified it is up to the implementation to decide.

Specified by:
setLocalAddress in interface org.apache.http.HttpClientConnection

isResponseAvailable

public boolean isResponseAvailable(int timeout)
                            throws java.io.IOException
Description copied from interface: org.apache.http.HttpClientConnection
Checks if response data is available from the connection. May wait for the specified time until some data becomes available. Note that some implementations may completely ignore the timeout parameter.

Specified by:
isResponseAvailable in interface org.apache.http.HttpClientConnection

sendRequestHeader

public void sendRequestHeader(org.apache.http.HttpRequest request)
                       throws org.apache.http.HttpException,
                              java.io.IOException
Description copied from interface: org.apache.http.HttpClientConnection
Sends the request line and all headers over the connection.

Specified by:
sendRequestHeader in interface org.apache.http.HttpClientConnection

sendRequestEntity

public void sendRequestEntity(org.apache.http.HttpEntityEnclosingRequest request)
                       throws org.apache.http.HttpException,
                              java.io.IOException
Description copied from interface: org.apache.http.HttpClientConnection
Sends the request entity over the connection.

Specified by:
sendRequestEntity in interface org.apache.http.HttpClientConnection

flush

public void flush()
           throws java.io.IOException
Description copied from interface: org.apache.http.HttpClientConnection
Writes out all pending buffered data over the open connection.

Specified by:
flush in interface org.apache.http.HttpClientConnection

sendRequestLine

protected void sendRequestLine(org.apache.http.HttpRequest request)
                        throws org.apache.http.HttpException,
                               java.io.IOException

sendRequestHeaders

protected void sendRequestHeaders(org.apache.http.HttpRequest request)
                           throws org.apache.http.HttpException,
                                  java.io.IOException

receiveResponseHeader

public org.apache.http.HttpResponse receiveResponseHeader(org.apache.http.params.HttpParams params)
                                                   throws org.apache.http.HttpException,
                                                          java.io.IOException
Description copied from interface: org.apache.http.HttpClientConnection
Receives the request line and headers of the next response available from this connection. The caller should examine the HttpResponse object to find out if it should try to receive a response entity as well.

Specified by:
receiveResponseHeader in interface org.apache.http.HttpClientConnection

receiveResponseEntity

public void receiveResponseEntity(org.apache.http.HttpResponse response)
                           throws org.apache.http.HttpException,
                                  java.io.IOException
Description copied from interface: org.apache.http.HttpClientConnection
Receives the next response entity available from this connection and attaches it to an existing HttpResponse object.

Specified by:
receiveResponseEntity in interface org.apache.http.HttpClientConnection

startsWithHTTP

private static boolean startsWithHTTP(org.apache.http.io.CharArrayBuffer buffer)
Tests if the string starts with 'HTTP' signature.


readResponseStatusLine

protected org.apache.http.HttpResponse readResponseStatusLine(org.apache.http.params.HttpParams params)
                                                       throws org.apache.http.HttpException,
                                                              java.io.IOException

readResponseHeaders

protected void readResponseHeaders(org.apache.http.HttpResponse response)
                            throws org.apache.http.HttpException,
                                   java.io.IOException

setReceiverFactory

public void setReceiverFactory(org.apache.http.io.HttpDataReceiverFactory rcvfactory)

setTransmitterFactory

public void setTransmitterFactory(org.apache.http.io.HttpDataTransmitterFactory trxfactory)

assertNotOpen

protected void assertNotOpen()

assertOpen

protected void assertOpen()

bind

protected void bind(java.net.Socket socket,
                    org.apache.http.params.HttpParams params)
             throws java.io.IOException

isOpen

public boolean isOpen()
Description copied from interface: org.apache.http.HttpConnection
Checks if this connection is open.

Specified by:
isOpen in interface org.apache.http.HttpConnection

shutdown

public void shutdown()
              throws java.io.IOException
Description copied from interface: org.apache.http.HttpConnection
This method will force close the connection. This is the only method, which may be called from a different thread to terminate the connection. This method will not attempt to flush the transmitter's internal buffer prior to closing the underlying socket.

Specified by:
shutdown in interface org.apache.http.HttpConnection

close

public void close()
           throws java.io.IOException
Description copied from interface: org.apache.http.HttpConnection
This method will gracefully close the connection. It will attempt to flush the transmitter's internal buffer prior to closing the underlying socket. This method MAY NOT be called from a different thread to force shutdown the connection. Use #shutdown() instead.

Specified by:
close in interface org.apache.http.HttpConnection

isStale

public boolean isStale()
Description copied from interface: org.apache.http.HttpConnection
Network connections may get closed during some time of inactivity for several reasons. The next time a read is attempted on such a connection it will throw an IOException. This method tries to alleviate this inconvenience by trying to find out if a connection is still usable. Implementations may do that by attempting a read with a very small timeout. Thus this method may block for a small indefinite time before returning a result.

Specified by:
isStale in interface org.apache.http.HttpConnection