org.apache.http.impl.conn
Class DefaultClientConnection

java.lang.Object
  extended by org.apache.http.impl.AbstractHttpClientConnection
      extended by org.apache.http.impl.SocketHttpClientConnection
          extended by org.apache.http.impl.conn.DefaultClientConnection
All Implemented Interfaces:
OperatedClientConnection, org.apache.http.HttpClientConnection, org.apache.http.HttpConnection, org.apache.http.HttpInetConnection

public class DefaultClientConnection
extends org.apache.http.impl.SocketHttpClientConnection
implements OperatedClientConnection

Default implementation of an operated client connection.

Since:
4.0
Version:
$Revision: 573830 $ $Date: 2007-09-08 14:41:42 +0200 (Sat, 08 Sep 2007) $
Author:
Roland Weber

Constructor Summary
DefaultClientConnection()
           
 
Method Summary
 void announce(java.net.Socket sock)
          Announces opening of this connection.
 void close()
           
protected  org.apache.http.io.HttpMessageParser createResponseParser(org.apache.http.io.SessionInputBuffer buffer, org.apache.http.HttpResponseFactory responseFactory, org.apache.http.params.HttpParams params)
           
protected  org.apache.http.io.SessionInputBuffer createSessionInputBuffer(java.net.Socket socket, int buffersize, org.apache.http.params.HttpParams params)
           
protected  org.apache.http.io.SessionOutputBuffer createSessionOutputBuffer(java.net.Socket socket, int buffersize, org.apache.http.params.HttpParams params)
           
 java.net.Socket getSocket()
          Obtains the socket for this connection.
 org.apache.http.HttpHost getTargetHost()
          Obtains the target host for this connection.
 boolean isSecure()
          Indicates whether this connection is secure.
 void open(java.net.Socket sock, org.apache.http.HttpHost target, boolean secure, org.apache.http.params.HttpParams params)
          Opens this connection.
 org.apache.http.HttpResponse receiveResponseHeader()
           
 void sendRequestHeader(org.apache.http.HttpRequest request)
           
 void shutdown()
          Force-closes this connection.
 void update(java.net.Socket sock, org.apache.http.HttpHost target, boolean secure, org.apache.http.params.HttpParams params)
          Updates this connection.
 
Methods inherited from class org.apache.http.impl.SocketHttpClientConnection
assertNotOpen, assertOpen, bind, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSocketTimeout, isOpen, setSocketTimeout
 
Methods inherited from class org.apache.http.impl.AbstractHttpClientConnection
createEntityDeserializer, createEntitySerializer, createHttpResponseFactory, createRequestWriter, doFlush, flush, getMetrics, init, isResponseAvailable, isStale, receiveResponseEntity, sendRequestEntity
 
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.HttpClientConnection
flush, isResponseAvailable, receiveResponseEntity, sendRequestEntity
 
Methods inherited from interface org.apache.http.HttpConnection
getMetrics, getSocketTimeout, isOpen, isStale, setSocketTimeout
 
Methods inherited from interface org.apache.http.HttpInetConnection
getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort
 
Methods inherited from interface org.apache.http.HttpConnection
getMetrics, getSocketTimeout, isOpen, isStale, setSocketTimeout
 

Constructor Detail

DefaultClientConnection

public DefaultClientConnection()
Method Detail

getTargetHost

public final org.apache.http.HttpHost getTargetHost()
Description copied from interface: OperatedClientConnection
Obtains the target host for this connection. If the connection is to a proxy but not tunnelled, this is the proxy. If the connection is tunnelled through a proxy, this is the target of the tunnel.
The return value is well-defined only while the connection is open. It may change even while the connection is open, because of an update.

Specified by:
getTargetHost in interface OperatedClientConnection
Returns:
the host to which this connection is opened

isSecure

public final boolean isSecure()
Description copied from interface: OperatedClientConnection
Indicates whether this connection is secure. The return value is well-defined only while the connection is open. It may change even while the connection is open, because of an update.

Specified by:
isSecure in interface OperatedClientConnection
Returns:
true if this connection is secure, false otherwise

getSocket

public final java.net.Socket getSocket()
Description copied from interface: OperatedClientConnection
Obtains the socket for this connection. The return value is well-defined only while the connection is open. It may change even while the connection is open, because of an update.

Specified by:
getSocket in interface OperatedClientConnection
Overrides:
getSocket in class org.apache.http.impl.SocketHttpClientConnection
Returns:
the socket for communicating with the target host

announce

public void announce(java.net.Socket sock)
Description copied from interface: OperatedClientConnection
Announces opening of this connection. Opening can be announced only while the connection is closed. This is an optional step, you can call open without an announcement.
By calling this method, you provide the connection with the unconnected socket that will be connected in order to call open. This allows the connection to close that socket if shutdown is called before it is open. Closing the unconnected socket will interrupt a thread that is blocked on the connect. Otherwise, that thread will either time out on the connect, or it returns successfully and then opens this connection which was just shut down.
Note: The result of getSocket is defined only for open connections. You MUST NOT rely on that method to return the unconnected socket after announcing.

Specified by:
announce in interface OperatedClientConnection
Parameters:
sock - the unconnected socket which is about to be connected in order to call open. null can be passed to undo a previous call.

shutdown

public void shutdown()
              throws java.io.IOException
Force-closes this connection. If it is not yet open but announced, the associated socket is closed. That will interrupt a thread that is blocked on connecting the socket.

Specified by:
shutdown in interface org.apache.http.HttpConnection
Overrides:
shutdown in class org.apache.http.impl.SocketHttpClientConnection
Throws:
java.io.IOException - in case of a problem

close

public void close()
           throws java.io.IOException
Specified by:
close in interface org.apache.http.HttpConnection
Overrides:
close in class org.apache.http.impl.SocketHttpClientConnection
Throws:
java.io.IOException

createSessionInputBuffer

protected org.apache.http.io.SessionInputBuffer createSessionInputBuffer(java.net.Socket socket,
                                                                         int buffersize,
                                                                         org.apache.http.params.HttpParams params)
                                                                  throws java.io.IOException
Overrides:
createSessionInputBuffer in class org.apache.http.impl.SocketHttpClientConnection
Throws:
java.io.IOException

createSessionOutputBuffer

protected org.apache.http.io.SessionOutputBuffer createSessionOutputBuffer(java.net.Socket socket,
                                                                           int buffersize,
                                                                           org.apache.http.params.HttpParams params)
                                                                    throws java.io.IOException
Overrides:
createSessionOutputBuffer in class org.apache.http.impl.SocketHttpClientConnection
Throws:
java.io.IOException

createResponseParser

protected org.apache.http.io.HttpMessageParser createResponseParser(org.apache.http.io.SessionInputBuffer buffer,
                                                                    org.apache.http.HttpResponseFactory responseFactory,
                                                                    org.apache.http.params.HttpParams params)
Overrides:
createResponseParser in class org.apache.http.impl.AbstractHttpClientConnection

open

public void open(java.net.Socket sock,
                 org.apache.http.HttpHost target,
                 boolean secure,
                 org.apache.http.params.HttpParams params)
          throws java.io.IOException
Description copied from interface: OperatedClientConnection
Opens this connection. A connection can be openend only while it is closed. To modify a connection while it is open, use update.

Specified by:
open in interface OperatedClientConnection
Parameters:
sock - the open socket for communicating with the target host
target - the target host of this connection
secure - true if this connection is secure, for example if an SSLSocket is used, or false if it is not secure
params - parameters for this connection. The parameters will be used when creating dependent objects, for example to determine buffer sizes.
Throws:
java.io.IOException

update

public void update(java.net.Socket sock,
                   org.apache.http.HttpHost target,
                   boolean secure,
                   org.apache.http.params.HttpParams params)
            throws java.io.IOException
Description copied from interface: OperatedClientConnection
Updates this connection. A connection can be updated only while it is open. Updates are used for example when a tunnel has been established, or when a TLS/SSL connection has been layered on top of a plain socket connection.
Note: Updating the connection will not close the previously used socket. It is the caller's responsibility to close that socket if it is no longer required.

Specified by:
update in interface OperatedClientConnection
Parameters:
sock - the new socket for communicating with the target host, or null to continue using the old socket. If null is passed, helper objects that depend on the socket should be re-used. In that case, some changes in the parameters will not take effect.
target - the new target host of this connection
secure - true if this connection is now secure, false if it is not secure
params - new parameters for this connection
Throws:
java.io.IOException

receiveResponseHeader

public org.apache.http.HttpResponse receiveResponseHeader()
                                                   throws org.apache.http.HttpException,
                                                          java.io.IOException
Specified by:
receiveResponseHeader in interface org.apache.http.HttpClientConnection
Overrides:
receiveResponseHeader in class org.apache.http.impl.AbstractHttpClientConnection
Throws:
org.apache.http.HttpException
java.io.IOException

sendRequestHeader

public void sendRequestHeader(org.apache.http.HttpRequest request)
                       throws org.apache.http.HttpException,
                              java.io.IOException
Specified by:
sendRequestHeader in interface org.apache.http.HttpClientConnection
Overrides:
sendRequestHeader in class org.apache.http.impl.AbstractHttpClientConnection
Throws:
org.apache.http.HttpException
java.io.IOException


Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.