Package org.apache.http.impl.conn
Class DefaultClientConnection
java.lang.Object
org.apache.http.impl.AbstractHttpClientConnection
org.apache.http.impl.SocketHttpClientConnection
org.apache.http.impl.conn.DefaultClientConnection
- All Implemented Interfaces:
OperatedClientConnection,HttpClientConnection,HttpConnection,HttpInetConnection
public class DefaultClientConnection extends SocketHttpClientConnection implements OperatedClientConnection
Default implementation of an operated client connection.
- Since:
- 4.0
- Version:
- $Revision: 673450 $ $Date: 2008-07-02 10:35:05 -0700 (Wed, 02 Jul 2008) $
- Author:
- Roland Weber
-
Constructor Summary
Constructors Constructor Description DefaultClientConnection() -
Method Summary
Modifier and Type Method Description voidclose()Closes this connection gracefully.protected HttpMessageParsercreateResponseParser(SessionInputBuffer buffer, HttpResponseFactory responseFactory, HttpParams params)protected SessionInputBuffercreateSessionInputBuffer(Socket socket, int buffersize, HttpParams params)protected SessionOutputBuffercreateSessionOutputBuffer(Socket socket, int buffersize, HttpParams params)SocketgetSocket()Obtains the socket for this connection.HttpHostgetTargetHost()Obtains the target host for this connection.booleanisSecure()Indicates whether this connection is secure.voidopenCompleted(boolean secure, HttpParams params)Signals that the connection has been successfully open.voidopening(Socket sock, HttpHost target)Signals that this connection is in the process of being open.HttpResponsereceiveResponseHeader()Receives the request line and headers of the next response available from this connection.voidsendRequestHeader(HttpRequest request)Sends the request line and all headers over the connection.voidshutdown()Force-closes this connection.voidupdate(Socket sock, HttpHost target, boolean secure, HttpParams params)Updates this connection.Methods inherited from class org.apache.http.impl.SocketHttpClientConnection
assertNotOpen, assertOpen, bind, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSocketTimeout, isOpen, setSocketTimeoutMethods inherited from class org.apache.http.impl.AbstractHttpClientConnection
createEntityDeserializer, createEntitySerializer, createHttpResponseFactory, createRequestWriter, doFlush, flush, getMetrics, init, isResponseAvailable, isStale, receiveResponseEntity, sendRequestEntityMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.http.HttpClientConnection
flush, isResponseAvailable, receiveResponseEntity, sendRequestEntityMethods inherited from interface org.apache.http.HttpConnection
getMetrics, getSocketTimeout, isOpen, isStale, setSocketTimeoutMethods inherited from interface org.apache.http.HttpInetConnection
getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort
-
Constructor Details
-
DefaultClientConnection
public DefaultClientConnection()
-
-
Method Details
-
getTargetHost
Description copied from interface:OperatedClientConnectionObtains 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 anupdate.- Specified by:
getTargetHostin interfaceOperatedClientConnection- Returns:
- the host to which this connection is opened
-
isSecure
public final boolean isSecure()Description copied from interface:OperatedClientConnectionIndicates 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 anupdate.- Specified by:
isSecurein interfaceOperatedClientConnection- Returns:
trueif this connection is secure,falseotherwise
-
getSocket
Description copied from interface:OperatedClientConnectionObtains 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 anupdate.- Specified by:
getSocketin interfaceOperatedClientConnection- Overrides:
getSocketin classSocketHttpClientConnection- Returns:
- the socket for communicating with the
target host
-
opening
Description copied from interface:OperatedClientConnectionSignals that this connection is in the process of being open.
By calling this method, you can provide the connection with the unconnected socket that will be connected beforeOperatedClientConnection.openCompleted(boolean, org.apache.http.params.HttpParams)is called. This allows the connection to close that socket ifshutdownis 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.
You also must callOperatedClientConnection.openCompleted(boolean, org.apache.http.params.HttpParams)in order to complete the process- Specified by:
openingin interfaceOperatedClientConnection- Parameters:
sock- the unconnected socket which is about to be connected.target- the target host of this connection- Throws:
IOException
-
openCompleted
Description copied from interface:OperatedClientConnectionSignals that the connection has been successfully open. An attempt to call this method on an open connection will cause an exception.- Specified by:
openCompletedin interfaceOperatedClientConnection- Parameters:
secure-trueif this connection is secure, for example if anSSLSocketis used, orfalseif it is not secureparams- parameters for this connection. The parameters will be used when creating dependent objects, for example to determine buffer sizes.- Throws:
IOException
-
shutdown
Force-closes this connection. If the connection is still in the process of being open (the methodopeningwas already called butopenCompletedwas not), the associated socket that is being connected to a remote address will be closed. That will interrupt a thread that is blocked on connecting the socket. If the connection is not yet open, this will prevent the connection from being opened.- Specified by:
shutdownin interfaceHttpConnection- Overrides:
shutdownin classSocketHttpClientConnection- Throws:
IOException- in case of a problem
-
close
Description copied from interface:HttpConnectionCloses this connection gracefully. This method will attempt to flush the transmitter's internal buffer prior to closing the underlying socket. This method MUST NOT be called from a different thread to force shutdown of the connection. Useshutdowninstead.- Specified by:
closein interfaceHttpConnection- Overrides:
closein classSocketHttpClientConnection- Throws:
IOException
-
createSessionInputBuffer
protected SessionInputBuffer createSessionInputBuffer(Socket socket, int buffersize, HttpParams params) throws IOException- Overrides:
createSessionInputBufferin classSocketHttpClientConnection- Throws:
IOException
-
createSessionOutputBuffer
protected SessionOutputBuffer createSessionOutputBuffer(Socket socket, int buffersize, HttpParams params) throws IOException- Overrides:
createSessionOutputBufferin classSocketHttpClientConnection- Throws:
IOException
-
createResponseParser
protected HttpMessageParser createResponseParser(SessionInputBuffer buffer, HttpResponseFactory responseFactory, HttpParams params)- Overrides:
createResponseParserin classAbstractHttpClientConnection
-
update
public void update(Socket sock, HttpHost target, boolean secure, HttpParams params) throws IOExceptionDescription copied from interface:OperatedClientConnectionUpdates 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:
updatein interfaceOperatedClientConnection- Parameters:
sock- the new socket for communicating with the target host, ornullto continue using the old socket. Ifnullis 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 connectionsecure-trueif this connection is now secure,falseif it is not secureparams- new parameters for this connection- Throws:
IOException
-
receiveResponseHeader
Description copied from interface:HttpClientConnectionReceives 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:
receiveResponseHeaderin interfaceHttpClientConnection- Overrides:
receiveResponseHeaderin classAbstractHttpClientConnection- Returns:
- a new HttpResponse object with status line and headers initialized.
- Throws:
HttpExceptionIOException
-
sendRequestHeader
Description copied from interface:HttpClientConnectionSends the request line and all headers over the connection.- Specified by:
sendRequestHeaderin interfaceHttpClientConnection- Overrides:
sendRequestHeaderin classAbstractHttpClientConnection- Parameters:
request- the request whose headers to send.- Throws:
HttpExceptionIOException
-