org.restlet.engine.http.connector
Class BaseClientHelper

java.lang.Object
  extended by org.restlet.engine.Helper
      extended by org.restlet.engine.RestletHelper<T>
          extended by org.restlet.engine.ConnectorHelper<T>
              extended by org.restlet.engine.http.connector.BaseHelper<Client>
                  extended by 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
BaseClientHelper(Client connector)
          Constructor.
 
Method Summary
protected  Connection<Client> createConnection(BaseHelper<Client> helper, Socket socket, SocketChannel socketChannel)
          Creates a connection associated to the given socket.
protected  SocketFactory createSecureSocketFactory()
          Creates a properly configured secure socket factory.
protected  Socket createSocket(boolean secure, InetSocketAddress socketAddress)
          Creates the socket that will be used to send the request and get the response.
protected  Socket createSocket(boolean secure, String hostDomain, int hostPort)
          Creates the socket that will be used to send the request and get the response.
protected  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.
 String getCertAlgorithm()
          Returns the SSL certificate algorithm.
 int getConnectTimeout()
          Returns the connection timeout.
 String getKeyPassword()
          Returns the SSL key password.
 String getKeystorePassword()
          Returns the SSL keystore password.
 String getKeystorePath()
          Returns the SSL keystore path.
 String getKeystoreType()
          Returns the SSL keystore type.
 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.
 SocketFactory getRegularSocketFactory()
          Returns the regular socket factory.
 String getSecureRandomAlgorithm()
          Returns the name of the RNG algorithm.
 SocketFactory getSecureSocketFactory()
          Returns the secure socket factory.
 String getSecurityProvider()
          Returns the Java security provider name.
protected  InetSocketAddress getSocketAddress(Request request)
          Returns an IP socket address representing the target host domain and port for a given request.
 SocketFactory getSocketFactory(boolean secure)
          Returns the socket factory.
 String getSslProtocol()
          Returns the SSL keystore type.
 boolean getTcpNoDelay()
          Indicates if the protocol will use Nagle's algorithm
 String getTruststorePassword()
          Returns the SSL trust store password.
 String getTruststorePath()
          Returns the SSL trust store path.
 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(SocketFactory regularSocketFactory)
          Sets the regular socket factory.
 void setSecureSocketFactory(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,
                                              Socket socket,
                                              SocketChannel socketChannel)
                                       throws 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:
IOException

createSecureSocketFactory

protected SocketFactory createSecureSocketFactory()
                                           throws IOException,
                                                  GeneralSecurityException
Creates a properly configured secure socket factory.

Returns:
Properly configured secure socket factory.
Throws:
IOException
GeneralSecurityException

createSocket

protected Socket createSocket(boolean secure,
                              InetSocketAddress socketAddress)
                       throws UnknownHostException,
                              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:
UnknownHostException
IOException

createSocket

protected Socket createSocket(boolean secure,
                              String hostDomain,
                              int hostPort)
                       throws UnknownHostException,
                              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:
UnknownHostException
IOException

createSocketFactory

protected 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 UnknownHostException,
                                               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:
UnknownHostException
IOException

getCertAlgorithm

public 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 String getKeyPassword()
Returns the SSL key password.

Returns:
The SSL key password.

getKeystorePassword

public String getKeystorePassword()
Returns the SSL keystore password.

Returns:
The SSL keystore password.

getKeystorePath

public String getKeystorePath()
Returns the SSL keystore path.

Returns:
The SSL keystore path.

getKeystoreType

public String getKeystoreType()
Returns the SSL keystore type.

Returns:
The SSL keystore type.

getProxyHost

public 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 SocketFactory getRegularSocketFactory()
Returns the regular socket factory.

Returns:
The regular socket factory.

getSecureRandomAlgorithm

public String getSecureRandomAlgorithm()
Returns the name of the RNG algorithm.

Returns:
The name of the RNG algorithm.

getSecureSocketFactory

public SocketFactory getSecureSocketFactory()
Returns the secure socket factory.

Returns:
The secure socket factory.

getSecurityProvider

public String getSecurityProvider()
Returns the Java security provider name.

Returns:
The Java security provider name.

getSocketAddress

protected InetSocketAddress getSocketAddress(Request request)
                                      throws 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:
UnknownHostException - If the proxy port is invalid or the host unresolved.

getSocketFactory

public 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 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 String getTruststorePassword()
Returns the SSL trust store password.

Returns:
The SSL trust store password.

getTruststorePath

public String getTruststorePath()
Returns the SSL trust store path.

Returns:
The SSL trust store path.

getTruststoreType

public 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(SocketFactory regularSocketFactory)
Sets the regular socket factory.

Parameters:
regularSocketFactory - The regular socket factory.

setSecureSocketFactory

public void setSecureSocketFactory(SocketFactory secureSocketFactory)
Sets the secure socket factory.

Parameters:
secureSocketFactory - The secure socket factory.

start

public void start()
           throws Exception
Description copied from class: RestletHelper
Start callback.

Overrides:
start in class BaseHelper<Client>
Throws:
Exception

stop

public void stop()
          throws Exception
Description copied from class: RestletHelper
Stop callback.

Overrides:
stop in class BaseHelper<Client>
Throws:
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.


Copyright © 2005-2011 Noelios Technologies.