Top Description Fields Constructors Methods
org.apache.http.impl.conn

public Class DefaultClientConnection

extends SocketHttpClientConnection
implements OperatedClientConnection, ManagedHttpClientConnection, HttpContext
Class Inheritance
All Implemented Interfaces
org.apache.http.protocol.HttpContext, org.apache.http.conn.ManagedHttpClientConnection, org.apache.http.HttpInetConnection, org.apache.http.HttpConnection, java.io.Closeable, java.lang.AutoCloseable, org.apache.http.HttpClientConnection, org.apache.http.conn.OperatedClientConnection
Annotations
@Deprecated
Imports
java.io.IOException, .InterruptedIOException, java.net.Socket, java.util.HashMap, .Map, javax.net.ssl.SSLSession, .SSLSocket, org.apache.commons.logging.Log, .LogFactory, org.apache.http.Header, .HttpException, .HttpHost, .HttpRequest, .HttpResponse, .HttpResponseFactory, org.apache.http.conn.ManagedHttpClientConnection, .OperatedClientConnection, org.apache.http.impl.SocketHttpClientConnection, org.apache.http.io.HttpMessageParser, .SessionInputBuffer, .SessionOutputBuffer, org.apache.http.params.BasicHttpParams, .HttpParams, .HttpProtocolParams, org.apache.http.protocol.HttpContext, org.apache.http.util.Args

Deprecated

(4.3) use ManagedHttpClientConnectionFactory.

Default implementation of an operated client connection.
Since
4.0

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
attributes

connection specific attributes

private boolean
connSecure

Whether this connection is secure.

private final Log
private final Log
private volatile boolean
shutdown

True if this connection was shutdown.

private volatile Socket
private HttpHost
targetHost

The target host of this connection.

private final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
bind(final Socket
the socket to bind the connection to.
socket
)

Implements org.apache.http.conn.ManagedHttpClientConnection.bind.

Binds this connection to the given socket.
public void
protected HttpMessageParser<HttpResponse>
createResponseParser(final SessionInputBuffer
the session input buffer.
buffer
,
final HttpResponseFactory
the HTTP response factory.
responseFactory
,
final HttpParams
HTTP parameters.
params
)

Overrides org.apache.http.impl.AbstractHttpClientConnection.createResponseParser.

Deprecated as a consequence of HttpParams being deprecated.
Creates an instance of HttpMessageParser to be used for parsing HTTP responses received over this connection.
protected SessionInputBuffer
createSessionInputBuffer(final Socket
the socket.
socket
,
final int
the buffer size.
bufferSize
,
final HttpParams
HTTP parameters.
params
)

Overrides org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer.

Deprecated as a consequence of HttpParams being deprecated.
Creates an instance of SocketInputBuffer to be used for receiving data from the given Socket.
protected SessionOutputBuffer
createSessionOutputBuffer(final Socket
the socket.
socket
,
final int
the buffer size.
bufferSize
,
final HttpParams
HTTP parameters.
params
)

Overrides org.apache.http.impl.SocketHttpClientConnection.createSessionOutputBuffer.

Deprecated as a consequence of HttpParams being deprecated.
Creates an instance of SessionOutputBuffer to be used for sending data to the given Socket.
public Object
getAttribute(final String
the attribute name.
id
)

Implements org.apache.http.protocol.HttpContext.getAttribute.

Obtains attribute with the given name.
public String
getId()

Implements org.apache.http.conn.ManagedHttpClientConnection.getId.

Returns connection ID which is expected to be unique for the life span of the connection manager.
public final Socket
public SSLSession
getSSLSession()

Implements org.apache.http.conn.ManagedHttpClientConnection.getSSLSession.

Obtains the SSL session of the underlying connection, if any.
public final HttpHost
getTargetHost()

Implements org.apache.http.conn.OperatedClientConnection.getTargetHost.

Obtains the target host for this connection.
public final boolean
isSecure()

Implements org.apache.http.conn.OperatedClientConnection.isSecure.

Indicates whether this connection is secure.
public void
openCompleted(final boolean
true if this connection is secure, for example if an SSLSocket is used, or false if it is not secure
secure
,
final HttpParams
parameters for this connection. The parameters will be used when creating dependent objects, for example to determine buffer sizes.
params
)

Implements org.apache.http.conn.OperatedClientConnection.openCompleted.

Deprecated as a consequence of HttpParams being deprecated.
Signals that the connection has been successfully open.
public void
opening(final Socket
the unconnected socket which is about to be connected.
sock
,
final HttpHost
the target host of this connection
target
)

Implements org.apache.http.conn.OperatedClientConnection.opening.

Signals that this connection is in the process of being open.
public HttpResponse
receiveResponseHeader()

Overrides org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader.

Implements org.apache.http.HttpClientConnection.receiveResponseHeader.

Receives the request line and headers of the next response available from this connection.
public Object
removeAttribute(final String
the attribute name.
id
)

Implements org.apache.http.protocol.HttpContext.removeAttribute.

Removes attribute with the given name from the context.
public void
sendRequestHeader(final HttpRequest
the request whose headers to send.
request
)

Overrides org.apache.http.impl.AbstractHttpClientConnection.sendRequestHeader.

Implements org.apache.http.HttpClientConnection.sendRequestHeader.

Sends the request line and all headers over the connection.
public void
setAttribute(final String
the attribute name.
id
,
final Object
the attribute value.
obj
)

Implements org.apache.http.protocol.HttpContext.setAttribute.

Sets value of the attribute with the given name.
public void
public void
update(final Socket
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.
sock
,
final HttpHost
the new target host of this connection
target
,
final boolean
true if this connection is now secure, false if it is not secure
secure
,
final HttpParams
new parameters for this connection
params
)

Implements org.apache.http.conn.OperatedClientConnection.update.

Deprecated as a consequence of HttpParams being deprecated.
Updates this connection.
Inherited from org.apache.http.impl.SocketHttpClientConnection:
assertNotOpenassertOpenbindgetLocalAddressgetLocalPortgetRemoteAddressgetRemotePortgetSocketTimeoutisOpensetSocketTimeouttoString

Field Detail

attributesback to summary
private final Map<String, Object> attributes

connection specific attributes

connSecureback to summary
private boolean connSecure

Whether this connection is secure.

headerLogback to summary
private final Log headerLog
logback to summary
private final Log log
shutdownback to summary
private volatile boolean shutdown

True if this connection was shutdown.

socketback to summary
private volatile Socket socket

Hides org.apache.http.impl.SocketHttpClientConnection.socket.

The unconnected socket

targetHostback to summary
private HttpHost targetHost

The target host of this connection.

wireLogback to summary
private final Log wireLog

Constructor Detail

DefaultClientConnectionback to summary
public DefaultClientConnection()

Method Detail

bindback to summary
public void bind(final Socket socket) throws IOException

Implements org.apache.http.conn.ManagedHttpClientConnection.bind.

Doc from org.apache.http.conn.ManagedHttpClientConnection.bind.

Binds this connection to the given socket. The connection is considered open if it is bound and the underlying socket is connection to a remote host.

Parameters
socket:Socket

the socket to bind the connection to.

Annotations
@Override
closeback to summary
public void close() throws IOException

Overrides org.apache.http.impl.SocketHttpClientConnection.close.

Implements org.apache.http.HttpConnection.close.

Doc from org.apache.http.HttpConnection.close.

Closes this connection gracefully. This method will attempt to flush the internal output buffer prior to closing the underlying socket. This method MUST NOT be called from a different thread to force shutdown of the connection. Use shutdown instead.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

createResponseParserback to summary
protected HttpMessageParser<HttpResponse> createResponseParser(final SessionInputBuffer buffer, final HttpResponseFactory responseFactory, final HttpParams params)

Overrides org.apache.http.impl.AbstractHttpClientConnection.createResponseParser.

Doc from org.apache.http.impl.AbstractHttpClientConnection.createResponseParser.

Deprecated

as a consequence of HttpParams being deprecated. See corresponding docs for further information.

Creates an instance of HttpMessageParser 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 org.apache.http.message.LineParser to the the DefaultHttpResponseParser constructor.

Parameters
buffer:SessionInputBuffer

the session input buffer.

responseFactory:HttpResponseFactory

the HTTP response factory.

params:HttpParams

HTTP parameters.

Returns:HttpMessageParser<HttpResponse>

HTTP message parser.

Annotations
@Override
createSessionInputBufferback to summary
protected SessionInputBuffer createSessionInputBuffer(final Socket socket, final int bufferSize, final HttpParams params) throws IOException

Overrides org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer.

Doc from org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer.

Deprecated

as a consequence of HttpParams being deprecated. See corresponding docs for further information.

Creates an instance of SocketInputBuffer 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.

Parameters
socket:Socket

the socket.

bufferSize:int

the buffer size.

params:HttpParams

HTTP parameters.

Returns:SessionInputBuffer

session input buffer.

Annotations
@Override
Exceptions
IOException:
in case of an I/O error.
createSessionOutputBufferback to summary
protected SessionOutputBuffer createSessionOutputBuffer(final Socket socket, final int bufferSize, final HttpParams params) throws IOException

Overrides org.apache.http.impl.SocketHttpClientConnection.createSessionOutputBuffer.

Doc from org.apache.http.impl.SocketHttpClientConnection.createSessionOutputBuffer.

Deprecated

as a consequence of HttpParams being deprecated. See corresponding docs for further information.

Creates an instance of SessionOutputBuffer 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.

Parameters
socket:Socket

the socket.

bufferSize:int

the buffer size.

params:HttpParams

HTTP parameters.

Returns:SessionOutputBuffer

session output buffer.

Annotations
@Override
Exceptions
IOException:
in case of an I/O error.
getAttributeback to summary
public Object getAttribute(final String id)

Implements org.apache.http.protocol.HttpContext.getAttribute.

Doc from org.apache.http.protocol.HttpContext.getAttribute.

Obtains attribute with the given name.

Parameters
id:String

the attribute name.

Returns:Object

attribute value, or null if not set.

Annotations
@Override
getIdback to summary
public String getId()

Implements org.apache.http.conn.ManagedHttpClientConnection.getId.

Doc from org.apache.http.conn.ManagedHttpClientConnection.getId.

Returns connection ID which is expected to be unique for the life span of the connection manager.

Annotations
@Override
getSocketback to summary
public final Socket getSocket()

Overrides org.apache.http.impl.SocketHttpClientConnection.getSocket.

Implements org.apache.http.conn.OperatedClientConnection.getSocket, org.apache.http.conn.ManagedHttpClientConnection.getSocket.

Doc from org.apache.http.conn.OperatedClientConnection.getSocket.

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.

Returns:Socket

the socket for communicating with the target host

Annotations
@Override
getSSLSessionback to summary
public SSLSession getSSLSession()

Implements org.apache.http.conn.ManagedHttpClientConnection.getSSLSession.

Doc from org.apache.http.conn.ManagedHttpClientConnection.getSSLSession.

Obtains the SSL session of the underlying connection, if any. If this connection is open, and the underlying socket is an SSLSocket, the SSL session of that socket is obtained. This is a potentially blocking operation.

Returns:SSLSession

the underlying SSL session if available, null otherwise

Annotations
@Override
getTargetHostback to summary
public final HttpHost getTargetHost()

Implements org.apache.http.conn.OperatedClientConnection.getTargetHost.

Doc from org.apache.http.conn.OperatedClientConnection.getTargetHost.

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.

Returns:HttpHost

the host to which this connection is opened

Annotations
@Override
isSecureback to summary
public final boolean isSecure()

Implements org.apache.http.conn.OperatedClientConnection.isSecure.

Doc from org.apache.http.conn.OperatedClientConnection.isSecure.

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.

Returns:boolean

true if this connection is secure, false otherwise

Annotations
@Override
openCompletedback to summary
public void openCompleted(final boolean secure, final HttpParams params) throws IOException

Implements org.apache.http.conn.OperatedClientConnection.openCompleted.

Doc from org.apache.http.conn.OperatedClientConnection.openCompleted.

Deprecated

as a consequence of HttpParams being deprecated. See corresponding docs for further information.

Signals that the connection has been successfully open. An attempt to call this method on an open connection will cause an exception.

Parameters
secure:boolean

true if this connection is secure, for example if an SSLSocket is used, or false if it is not secure

params:HttpParams

parameters for this connection. The parameters will be used when creating dependent objects, for example to determine buffer sizes.

Annotations
@Override
openingback to summary
public void opening(final Socket sock, final HttpHost target) throws IOException

Implements org.apache.http.conn.OperatedClientConnection.opening.

Doc from org.apache.http.conn.OperatedClientConnection.opening.

Signals that this connection is in the process of being open.

By calling this method, the connection can be re-initialized with a new Socket instance before openCompleted 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 openCompleted in order to complete the process.

Parameters
sock:Socket

the unconnected socket which is about to be connected.

target:HttpHost

the target host of this connection

Annotations
@Override
receiveResponseHeaderback to summary
public HttpResponse receiveResponseHeader() throws HttpException, IOException

Overrides org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader.

Implements org.apache.http.HttpClientConnection.receiveResponseHeader.

Doc from org.apache.http.HttpClientConnection.receiveResponseHeader.

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.

Returns:HttpResponse

a new HttpResponse object with status line and headers initialized.

Annotations
@Override
Exceptions
HttpException:
in case of HTTP protocol violation
IOException:
in case of an I/O error
removeAttributeback to summary
public Object removeAttribute(final String id)

Implements org.apache.http.protocol.HttpContext.removeAttribute.

Doc from org.apache.http.protocol.HttpContext.removeAttribute.

Removes attribute with the given name from the context.

Parameters
id:String

the attribute name.

Returns:Object

attribute value, or null if not set.

Annotations
@Override
sendRequestHeaderback to summary
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException

Overrides org.apache.http.impl.AbstractHttpClientConnection.sendRequestHeader.

Implements org.apache.http.HttpClientConnection.sendRequestHeader.

Doc from org.apache.http.HttpClientConnection.sendRequestHeader.

Sends the request line and all headers over the connection.

Parameters
request:HttpRequest

the request whose headers to send.

Annotations
@Override
Exceptions
HttpException:
in case of HTTP protocol violation
IOException:
in case of an I/O error
setAttributeback to summary
public void setAttribute(final String id, final Object obj)

Implements org.apache.http.protocol.HttpContext.setAttribute.

Doc from org.apache.http.protocol.HttpContext.setAttribute.

Sets value of the attribute with the given name.

Parameters
id:String

the attribute name.

obj:Object

the attribute value.

Annotations
@Override
shutdownback to summary
public void shutdown() throws IOException

Overrides org.apache.http.impl.SocketHttpClientConnection.shutdown.

Implements org.apache.http.HttpConnection.shutdown.

Force-closes this connection. If the connection is still in the process of being open (the method 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.

Annotations
@Override
Exceptions
IOException:
in case of a problem
updateback to summary
public void update(final Socket sock, final HttpHost target, final boolean secure, final HttpParams params) throws IOException

Implements org.apache.http.conn.OperatedClientConnection.update.

Doc from org.apache.http.conn.OperatedClientConnection.update.

Deprecated

as a consequence of HttpParams being deprecated. See corresponding docs for further information.

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.

Parameters
sock:Socket

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:HttpHost

the new target host of this connection

secure:boolean

true if this connection is now secure, false if it is not secure

params:HttpParams

new parameters for this connection

Annotations
@Override