org.restlet.engine.http.connector

## Class BaseClientHelper

- java.lang.Object
- - org.restlet.engine.Helper
  - - org.restlet.engine.RestletHelper<T>
    - - org.restlet.engine.ConnectorHelper<T>
      - - org.restlet.engine.http.connector.BaseHelper<Client>
        - - org.restlet.engine.http.connector.BaseClientHelper

Direct Known Subclasses:
  HttpClientHelper

    public class BaseClientHelper
    extends BaseHelper<Client>

Base client helper based on NIO blocking sockets. Here is the list of parameters that are supported. They should be set in the Client's context before it is started:

Parameter name | Value type | Default value | Description
--- | --- | --- | ---
proxyHost | String | System property "http.proxyHost" | The host name of the HTTP proxy.
proxyPort | int | System property "http.proxyPort" | The port of the HTTP proxy.
tcpNoDelay | boolean | false | Indicate if Nagle's TCP_NODELAY algorithm should be used.
keystorePath | String | ${user.home}/.keystore | SSL keystore path.
keystorePassword | String | System property "javax.net.ssl.keyStorePassword" | SSL keystore password.
keystoreType | String | JKS | SSL keystore type
keyPassword | String | System property "javax.net.ssl.keyStorePassword" | SSL key password.
certAlgorithm | String | SunX509 | SSL certificate algorithm.
secureRandomAlgorithm | String | null (see java.security.SecureRandom) | Name of the RNG algorithm. (see java.security.SecureRandom class).
securityProvider | String | null (see javax.net.ssl.SSLContext) | Java security provider name (see java.security.Provider class).
sslProtocol | String | TLS | SSL protocol.
truststoreType | String | System property "javax.net.ssl.trustStoreType" | Trust store type
truststorePath | String | null | Path to trust store
truststorePassword | String | System property "javax.net.ssl.trustStorePassword" | Trust store password

Author:
  Jerome Louvel

### Constructor Summary

Constructors
Constructor and Description
`BaseClientHelper(Client connector)` Constructor.

### Method Summary

Methods
`protected Connection<Client>` `createConnection(BaseHelper<Client> helper, java.net.Socket socket, java.nio.channels.SocketChannel socketChannel)` Creates a connection associated to the given socket.
`protected javax.net.SocketFactory` `createSecureSocketFactory()` Creates a properly configured secure socket factory.
`protected java.net.Socket` `createSocket(boolean secure, java.net.InetSocketAddress socketAddress)` Creates the socket that will be used to send the request and get the response.
`protected java.net.Socket` `createSocket(boolean secure, java.lang.String hostDomain, int hostPort)` Creates the socket that will be used to send the request and get the response.
`protected javax.net.SocketFactory` `createSocketFactory(boolean secure)` Creates a normal or secure socket factory.
`protected Connection<Client>` `getBestConnection(Request request)` Tries to reuse an existing connection for the given request, or creates a new one.
`java.lang.String` `getCertAlgorithm()` Returns the SSL certificate algorithm.
`int` `getConnectTimeout()` Returns the connection timeout.
`java.lang.String` `getKeyPassword()` Returns the SSL key password.
`java.lang.String` `getKeystorePassword()` Returns the SSL keystore password.
`java.lang.String` `getKeystorePath()` Returns the SSL keystore path.
`java.lang.String` `getKeystoreType()` Returns the SSL keystore type.
`java.lang.String` `getProxyHost()` Returns the host name of the HTTP proxy, if specified.
`int` `getProxyPort()` Returns the port of the HTTP proxy, if specified, 3128 otherwise.
`javax.net.SocketFactory` `getRegularSocketFactory()` Returns the regular socket factory.
`java.lang.String` `getSecureRandomAlgorithm()` Returns the name of the RNG algorithm.
`javax.net.SocketFactory` `getSecureSocketFactory()` Returns the secure socket factory.
`java.lang.String` `getSecurityProvider()` Returns the Java security provider name.
`protected java.net.InetSocketAddress` `getSocketAddress(Request request)` Returns an IP socket address representing the target host domain and port for a given request.
`javax.net.SocketFactory` `getSocketFactory(boolean secure)` Returns the socket factory.
`java.lang.String` `getSslProtocol()` Returns the SSL keystore type.
`boolean` `getTcpNoDelay()` Indicates if the protocol will use Nagle's algorithm
`java.lang.String` `getTruststorePassword()` Returns the SSL trust store password.
`java.lang.String` `getTruststorePath()` Returns the SSL trust store path.
`java.lang.String` `getTruststoreType()` Returns the SSL trust store type.
`void` `handle(Request request, Response response)` Handles a call.
`void` `handleInbound(Response response)` Handles an inbound message.
`void` `handleOutbound(Response response)` Handles an outbound message.
`boolean` `isProxying()` Indicates if the helper is going through a client proxy or is a server proxy.
`void` `setRegularSocketFactory(javax.net.SocketFactory regularSocketFactory)` Sets the regular socket factory.
`void` `setSecureSocketFactory(javax.net.SocketFactory secureSocketFactory)` Sets the secure socket factory.
`void` `start()` Start callback.
`void` `stop()` Stop callback.

### Methods inherited from class org.restlet.engine.http.connector.BaseHelper

`createController, createControllerService, createResponse, createWorkerService, getConnections, getController, getControllerSleepTimeMs, getInboundBufferSize, getInboundMessages, getMaxConnectionsPerHost, getMaxThreads, getMaxTotalConnections, getMinThreads, getOutboundBufferSize, getOutboundMessages, getThreadMaxIdleTimeMs, getWorkerService, handleNextInbound, handleNextOutbound, isClientSide, isControllerDaemon, isPersistingConnections, isPipeliningConnections, isServerSide, isTracing, isWorkerServiceFull`

### Methods inherited from class org.restlet.engine.ConnectorHelper

`getConnectorService, getContext, getProtocols, update`

### Methods inherited from class org.restlet.engine.RestletHelper

`getAttributes, getHelped, getHelpedParameters, getLogger, getMetadataService, setHelped`

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

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

### Constructor Detail

#### BaseClientHelper

    public BaseClientHelper(Client connector)

Constructor.

Parameters:
  `connector` - The helped client connector.

### Method Detail

#### createConnection

    protected Connection<Client> createConnection(BaseHelper<Client> helper,
                                      java.net.Socket socket,
                                      java.nio.channels.SocketChannel socketChannel)
                                           throws java.io.IOException

Description copied from class: `BaseHelper`
Creates a connection associated to the given socket.

Specified by:
  `createConnection` in class `BaseHelper<Client>`
Parameters:
  `helper` - The parent helper.
  `socket` - The underlying BIO socket.
  `socketChannel` - The underlying NIO socket channel.
Returns:
  The new connection.
Throws:
  `java.io.IOException`

#### createSecureSocketFactory

    protected javax.net.SocketFactory createSecureSocketFactory()
                                                         throws java.io.IOException,
                                                                java.security.GeneralSecurityException

Creates a properly configured secure socket factory.

Returns:
  Properly configured secure socket factory.
Throws:
  `java.io.IOException`
  `java.security.GeneralSecurityException`

#### createSocket

    protected java.net.Socket createSocket(boolean secure,
                               java.net.InetSocketAddress socketAddress)
                                    throws java.net.UnknownHostException,
                                           java.io.IOException

Creates the socket that will be used to send the request and get the response. This method is called by `getBestConnection(Request)` when a new connection is to be created. By default, calls the `createSocket(boolean, String, int)` method.

Parameters:
  `secure` - Indicates if messages will be exchanged confidentially, for example via a SSL-secured connection.
  `socketAddress` - The holder of a host/port pair.
Returns:
  The created socket.
Throws:
  `java.net.UnknownHostException`
  `java.io.IOException`

#### createSocket

    protected java.net.Socket createSocket(boolean secure,
                               java.lang.String hostDomain,
                               int hostPort)
                                    throws java.net.UnknownHostException,
                                           java.io.IOException

Creates the socket that will be used to send the request and get the response.

Parameters:
  `secure` - Indicates if messages will be exchanged confidentially, for example via a SSL-secured connection.
  `hostDomain` - The target host domain name.
  `hostPort` - The target host port.
Returns:
  The created socket.
Throws:
  `java.net.UnknownHostException`
  `java.io.IOException`

#### createSocketFactory

    protected javax.net.SocketFactory createSocketFactory(boolean secure)

Creates a normal or secure socket factory.

Parameters:
  `secure` - Indicates if the sockets should be secured.
Returns:
  A normal or secure socket factory.

#### getBestConnection

    protected Connection<Client> getBestConnection(Request request)
                                            throws java.net.UnknownHostException,
                                                   java.io.IOException

Tries to reuse an existing connection for the given request, or creates a new one. It may return null if the maximum number of connections per host or in general is reached.

Parameters:
  `request` - The request to handle.
Returns:
  An existing connection able to handle the request or new one.
Throws:
  `java.net.UnknownHostException`
  `java.io.IOException`

#### getCertAlgorithm

    public java.lang.String getCertAlgorithm()

Returns the SSL certificate algorithm.

Returns:
  The SSL certificate algorithm.

#### getConnectTimeout

    public int getConnectTimeout()

Returns the connection timeout.

Returns:
  The connection timeout.

#### getKeyPassword

    public java.lang.String getKeyPassword()

Returns the SSL key password.

Returns:
  The SSL key password.

#### getKeystorePassword

    public java.lang.String getKeystorePassword()

Returns the SSL keystore password.

Returns:
  The SSL keystore password.

#### getKeystorePath

    public java.lang.String getKeystorePath()

Returns the SSL keystore path.

Returns:
  The SSL keystore path.

#### getKeystoreType

    public java.lang.String getKeystoreType()

Returns the SSL keystore type.

Returns:
  The SSL keystore type.

#### getProxyHost

    public java.lang.String getProxyHost()

Returns the host name of the HTTP proxy, if specified.

Returns:
  the host name of the HTTP proxy, if specified.

#### getProxyPort

    public int getProxyPort()

Returns the port of the HTTP proxy, if specified, 3128 otherwise.

Returns:
  the port of the HTTP proxy.

#### getRegularSocketFactory

    public javax.net.SocketFactory getRegularSocketFactory()

Returns the regular socket factory.

Returns:
  The regular socket factory.

#### getSecureRandomAlgorithm

    public java.lang.String getSecureRandomAlgorithm()

Returns the name of the RNG algorithm.

Returns:
  The name of the RNG algorithm.

#### getSecureSocketFactory

    public javax.net.SocketFactory getSecureSocketFactory()

Returns the secure socket factory.

Returns:
  The secure socket factory.

#### getSecurityProvider

    public java.lang.String getSecurityProvider()

Returns the Java security provider name.

Returns:
  The Java security provider name.

#### getSocketAddress

    protected java.net.InetSocketAddress getSocketAddress(Request request)
                                                   throws java.net.UnknownHostException

Returns an IP socket address representing the target host domain and port for a given request. If the helper relies on a proxy, the socket represents the domain and port of the proxy host. Used by the `getBestConnection(Request)` method.

Parameters:
  `request` - The given request
Returns:
  The IP socket address representing the target host domain and port for a given request.
Throws:
  `java.net.UnknownHostException` - If the proxy port is invalid or the host unresolved.

#### getSocketFactory

    public javax.net.SocketFactory getSocketFactory(boolean secure)

Returns the socket factory.

Parameters:
  `secure` - Indicates if a factory for secure sockets is expected.
Returns:
  The socket factory.

#### getSslProtocol

    public java.lang.String getSslProtocol()

Returns the SSL keystore type.

Returns:
  The SSL keystore type.

#### getTcpNoDelay

    public boolean getTcpNoDelay()

Indicates if the protocol will use Nagle's algorithm

Returns:
  True to enable TCP_NODELAY, false to disable.
See Also:
  `Socket.setTcpNoDelay(boolean)`

#### getTruststorePassword

    public java.lang.String getTruststorePassword()

Returns the SSL trust store password.

Returns:
  The SSL trust store password.

#### getTruststorePath

    public java.lang.String getTruststorePath()

Returns the SSL trust store path.

Returns:
  The SSL trust store path.

#### getTruststoreType

    public java.lang.String getTruststoreType()

Returns the SSL trust store type.

Returns:
  The SSL trust store type.

#### handle

    public void handle(Request request,
              Response response)

Description copied from class: `RestletHelper`
Handles a call.

Overrides:
  `handle` in class `RestletHelper<Client>`
Parameters:
  `request` - The request to handle.
  `response` - The response to update.

#### handleInbound

    public void handleInbound(Response response)

Description copied from class: `BaseHelper`
Handles an inbound message.

Specified by:
  `handleInbound` in class `BaseHelper<Client>`
Parameters:
  `response` - The response to handle.

#### handleOutbound

    public void handleOutbound(Response response)

Description copied from class: `BaseHelper`
Handles an outbound message.

Specified by:
  `handleOutbound` in class `BaseHelper<Client>`
Parameters:
  `response` - The response to handle.

#### setRegularSocketFactory

    public void setRegularSocketFactory(javax.net.SocketFactory regularSocketFactory)

Sets the regular socket factory.

Parameters:
  `regularSocketFactory` - The regular socket factory.

#### setSecureSocketFactory

    public void setSecureSocketFactory(javax.net.SocketFactory secureSocketFactory)

Sets the secure socket factory.

Parameters:
  `secureSocketFactory` - The secure socket factory.

#### start

    public void start()
               throws java.lang.Exception

Description copied from class: `RestletHelper`
Start callback.

Overrides:
  `start` in class `BaseHelper<Client>`
Throws:
  `java.lang.Exception`

#### stop

    public void stop()
              throws java.lang.Exception

Description copied from class: `RestletHelper`
Stop callback.

Overrides:
  `stop` in class `BaseHelper<Client>`
Throws:
  `java.lang.Exception`

#### isProxying

    public boolean isProxying()

Description copied from class: `BaseHelper`
Indicates if the helper is going through a client proxy or is a server proxy.

Specified by:
  `isProxying` in class `BaseHelper<Client>`
Returns:
  True if the helper is going through a client proxy or is a server proxy.