@NotThreadSafe public class DefaultClientConnection extends SocketHttpClientConnection implements OperatedClientConnection, HttpContext
The following parameters can be used to customize the behavior of this class:
RESERVED_PREFIX| Constructor and Description |
|---|
DefaultClientConnection() |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected HttpMessageParser<HttpResponse> |
createResponseParser(SessionInputBuffer buffer,
HttpResponseFactory responseFactory,
HttpParams params) |
protected SessionInputBuffer |
createSessionInputBuffer(Socket socket,
int buffersize,
HttpParams params) |
protected SessionOutputBuffer |
createSessionOutputBuffer(Socket socket,
int buffersize,
HttpParams params) |
Object |
getAttribute(String id) |
Socket |
getSocket()
Obtains the socket for this connection.
|
HttpHost |
getTargetHost()
Obtains the target host for this connection.
|
boolean |
isSecure()
Indicates whether this connection is secure.
|
void |
openCompleted(boolean secure,
HttpParams params)
Signals that the connection has been successfully open.
|
void |
opening(Socket sock,
HttpHost target)
Signals that this connection is in the process of being open.
|
HttpResponse |
receiveResponseHeader() |
Object |
removeAttribute(String id) |
void |
sendRequestHeader(HttpRequest request) |
void |
setAttribute(String id,
Object obj) |
void |
shutdown()
Force-closes this connection.
|
void |
update(Socket sock,
HttpHost target,
boolean secure,
HttpParams params)
Updates this connection.
|
assertNotOpen, assertOpen, bind, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSocketTimeout, isOpen, setSocketTimeout, toStringcreateConnectionMetrics, createEntityDeserializer, createEntitySerializer, createHttpResponseFactory, createRequestWriter, doFlush, flush, getMetrics, init, isEof, isResponseAvailable, isStale, receiveResponseEntity, sendRequestEntityclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitflush, isResponseAvailable, receiveResponseEntity, sendRequestEntitygetLocalAddress, getLocalPort, getRemoteAddress, getRemotePortgetMetrics, getSocketTimeout, isOpen, isStale, setSocketTimeoutpublic final HttpHost getTargetHost()
OperatedClientConnectionupdate.getTargetHost in interface OperatedClientConnectionpublic final boolean isSecure()
OperatedClientConnectionupdate.isSecure in interface OperatedClientConnectiontrue if this connection is secure,
false otherwisepublic final Socket getSocket()
OperatedClientConnectionupdate.getSocket in interface OperatedClientConnectiongetSocket in class SocketHttpClientConnectiontarget hostpublic void opening(Socket sock, HttpHost target) throws IOException
OperatedClientConnection
By calling this method, the connection can be re-initialized
with a new Socket instance before OperatedClientConnection.openCompleted(boolean, org.apache.http.params.HttpParams) is called.
This enabled the connection to close that socket if
shutdown
is called before it is fully open. Closing an 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.
This method can be called multiple times if the connection is layered over another protocol. Note: This method will not close the previously used socket. It is the caller's responsibility to close that socket if it is no longer required.
The caller must invoke OperatedClientConnection.openCompleted(boolean, org.apache.http.params.HttpParams) in order to complete
the process.
opening in interface OperatedClientConnectionsock - the unconnected socket which is about to
be connected.target - the target host of this connectionIOExceptionpublic void openCompleted(boolean secure,
HttpParams params)
throws IOException
OperatedClientConnectionopenCompleted in interface OperatedClientConnectionsecure - true if this connection is secure, for
example if an SSLSocket is used, or
false if it is not secureparams - parameters for this connection. The parameters will
be used when creating dependent objects, for example
to determine buffer sizes.IOExceptionpublic void shutdown()
throws IOException
opening was already called but
openCompleted was 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.shutdown in interface HttpConnectionshutdown in class SocketHttpClientConnectionIOException - in case of a problempublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface HttpConnectionclose in class SocketHttpClientConnectionIOExceptionprotected SessionInputBuffer createSessionInputBuffer(Socket socket, int buffersize, HttpParams params) throws IOException
createSessionInputBuffer in class SocketHttpClientConnectionIOExceptionprotected SessionOutputBuffer createSessionOutputBuffer(Socket socket, int buffersize, HttpParams params) throws IOException
createSessionOutputBuffer in class SocketHttpClientConnectionIOExceptionprotected HttpMessageParser<HttpResponse> createResponseParser(SessionInputBuffer buffer, HttpResponseFactory responseFactory, HttpParams params)
createResponseParser in class AbstractHttpClientConnectionpublic void update(Socket sock, HttpHost target, boolean secure, HttpParams params) throws IOException
OperatedClientConnectionupdate in interface OperatedClientConnectionsock - 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 connectionsecure - true if this connection is now secure,
false if it is not secureparams - new parameters for this connectionIOExceptionpublic HttpResponse receiveResponseHeader() throws HttpException, IOException
receiveResponseHeader in interface HttpClientConnectionreceiveResponseHeader in class AbstractHttpClientConnectionHttpExceptionIOExceptionpublic void sendRequestHeader(HttpRequest request) throws HttpException, IOException
sendRequestHeader in interface HttpClientConnectionsendRequestHeader in class AbstractHttpClientConnectionHttpExceptionIOExceptionpublic Object getAttribute(String id)
getAttribute in interface HttpContextpublic Object removeAttribute(String id)
removeAttribute in interface HttpContextpublic void setAttribute(String id, Object obj)
setAttribute in interface HttpContextCopyright © 1999–2013 The Apache Software Foundation. All rights reserved.