Package org.apache.synapse.transport.nhttp

## Class ClientHandler

- java.lang.Object
- - org.apache.synapse.transport.nhttp.ClientHandler

- All Implemented Interfaces:
    `org.apache.http.nio.NHttpClientEventHandler`

      public class ClientHandler
      extends Object
      implements org.apache.http.nio.NHttpClientEventHandler

  The client connection handler. An instance of this class is used by each IOReactor, to process every connection. Hence this class should not store any data related to a single connection - as this is being shared.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static String` | `ATTACHMENT_KEY` |
    `static String` | `AXIS2_HTTP_REQUEST` |
    `static String` | `CLIENT_CONNECTION_DEBUG` |
    `static String` | `CONNECTION_CREATION_TIME` |
    `static String` | `OUTGOING_MESSAGE_CONTEXT` |
    `static String` | `REQUEST_SOURCE_BUFFER` |
    `static String` | `RESPONSE_SINK_BUFFER` |
    `static String` | `TUNNEL_HANDLER` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ClientHandler​(ConnectionPool connpool, ClientConnFactory connFactory, ProxyConfig proxyConfig, org.apache.axis2.context.ConfigurationContext cfgCtx, org.apache.http.params.HttpParams params, NhttpMetricsCollector metrics)` | Create an instance of this client connection handler using the Axis2 configuration context and Http protocol parameters given

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `closed​(org.apache.http.nio.NHttpClientConnection conn)` | Handle connection close events
    `void` | `connected​(org.apache.http.nio.NHttpClientConnection conn, Object attachment)` | Invoked when the destination is connected
    `void` | `endOfInput​(org.apache.http.nio.NHttpClientConnection conn)` |
    `void` | `exception​(org.apache.http.nio.NHttpClientConnection conn, Exception ex)` | Handle IO errors while reading or writing to underlying channels
    `void` | `exception​(org.apache.http.nio.NHttpClientConnection conn, org.apache.http.HttpException e)` | Handle Http protocol violations encountered while reading from underlying channels
    `void` | `execute​(Runnable task)` |
    `int` | `getActiveCount()` |
    `int` | `getQueueSize()` |
    `void` | `inputReady​(org.apache.http.nio.NHttpClientConnection conn, org.apache.http.nio.ContentDecoder decoder)` | Process ready input (i.e.
    `protected void` | `markRequestCompletedWithError​(Axis2HttpRequest axis2Request, int errorCode, String errorMessage, Exception exceptionToRaise)` | Mark request to send failed with error
    `void` | `outputReady​(org.apache.http.nio.NHttpClientConnection conn, org.apache.http.nio.ContentEncoder encoder)` | Process ready output (i.e.
    `void` | `requestReady​(org.apache.http.nio.NHttpClientConnection conn)` |
    `void` | `resetConnectionPool​(Set<RequestDescriptor> hostList)` | Shutdown the connections of the given host:port list.
    `void` | `responseReceived​(org.apache.http.nio.NHttpClientConnection conn)` | Process a response received for the request sent out
    `void` | `setConnFactory​(ClientConnFactory connFactory)` | Set the given Client Connection Factory.
    `void` | `stop()` |
    `void` | `submitRequest​(org.apache.http.nio.NHttpClientConnection conn, Axis2HttpRequest axis2Req)` | Submit a new request over an already established connection, which has been 'kept alive'
    `void` | `timeout​(org.apache.http.nio.NHttpClientConnection conn)` | Handle connection timeouts by shutting down the connections.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ATTACHMENT_KEY

          public static final String ATTACHMENT_KEY

      See Also:
        Constant Field Values

    - #### TUNNEL_HANDLER

          public static final String TUNNEL_HANDLER

      See Also:
        Constant Field Values

    - #### OUTGOING_MESSAGE_CONTEXT

          public static final String OUTGOING_MESSAGE_CONTEXT

      See Also:
        Constant Field Values

    - #### AXIS2_HTTP_REQUEST

          public static final String AXIS2_HTTP_REQUEST

      See Also:
        Constant Field Values

    - #### CLIENT_CONNECTION_DEBUG

          public static final String CLIENT_CONNECTION_DEBUG

      See Also:
        Constant Field Values

    - #### CONNECTION_CREATION_TIME

          public static final String CONNECTION_CREATION_TIME

      See Also:
        Constant Field Values

    - #### REQUEST_SOURCE_BUFFER

          public static final String REQUEST_SOURCE_BUFFER

      See Also:
        Constant Field Values

    - #### RESPONSE_SINK_BUFFER

          public static final String RESPONSE_SINK_BUFFER

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ClientHandler

          public ClientHandler​(ConnectionPool connpool,
                               ClientConnFactory connFactory,
                               ProxyConfig proxyConfig,
                               org.apache.axis2.context.ConfigurationContext cfgCtx,
                               org.apache.http.params.HttpParams params,
                               NhttpMetricsCollector metrics)
                        throws org.apache.axis2.AxisFault

      Create an instance of this client connection handler using the Axis2 configuration context and Http protocol parameters given
      Parameters:
        `cfgCtx` - the Axis2 configuration context
        `params` - the Http protocol parameters to adhere to
        `metrics` - statistics collection metrics
      Throws:
        `org.apache.axis2.AxisFault`

  - ### Method Detail

    - #### requestReady

          public void requestReady​(org.apache.http.nio.NHttpClientConnection conn)
                            throws IOException,
                                   org.apache.http.HttpException

      Specified by:
        `requestReady` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Throws:
        `IOException`
        `org.apache.http.HttpException`

    - #### submitRequest

          public void submitRequest​(org.apache.http.nio.NHttpClientConnection conn,
                                    Axis2HttpRequest axis2Req)
                             throws org.apache.http.ConnectionClosedException

      Submit a new request over an already established connection, which has been 'kept alive'
      Parameters:
        `conn` - the connection to use to send the request, which has been kept open
        `axis2Req` - the new request
      Throws:
        `org.apache.http.ConnectionClosedException` - if the connection is closed by the other party

    - #### connected

          public void connected​(org.apache.http.nio.NHttpClientConnection conn,
                                Object attachment)

      Invoked when the destination is connected
      Specified by:
        `connected` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Parameters:
        `conn` - the connection being processed
        `attachment` - the attachment set previously

    - #### closed

          public void closed​(org.apache.http.nio.NHttpClientConnection conn)

      Handle connection close events
      Specified by:
        `closed` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Parameters:
        `conn` - HTTP connection to be closed

    - #### timeout

          public void timeout​(org.apache.http.nio.NHttpClientConnection conn)

      Handle connection timeouts by shutting down the connections. These are established that have reached the SO_TIMEOUT of the socket
      Specified by:
        `timeout` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Parameters:
        `conn` - the connection being processed

    - #### exception

          public void exception​(org.apache.http.nio.NHttpClientConnection conn,
                                org.apache.http.HttpException e)

      Handle Http protocol violations encountered while reading from underlying channels
      Parameters:
        `conn` - the connection being processed
        `e` - the exception encountered

    - #### exception

          public void exception​(org.apache.http.nio.NHttpClientConnection conn,
                                Exception ex)

      Handle IO errors while reading or writing to underlying channels
      Specified by:
        `exception` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Parameters:
        `conn` - the connection being processed
        `ex` - the exception encountered

    - #### endOfInput

          public void endOfInput​(org.apache.http.nio.NHttpClientConnection conn)
                          throws IOException

      Specified by:
        `endOfInput` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Throws:
        `IOException`

    - #### markRequestCompletedWithError

          protected void markRequestCompletedWithError​(Axis2HttpRequest axis2Request,
                                                       int errorCode,
                                                       String errorMessage,
                                                       Exception exceptionToRaise)

      Mark request to send failed with error
      Parameters:
        `axis2Request` - the Axis2HttpRequest to be marked as completed with an error
        `errorCode` - the error code to raise
        `errorMessage` - the text for an error message to be returned to the MR on failure
        `exceptionToRaise` - an Exception to be returned to the MR on failure

    - #### inputReady

          public void inputReady​(org.apache.http.nio.NHttpClientConnection conn,
                                 org.apache.http.nio.ContentDecoder decoder)

      Process ready input (i.e. response from remote server)
      Specified by:
        `inputReady` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Parameters:
        `conn` - connection being processed
        `decoder` - the content decoder in use

    - #### outputReady

          public void outputReady​(org.apache.http.nio.NHttpClientConnection conn,
                                  org.apache.http.nio.ContentEncoder encoder)

      Process ready output (i.e. write request to remote server)
      Specified by:
        `outputReady` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Parameters:
        `conn` - the connection being processed
        `encoder` - the encoder in use

    - #### responseReceived

          public void responseReceived​(org.apache.http.nio.NHttpClientConnection conn)

      Process a response received for the request sent out
      Specified by:
        `responseReceived` in interface `org.apache.http.nio.NHttpClientEventHandler`
      Parameters:
        `conn` - the connection being processed

    - #### execute

          public void execute​(Runnable task)

    - #### getActiveCount

          public int getActiveCount()

    - #### getQueueSize

          public int getQueueSize()

    - #### stop

          public void stop()

    - #### setConnFactory

          public void setConnFactory​(ClientConnFactory connFactory)

      Set the given Client Connection Factory.
      Parameters:
        `connFactory` - ClientConnectionFactory instance

    - #### resetConnectionPool

          public void resetConnectionPool​(Set<RequestDescriptor> hostList)

      Shutdown the connections of the given host:port list. This will allow to create new connection at the next request happens.
      Parameters:
        `hostList` - Set of String which contains entries in hots:port format