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

public abstract Class AbstractClientConnAdapter

extends Object
implements ManagedClientConnection, HttpContext
Class Inheritance
All Implemented Interfaces
org.apache.http.protocol.HttpContext, org.apache.http.conn.ManagedClientConnection, org.apache.http.conn.ConnectionReleaseTrigger, 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.HttpRoutedConnection
Known Direct Subclasses
org.apache.http.impl.conn.AbstractPooledConnAdapter
Annotations
@Deprecated
Imports
java.io.IOException, .InterruptedIOException, java.net.InetAddress, .Socket, java.util.concurrent.TimeUnit, javax.net.ssl.SSLSession, .SSLSocket, org.apache.http.HttpConnectionMetrics, .HttpEntityEnclosingRequest, .HttpException, .HttpRequest, .HttpResponse, org.apache.http.conn.ClientConnectionManager, .ManagedClientConnection, .OperatedClientConnection, org.apache.http.protocol.HttpContext

Deprecated

(4.2) do not use

Abstract adapter from operated to managed client connections. Read and write methods are delegated to the wrapped connection. Operations affecting the connection state have to be implemented by derived classes. Operations for querying the connection state are delegated to the wrapped connection if there is one, or return a default value if there is none.

This adapter tracks the checkpoints for reusable communication states, as indicated by markReusable and queried by isMarkedReusable. All send and receive operations will automatically clear the mark.

Connection release calls are delegated to the connection manager, if there is one. abortConnection will clear the reusability mark first. The connection manager is expected to tolerate multiple calls to the release method.

Since
4.0

Field Summary

Modifier and TypeField and Description
private final ClientConnectionManager
connManager

The connection manager.

private volatile long
duration

The duration this is valid for while idle (in ms).

private volatile boolean
markedReusable

The reusability marker.

private volatile boolean
released

True if the connection has been shut down or released.

private volatile OperatedClientConnection
wrappedConnection

The wrapped connection.

Constructor Summary

AccessConstructor and Description
protected
AbstractClientConnAdapter(final ClientConnectionManager
the connection manager, or null
mgr
,
final OperatedClientConnection
the connection to wrap, or null
conn
)

Deprecated as a consequence of ClientConnectionManager and OperatedClientConnection being deprecated.
Creates a new connection adapter.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
abortConnection()

Implements org.apache.http.conn.ConnectionReleaseTrigger.abortConnection.

Releases the connection without the option of keep-alive.
protected final void
protected final void
assertValid(final OperatedClientConnection wrappedConn)

Deprecated as a consequence of OperatedClientConnection being deprecated.
Asserts that there is a valid wrapped connection to delegate to.
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.
protected synchronized void
detach()

Detaches this adapter from the wrapped connection.

public void
flush()

Implements org.apache.http.HttpClientConnection.flush.

Writes out all pending buffered data over the open connection.
public Object
getAttribute(final String
the attribute name.
id
)

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

Obtains attribute with the given name.
public InetAddress
public int
protected ClientConnectionManager
getManager()

Deprecated as a consequence of ClientConnectionManager being deprecated.
public HttpConnectionMetrics
getMetrics()

Implements org.apache.http.HttpConnection.getMetrics.

Returns a collection of connection metrics.
public InetAddress
public int
public Socket
getSocket()

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

Returns the underlying socket.
public int
getSocketTimeout()

Implements org.apache.http.HttpConnection.getSocketTimeout.

Returns the socket timeout value.
public SSLSession
getSSLSession()

Implements org.apache.http.conn.ManagedClientConnection.getSSLSession.

Obtains the SSL session of the underlying connection, if any.
protected OperatedClientConnection
getWrappedConnection()

Deprecated as a consequence of OperatedClientConnection being deprecated.
public boolean
isMarkedReusable()

Implements org.apache.http.conn.ManagedClientConnection.isMarkedReusable.

Indicates whether this connection is in a reusable communication state.
public boolean
isOpen()

Implements org.apache.http.HttpConnection.isOpen.

Checks if this connection is open.
protected boolean

Returns:

value of released flag
isReleased
()

public boolean
isResponseAvailable(final int
the maximum time in milliseconds to wait for data
timeout
)

Implements org.apache.http.HttpClientConnection.isResponseAvailable.

Checks if response data is available from the connection.
public boolean
isSecure()

Implements org.apache.http.conn.ManagedClientConnection.isSecure.

Indicates whether this connection is secure.
public boolean
isStale()

Implements org.apache.http.HttpConnection.isStale.

Checks whether this connection has gone down.
public void
markReusable()

Implements org.apache.http.conn.ManagedClientConnection.markReusable.

Marks this connection as being in a reusable communication state.
public void
receiveResponseEntity(final HttpResponse
the response to attach the entity to
response
)

Implements org.apache.http.HttpClientConnection.receiveResponseEntity.

Receives the next response entity available from this connection and attaches it to an existing HttpResponse object.
public HttpResponse
receiveResponseHeader()

Implements org.apache.http.HttpClientConnection.receiveResponseHeader.

Receives the request line and headers of the next response available from this connection.
public synchronized void
releaseConnection()

Implements org.apache.http.conn.ConnectionReleaseTrigger.releaseConnection.

Releases the connection with the option of keep-alive.
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
sendRequestEntity(final HttpEntityEnclosingRequest
the request whose entity to send.
request
)

Implements org.apache.http.HttpClientConnection.sendRequestEntity.

Sends the request entity over the connection.
public void
sendRequestHeader(final HttpRequest
the request whose headers to send.
request
)

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
setIdleDuration(final long duration, final TimeUnit unit)

Implements org.apache.http.conn.ManagedClientConnection.setIdleDuration.

Sets the duration that this connection can remain idle before it is reused.
public void
setSocketTimeout(final int
timeout value in milliseconds
timeout
)

Implements org.apache.http.HttpConnection.setSocketTimeout.

Sets the socket timeout value.
public void
unmarkReusable()

Implements org.apache.http.conn.ManagedClientConnection.unmarkReusable.

Marks this connection as not being in a reusable state.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connManagerback to summary
private final ClientConnectionManager connManager

Deprecated

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

The connection manager.

durationback to summary
private volatile long duration

The duration this is valid for while idle (in ms).

markedReusableback to summary
private volatile boolean markedReusable

The reusability marker.

releasedback to summary
private volatile boolean released

True if the connection has been shut down or released.

wrappedConnectionback to summary
private volatile OperatedClientConnection wrappedConnection

Deprecated

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

The wrapped connection.

Constructor Detail

AbstractClientConnAdapterback to summary
protected AbstractClientConnAdapter(final ClientConnectionManager mgr, final OperatedClientConnection conn)

Deprecated

as a consequence of ClientConnectionManager and OperatedClientConnection being deprecated. See corresponding docs for further information.

Creates a new connection adapter. The adapter is initially not marked as reusable.

Parameters
mgr:ClientConnectionManager

the connection manager, or null

conn:OperatedClientConnection

the connection to wrap, or null

Method Detail

abortConnectionback to summary
public synchronized void abortConnection()

Implements org.apache.http.conn.ConnectionReleaseTrigger.abortConnection.

Doc from org.apache.http.conn.ConnectionReleaseTrigger.abortConnection.

Releases the connection without the option of keep-alive. This is a "hard" release that implies a shutdown of the connection. Use releaseConnection() for a graceful release.

Annotations
@Override
assertNotAbortedback to summary
protected final void assertNotAborted() throws InterruptedIOException
Annotations
@Deprecated
assertValidback to summary
protected final void assertValid(final OperatedClientConnection wrappedConn) throws ConnectionShutdownException

Deprecated

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

Asserts that there is a valid wrapped connection to delegate to.

Exceptions
ConnectionShutdownException:
if there is no wrapped connection or connection has been aborted
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
detachback to summary
protected synchronized void detach()

Detaches this adapter from the wrapped connection. This adapter becomes useless.

flushback to summary
public void flush() throws IOException

Implements org.apache.http.HttpClientConnection.flush.

Doc from org.apache.http.HttpClientConnection.flush.

Writes out all pending buffered data over the open connection.

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
getLocalAddressback to summary
public InetAddress getLocalAddress()

Implements org.apache.http.HttpInetConnection.getLocalAddress.

Annotations
@Override
getLocalPortback to summary
public int getLocalPort()

Implements org.apache.http.HttpInetConnection.getLocalPort.

Annotations
@Override
getManagerback to summary
protected ClientConnectionManager getManager()

Deprecated

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

getMetricsback to summary
public HttpConnectionMetrics getMetrics()

Implements org.apache.http.HttpConnection.getMetrics.

Doc from org.apache.http.HttpConnection.getMetrics.

Returns a collection of connection metrics.

Returns:HttpConnectionMetrics

HttpConnectionMetrics

Annotations
@Override
getRemoteAddressback to summary
public InetAddress getRemoteAddress()

Implements org.apache.http.HttpInetConnection.getRemoteAddress.

Annotations
@Override
getRemotePortback to summary
public int getRemotePort()

Implements org.apache.http.HttpInetConnection.getRemotePort.

Annotations
@Override
getSocketback to summary
public Socket getSocket()

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

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

Returns the underlying socket.

Annotations
@Override
getSocketTimeoutback to summary
public int getSocketTimeout()

Implements org.apache.http.HttpConnection.getSocketTimeout.

Doc from org.apache.http.HttpConnection.getSocketTimeout.

Returns the socket timeout value.

Returns:int

positive value in milliseconds if a timeout is set, 0 if timeout is disabled or -1 if timeout is undefined.

Annotations
@Override
getSSLSessionback to summary
public SSLSession getSSLSession()

Implements org.apache.http.conn.ManagedClientConnection.getSSLSession.

Doc from org.apache.http.conn.ManagedClientConnection.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.

Note

Whether the underlying socket is an SSL socket can not necessarily be determined via isSecure. Plain sockets may be considered secure, for example if they are connected to a known host in the same network segment. On the other hand, SSL sockets may be considered insecure, for example depending on the chosen cipher suite.

Returns:SSLSession

the underlying SSL session if available, null otherwise

Annotations
@Override
getWrappedConnectionback to summary
protected OperatedClientConnection getWrappedConnection()

Deprecated

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

isMarkedReusableback to summary
public boolean isMarkedReusable()

Implements org.apache.http.conn.ManagedClientConnection.isMarkedReusable.

Doc from org.apache.http.conn.ManagedClientConnection.isMarkedReusable.

Indicates whether this connection is in a reusable communication state. See markReusable and unmarkReusable for details.

Returns:boolean

true if this connection is marked as being in a reusable communication state, false otherwise

Annotations
@Override
isOpenback to summary
public boolean isOpen()

Implements org.apache.http.HttpConnection.isOpen.

Doc from org.apache.http.HttpConnection.isOpen.

Checks if this connection is open.

Returns:boolean

true if it is open, false if it is closed.

Annotations
@Override
isReleasedback to summary
protected boolean isReleased()
Returns:boolean

value of released flag

Since
4.1
isResponseAvailableback to summary
public boolean isResponseAvailable(final int timeout) throws IOException

Implements org.apache.http.HttpClientConnection.isResponseAvailable.

Doc from org.apache.http.HttpClientConnection.isResponseAvailable.

Checks if response data is available from the connection. May wait for the specified time until some data becomes available. Note that some implementations may completely ignore the timeout parameter.

Parameters
timeout:int

the maximum time in milliseconds to wait for data

Returns:boolean

true if data is available; false if there was no data available even after waiting for timeout milliseconds.

Annotations
@Override
Exceptions
IOException:
if an error happens on the connection
isSecureback to summary
public boolean isSecure()

Implements org.apache.http.conn.ManagedClientConnection.isSecure.

Doc from org.apache.http.conn.ManagedClientConnection.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.

Returns:boolean

true if this connection is secure, false otherwise

Annotations
@Override
isStaleback to summary
public boolean isStale()

Implements org.apache.http.HttpConnection.isStale.

Doc from org.apache.http.HttpConnection.isStale.

Checks whether this connection has gone down. Network connections may get closed during some time of inactivity for several reasons. The next time a read is attempted on such a connection it will throw an IOException. This method tries to alleviate this inconvenience by trying to find out if a connection is still usable. Implementations may do that by attempting a read with a very small timeout. Thus this method may block for a small amount of time before returning a result. It is therefore an expensive operation.

Returns:boolean

true if attempts to use this connection are likely to succeed, or false if they are likely to fail and this connection should be closed

Annotations
@Override
markReusableback to summary
public void markReusable()

Implements org.apache.http.conn.ManagedClientConnection.markReusable.

Doc from org.apache.http.conn.ManagedClientConnection.markReusable.

Marks this connection as being in a reusable communication state. The checkpoints for reuseable communication states (in the absence of pipelining) are before sending a request and after receiving the response in its entirety. The connection will automatically clear the checkpoint when used for communication. A call to this method indicates that the next checkpoint has been reached.

A reusable communication state is necessary but not sufficient for the connection to be reused. A route mismatch, the connection being closed, or other circumstances might prevent reuse.

Annotations
@Override
receiveResponseEntityback to summary
public void receiveResponseEntity(final HttpResponse response) throws HttpException, IOException

Implements org.apache.http.HttpClientConnection.receiveResponseEntity.

Doc from org.apache.http.HttpClientConnection.receiveResponseEntity.

Receives the next response entity available from this connection and attaches it to an existing HttpResponse object.

Parameters
response:HttpResponse

the response to attach the entity to

Annotations
@Override
Exceptions
HttpException:
in case of HTTP protocol violation
IOException:
in case of an I/O error
receiveResponseHeaderback to summary
public HttpResponse receiveResponseHeader() throws HttpException, IOException

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
releaseConnectionback to summary
public synchronized void releaseConnection()

Implements org.apache.http.conn.ConnectionReleaseTrigger.releaseConnection.

Doc from org.apache.http.conn.ConnectionReleaseTrigger.releaseConnection.

Releases the connection with the option of keep-alive. This is a "graceful" release and may cause IO operations for consuming the remainder of a response entity. Use abortConnection for a hard release. The connection may be reused as specified by the duration.

Annotations
@Override
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
sendRequestEntityback to summary
public void sendRequestEntity(final HttpEntityEnclosingRequest request) throws HttpException, IOException

Implements org.apache.http.HttpClientConnection.sendRequestEntity.

Doc from org.apache.http.HttpClientConnection.sendRequestEntity.

Sends the request entity over the connection.

Parameters
request:HttpEntityEnclosingRequest

the request whose entity to send.

Annotations
@Override
Exceptions
HttpException:
in case of HTTP protocol violation
IOException:
in case of an I/O error
sendRequestHeaderback to summary
public void sendRequestHeader(final HttpRequest request) throws HttpException, IOException

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
setIdleDurationback to summary
public void setIdleDuration(final long duration, final TimeUnit unit)

Implements org.apache.http.conn.ManagedClientConnection.setIdleDuration.

Doc from org.apache.http.conn.ManagedClientConnection.setIdleDuration.

Sets the duration that this connection can remain idle before it is reused. The connection should not be used again if this time elapses. The idle duration must be reset after each request sent over this connection. The elapsed time starts counting when the connection is released, which is typically after the headers (and any response body, if present) is fully consumed.

Annotations
@Override
setSocketTimeoutback to summary
public void setSocketTimeout(final int timeout)

Implements org.apache.http.HttpConnection.setSocketTimeout.

Doc from org.apache.http.HttpConnection.setSocketTimeout.

Sets the socket timeout value.

Parameters
timeout:int

timeout value in milliseconds

Annotations
@Override
unmarkReusableback to summary
public void unmarkReusable()

Implements org.apache.http.conn.ManagedClientConnection.unmarkReusable.

Doc from org.apache.http.conn.ManagedClientConnection.unmarkReusable.

Marks this connection as not being in a reusable state. This can be used immediately before releasing this connection to prevent its reuse. Reasons for preventing reuse include error conditions and the evaluation of a reuse strategy.

Note

It is not necessary to call here before writing to or reading from this connection. Communication attempts will automatically unmark the state as non-reusable. It can then be switched back using markReusable.

Annotations
@Override