## 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:
  Closeable, OperatedClientConnection, HttpClientConnection, HttpConnection, HttpInetConnection, HttpContext

    @NotThreadSafe
    public class DefaultClientConnection

extends SocketHttpClientConnection
implements OperatedClientConnection, HttpContext

Default implementation of an operated client connection.

The following parameters can be used to customize the behavior of this class:

- `CoreProtocolPNames.STRICT_TRANSFER_ENCODING`
- `CoreProtocolPNames.HTTP_ELEMENT_CHARSET`
- `CoreConnectionPNames.SOCKET_BUFFER_SIZE`
- `CoreConnectionPNames.MAX_LINE_LENGTH`
- `CoreConnectionPNames.MAX_HEADER_COUNT`

Since:
  4.0

Field Summary

Fields inherited from interface org.apache.http.protocol.HttpContext
`RESERVED_PREFIX`

Constructor Summary
`DefaultClientConnection()`

Method Summary
`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.

Methods inherited from class org.apache.http.impl.SocketHttpClientConnection
`assertNotOpen, assertOpen, bind, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSocketTimeout, isOpen, setSocketTimeout, toString`

Methods inherited from class org.apache.http.impl.AbstractHttpClientConnection
`createConnectionMetrics, createEntityDeserializer, createEntitySerializer, createHttpResponseFactory, createRequestWriter, doFlush, flush, getMetrics, init, isEof, isResponseAvailable, isStale, receiveResponseEntity, sendRequestEntity`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.apache.http.HttpClientConnection
`flush, isResponseAvailable, receiveResponseEntity, sendRequestEntity`

Methods inherited from interface org.apache.http.HttpConnection
`getMetrics, getSocketTimeout, isOpen, isStale, setSocketTimeout`

Methods inherited from interface org.apache.http.HttpInetConnection
`getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort`

Methods inherited from interface org.apache.http.HttpConnection
`getMetrics, getSocketTimeout, isOpen, isStale, setSocketTimeout`

Constructor Detail

### DefaultClientConnection

    public DefaultClientConnection()

Method Detail

### getTargetHost

    public final HttpHost getTargetHost()

  Description copied from interface: `OperatedClientConnection`
  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`.

  Specified by:
    `getTargetHost` in interface `OperatedClientConnection`
  Returns:
    the host to which this connection is opened

### isSecure

    public final boolean isSecure()

  Description copied from interface: `OperatedClientConnection`
  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`.

  Specified by:
    `isSecure` in interface `OperatedClientConnection`
  Returns:
    `true` if this connection is secure, `false` otherwise

### getSocket

    public final Socket getSocket()

  Description copied from interface: `OperatedClientConnection`
  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`.

  Specified by:
    `getSocket` in interface `OperatedClientConnection`
  Overrides:
    `getSocket` in class `SocketHttpClientConnection`
  Returns:
    the socket for communicating with the `target host`

### opening

    public void opening(Socket sock,
                        HttpHost target)
                 throws IOException

  Description copied from interface: `OperatedClientConnection`
  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 `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.

  Specified by:
    `opening` in interface `OperatedClientConnection`
  Parameters:
    `sock` - the unconnected socket which is about to be connected.
    `target` - the target host of this connection
  Throws:
    `IOException`

### openCompleted

    public void openCompleted(boolean secure,
                              HttpParams params)
                       throws IOException

  Description copied from interface: `OperatedClientConnection`
  Signals that the connection has been successfully open. An attempt to call this method on an open connection will cause an exception.

  Specified by:
    `openCompleted` in interface `OperatedClientConnection`
  Parameters:
    `secure` - `true` if this connection is secure, for example if an `SSLSocket` is used, or `false` if it is not secure
    `params` - parameters for this connection. The parameters will be used when creating dependent objects, for example to determine buffer sizes.
  Throws:
    `IOException`

### shutdown

    public void shutdown()
                  throws IOException

  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.

  Specified by:
    `shutdown` in interface `HttpConnection`
  Overrides:
    `shutdown` in class `SocketHttpClientConnection`
  Throws:
    `IOException` - in case of a problem

### close

    public void close()
               throws IOException

  Specified by:
    `close` in interface `Closeable`
  Specified by:
    `close` in interface `HttpConnection`
  Overrides:
    `close` in class `SocketHttpClientConnection`
  Throws:
    `IOException`

### createSessionInputBuffer

    protected SessionInputBuffer createSessionInputBuffer(Socket socket,
                                                          int buffersize,
                                                          HttpParams params)
                                                   throws IOException

  Overrides:
    `createSessionInputBuffer` in class `SocketHttpClientConnection`
  Throws:
    `IOException`

### createSessionOutputBuffer

    protected SessionOutputBuffer createSessionOutputBuffer(Socket socket,
                                                            int buffersize,
                                                            HttpParams params)
                                                     throws IOException

  Overrides:
    `createSessionOutputBuffer` in class `SocketHttpClientConnection`
  Throws:
    `IOException`

### createResponseParser

    protected HttpMessageParser<HttpResponse> createResponseParser(SessionInputBuffer buffer,
                                                                   HttpResponseFactory responseFactory,
                                                                   HttpParams params)

  Overrides:
    `createResponseParser` in class `AbstractHttpClientConnection`

### update

    public void update(Socket sock,
                       HttpHost target,
                       boolean secure,
                       HttpParams params)
                throws IOException

  Description copied from interface: `OperatedClientConnection`
  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.

  Specified by:
    `update` in interface `OperatedClientConnection`
  Parameters:
    `sock` - 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 connection
    `secure` - `true` if this connection is now secure, `false` if it is not secure
    `params` - new parameters for this connection
  Throws:
    `IOException`

### receiveResponseHeader

    public HttpResponse receiveResponseHeader()
                                       throws HttpException,
                                              IOException

  Specified by:
    `receiveResponseHeader` in interface `HttpClientConnection`
  Overrides:
    `receiveResponseHeader` in class `AbstractHttpClientConnection`
  Throws:
    `HttpException`
    `IOException`

### sendRequestHeader

    public void sendRequestHeader(HttpRequest request)
                           throws HttpException,
                                  IOException

  Specified by:
    `sendRequestHeader` in interface `HttpClientConnection`
  Overrides:
    `sendRequestHeader` in class `AbstractHttpClientConnection`
  Throws:
    `HttpException`
    `IOException`

### getAttribute

    public Object getAttribute(String id)

  Specified by:
    `getAttribute` in interface `HttpContext`

### removeAttribute

    public Object removeAttribute(String id)

  Specified by:
    `removeAttribute` in interface `HttpContext`

### setAttribute

    public void setAttribute(String id,
                             Object obj)

  Specified by:
    `setAttribute` in interface `HttpContext`

Copyright © 1999-2013 The Apache Software Foundation. All Rights Reserved.