@NotThreadSafe public class DefaultClientConnection extends SocketHttpClientConnection implements OperatedClientConnection, HttpContext
The following parameters can be used to customize the behavior of this class:
RESERVED_PREFIX| 构造器和说明 |
|---|
DefaultClientConnection() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close()
Closes this connection gracefully.
|
protected HttpMessageParser<HttpResponse> |
createResponseParser(SessionInputBuffer buffer,
HttpResponseFactory responseFactory,
HttpParams params)
Creates an instance of
HttpMessageParser to be used for parsing
HTTP responses received over this connection. |
protected SessionInputBuffer |
createSessionInputBuffer(java.net.Socket socket,
int buffersize,
HttpParams params)
Creates an instance of
SocketInputBuffer to be used for
receiving data from the given Socket. |
protected SessionOutputBuffer |
createSessionOutputBuffer(java.net.Socket socket,
int buffersize,
HttpParams params)
Creates an instance of
SessionOutputBuffer to be used for
sending data to the given Socket. |
java.lang.Object |
getAttribute(java.lang.String id)
Obtains attribute with the given name.
|
java.net.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(java.net.Socket sock,
HttpHost target)
Signals that this connection is in the process of being open.
|
HttpResponse |
receiveResponseHeader()
Receives the request line and headers of the next response available from
this connection.
|
java.lang.Object |
removeAttribute(java.lang.String id)
Removes attribute with the given name from the context.
|
void |
sendRequestHeader(HttpRequest request)
Sends the request line and all headers over the connection.
|
void |
setAttribute(java.lang.String id,
java.lang.Object obj)
Sets value of the attribute with the given name.
|
void |
shutdown()
Force-closes this connection.
|
void |
update(java.net.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 在接口中 OperatedClientConnectionpublic final boolean isSecure()
OperatedClientConnectionupdate.isSecure 在接口中 OperatedClientConnectiontrue if this connection is secure,
false otherwisepublic final java.net.Socket getSocket()
OperatedClientConnectionupdate.getSocket 在接口中 OperatedClientConnectiongetSocket 在类中 SocketHttpClientConnectiontarget hostpublic void opening(java.net.Socket sock,
HttpHost target)
throws java.io.IOException
OperatedClientConnection
By calling this method, the connection can be re-initialized
with a new Socket instance before OperatedClientConnection.openCompleted(boolean, depends.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, depends.org.apache.http.params.HttpParams) in order to complete
the process.
opening 在接口中 OperatedClientConnectionsock - the unconnected socket which is about to
be connected.target - the target host of this connectionjava.io.IOExceptionpublic void openCompleted(boolean secure,
HttpParams params)
throws java.io.IOException
OperatedClientConnectionopenCompleted 在接口中 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.java.io.IOExceptionpublic void shutdown()
throws java.io.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 在接口中 HttpConnectionshutdown 在类中 SocketHttpClientConnectionjava.io.IOException - in case of a problempublic void close()
throws java.io.IOException
HttpConnectionshutdown instead.close 在接口中 HttpConnectionclose 在接口中 java.io.Closeableclose 在接口中 java.lang.AutoCloseableclose 在类中 SocketHttpClientConnectionjava.io.IOExceptionprotected SessionInputBuffer createSessionInputBuffer(java.net.Socket socket, int buffersize, HttpParams params) throws java.io.IOException
SocketHttpClientConnectionSocketInputBuffer to be used for
receiving data from the given Socket.
This method can be overridden in a super class in order to provide
a custom implementation of SessionInputBuffer interface.
createSessionInputBuffer 在类中 SocketHttpClientConnectionsocket - the socket.buffersize - the buffer size.params - HTTP parameters.java.io.IOException - in case of an I/O error.SocketInputBuffer.SocketInputBuffer(Socket, int, HttpParams)protected SessionOutputBuffer createSessionOutputBuffer(java.net.Socket socket, int buffersize, HttpParams params) throws java.io.IOException
SocketHttpClientConnectionSessionOutputBuffer to be used for
sending data to the given Socket.
This method can be overridden in a super class in order to provide
a custom implementation of SocketOutputBuffer interface.
createSessionOutputBuffer 在类中 SocketHttpClientConnectionsocket - the socket.buffersize - the buffer size.params - HTTP parameters.java.io.IOException - in case of an I/O error.SocketOutputBuffer.SocketOutputBuffer(Socket, int, HttpParams)protected HttpMessageParser<HttpResponse> createResponseParser(SessionInputBuffer buffer, HttpResponseFactory responseFactory, HttpParams params)
AbstractHttpClientConnectionHttpMessageParser to be used for parsing
HTTP responses received over this connection.
This method can be overridden in a super class in order to provide
a different implementation of the HttpMessageParser interface or
to pass a different implementation of the
LineParser to the the
DefaultHttpResponseParser constructor.
createResponseParser 在类中 AbstractHttpClientConnectionbuffer - the session input buffer.responseFactory - the HTTP response factory.params - HTTP parameters.public void update(java.net.Socket sock,
HttpHost target,
boolean secure,
HttpParams params)
throws java.io.IOException
OperatedClientConnectionupdate 在接口中 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 connectionjava.io.IOExceptionpublic HttpResponse receiveResponseHeader() throws HttpException, java.io.IOException
HttpClientConnectionreceiveResponseHeader 在接口中 HttpClientConnectionreceiveResponseHeader 在类中 AbstractHttpClientConnectionHttpException - in case of HTTP protocol violationjava.io.IOException - in case of an I/O errorpublic void sendRequestHeader(HttpRequest request) throws HttpException, java.io.IOException
HttpClientConnectionsendRequestHeader 在接口中 HttpClientConnectionsendRequestHeader 在类中 AbstractHttpClientConnectionrequest - the request whose headers to send.HttpException - in case of HTTP protocol violationjava.io.IOException - in case of an I/O errorpublic java.lang.Object getAttribute(java.lang.String id)
HttpContextgetAttribute 在接口中 HttpContextid - the attribute name.null if not set.public java.lang.Object removeAttribute(java.lang.String id)
HttpContextremoveAttribute 在接口中 HttpContextid - the attribute name.null if not set.public void setAttribute(java.lang.String id,
java.lang.Object obj)
HttpContextsetAttribute 在接口中 HttpContextid - the attribute name.obj - the attribute value.