Package com.opencloud.slee.remote
Class RhinoConnectionFactory
- java.lang.Object
-
- com.opencloud.slee.remote.RhinoConnectionFactory
-
public class RhinoConnectionFactory extends Object
Factory class to create connections to Rhino.
-
-
Field Summary
Fields Modifier and Type Field Description static StringRHINO_HOST_ATTRIBUTEstatic StringRHINO_KEYSTORE_ATTRIBUTEstatic StringRHINO_KEYSTOREPASS_ATTRIBUTEstatic StringRHINO_PASSWORD_ATTRIBUTEstatic StringRHINO_PASSWORD_ENVstatic StringRHINO_PORT_ATTRIBUTEstatic StringRHINO_SERVERLIST_ATTRIBUTEstatic StringRHINO_TRUSTSTORE_ATTRIBUTEstatic StringRHINO_TRUSTSTOREPASS_ATTRIBUTEstatic StringRHINO_USERNAME_ATTRIBUTE
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static RhinoConnectionconnect(File propertiesFile)Create a Rhino client using connection properties in the given properties file.static RhinoConnectionconnect(String[] servers, String username, String password)Create a Rhino client that will attempt connections to the given servers in the order specified, and authenticate using the given username and password.static RhinoConnectionconnect(String[] servers, String username, String password, Properties sslProps)Deprecated.Initialise SSL properties by callingsetRhinoSslProperties(java.util.Properties)(only once) then use connect methods on this class that do not take SSL properties as an argument.static RhinoConnectionconnect(String host, int port, String username, String password)Create a Rhino client that will connect to the given host and port, and authenticate using the given username and password.static RhinoConnectionconnect(String host, int port, String username, String password, Properties sslProps)Deprecated.Initialise SSL properties by callingsetRhinoSslProperties(java.util.Properties)(only once) then use connect methods on this class that do not take SSL properties as an argument.static RhinoConnectionconnect(String serverList, String username, String password)Create a Rhino client that will attempt connections to the given hosts and ports in the order specified, and authenticate using the given username and password.static RhinoConnectionconnect(Properties properties)Create a Rhino client using connection properties in the given properties object.static PrintWritergetLogWriter()Retrieves the log writer.static StringgetPassword(Properties props)Try to obtain the user password.static voidrecreateSslContext()Force the SSL context and client socket factory to be recreated.static voidsetLogWriter(PrintWriter out)Sets the logging/tracing PrintWriter object that is used by the RhinoConnectionFactory and all connections.static voidsetRhinoSslProperties(Properties sslProps)Set the SSL properties.static voidsetRhinoSslProperties(Properties sslProps, boolean useJavaxSslProperties)Set the SSL properties.
-
-
-
Field Detail
-
RHINO_HOST_ATTRIBUTE
public static final String RHINO_HOST_ATTRIBUTE
- See Also:
- Constant Field Values
-
RHINO_PORT_ATTRIBUTE
public static final String RHINO_PORT_ATTRIBUTE
- See Also:
- Constant Field Values
-
RHINO_SERVERLIST_ATTRIBUTE
public static final String RHINO_SERVERLIST_ATTRIBUTE
- See Also:
- Constant Field Values
-
RHINO_USERNAME_ATTRIBUTE
public static final String RHINO_USERNAME_ATTRIBUTE
- See Also:
- Constant Field Values
-
RHINO_PASSWORD_ATTRIBUTE
public static final String RHINO_PASSWORD_ATTRIBUTE
- See Also:
- Constant Field Values
-
RHINO_PASSWORD_ENV
public static final String RHINO_PASSWORD_ENV
- See Also:
- Constant Field Values
-
RHINO_TRUSTSTORE_ATTRIBUTE
public static final String RHINO_TRUSTSTORE_ATTRIBUTE
- See Also:
- Constant Field Values
-
RHINO_TRUSTSTOREPASS_ATTRIBUTE
public static final String RHINO_TRUSTSTOREPASS_ATTRIBUTE
- See Also:
- Constant Field Values
-
RHINO_KEYSTORE_ATTRIBUTE
public static final String RHINO_KEYSTORE_ATTRIBUTE
- See Also:
- Constant Field Values
-
RHINO_KEYSTOREPASS_ATTRIBUTE
public static final String RHINO_KEYSTOREPASS_ATTRIBUTE
- See Also:
- Constant Field Values
-
-
Method Detail
-
setLogWriter
public static void setLogWriter(PrintWriter out)
Sets the logging/tracing PrintWriter object that is used by the RhinoConnectionFactory and all connections. To log debugging information to standard out, use the following: [source,java] ---- RhinoConnectionFactory.setLogWriter(new PrintWriter(System.out, true)); ---- *Note the second parameter to the PrintWriter constructor (`true`) -- if this is not supplied, no output will be displayed until the PrintWriter's buffer is full, which is generally not the desired behaviour.* To log to a Log4J logger, you could do this: [source,java] ---- class LogWriter extends Writer { public void write(char[] cbuf, int off, int len) { String s = new String(cbuf, off, len); if(!lineSep.equals(s)) log.info(s); } public void flush() { } public void close() { } private final String lineSep = System.getProperty("line.separator"); } RhinoConnectionFactory.setLogWriter(new PrintWriter(new LogWriter())); ----- Parameters:
out- the new logging/tracing PrintWriter object; null to disable logging and tracing
-
getLogWriter
public static PrintWriter getLogWriter()
Retrieves the log writer.- Returns:
- a java.io.PrintWriter object
-
getPassword
public static String getPassword(Properties props)
Try to obtain the user password. The password is first looked for in the provided properties object using the keyRHINO_PASSWORD_ATTRIBUTE. If no password is found there, then theRHINO_PASSWORD_ENVenvironment variable is checked. If a password is found in the environment variable, it is added to the properties object with the same key as above.- Parameters:
props- connection properties to check.- Returns:
- a password string if found, otherwise `null`.
-
setRhinoSslProperties
public static void setRhinoSslProperties(Properties sslProps) throws IllegalArgumentException
Set the SSL properties. The values will be used by theRhinoSslRMIClientSocketFactoryto create a custom TrustManagerFactory and KeyManagerFactory which support reloadable keystores. *Note:* This feature will only work when connecting to Rhino 2.2 or later. If connecting to an earlier version of Rhino, you must useRhinoSsl.checkSslProperties(java.util.Properties)instead, and note that keystore files will only be read once. Both SSL mechanisms can be used simultaneously: connections to Rhino 2.2+ nodes will use these settings, and connections to older Rhino instances will use the settings provided toRhinoSsl.checkSslProperties(java.util.Properties).- Parameters:
sslProps- a properties object containing properties with names of the String constant valuesRHINO_TRUSTSTORE_ATTRIBUTE,RHINO_TRUSTSTOREPASS_ATTRIBUTE,RHINO_KEYSTORE_ATTRIBUTEandRHINO_KEYSTOREPASS_ATTRIBUTE.- Throws:
IllegalArgumentException- Since:
- 2.2 @see com.opencloud.slee.remote.RhinoConnectionFactory#setRhinoSslProperties(java.util.Properties, boolean)
-
setRhinoSslProperties
public static void setRhinoSslProperties(Properties sslProps, boolean useJavaxSslProperties) throws IllegalArgumentException
Set the SSL properties. The values will be used by theRhinoSslRMIClientSocketFactoryto create a custom TrustManagerFactory and KeyManagerFactory which support reloadable keystores. *Note:* This feature will only work when connecting to Rhino 2.2 or later. If connecting to an earlier version of Rhino, you must useRhinoSsl.checkSslProperties(java.util.Properties)instead, and note that keystore files will only be read once. Both SSL mechanisms can be used simultaneously: connections to Rhino 2.2+ nodes will use these settings, and connections to older Rhino instances will use the settings provided toRhinoSsl.checkSslProperties(java.util.Properties). *Note:* The useJavaxSslProperties flag affects which properties are used.- Parameters:
sslProps- A properties object containing the SSL properties to use. When the boolean useJavaxSslProperties is true, this method uses properties with names of the String constant valuesRhinoSsl.JAVAXSSL_TRUSTSTORE_ATTRIBUTE,RhinoSsl.JAVAXSSL_TRUSTSTOREPASS_ATTRIBUTE,RhinoSsl.JAVAXSSL_KEYSTORE_ATTRIBUTEandRhinoSsl.JAVAXSSL_KEYSTOREPASS_ATTRIBUTE. This is useful when reading SSL properties from a Rhino client.properties file. When useJavaxSslProperties is false, it uses properties with names of the String constant valuesRHINO_TRUSTSTORE_ATTRIBUTE,RHINO_TRUSTSTOREPASS_ATTRIBUTE,RHINO_KEYSTORE_ATTRIBUTEandRHINO_KEYSTOREPASS_ATTRIBUTE.useJavaxSslProperties- Controls which properties in sslProps are read from (see sslProps above).- Throws:
IllegalArgumentException- Since:
- 2.4 @see com.opencloud.slee.remote.RhinoConnectionFactory#setRhinoSslProperties(java.util.Properties)
-
connect
public static RhinoConnection connect(File propertiesFile) throws ConnectionException
Create a Rhino client using connection properties in the given properties file. The names of the properties are defined by the link:../../../../constant-values.html#com.opencloud.slee.remote.RhinoConnectionFactory.RHINO_HOST_ATTRIBUTE[constant field values] of this class. If both a server list and a host/port are in the properties, the server list takes precedence. If the target Rhino server requires SSL, the properties file must contain SSL properties if they have not been set as system properties prior to calling this method. The names of the SSL properties are defined by the link:../../../../constant-values.html#com.opencloud.slee.remote.RhinoSsl.JAVAXSSL_KEYSTORE_ATTRIBUTE[constant field values] in theRhinoSslclass.- Parameters:
propertiesFile- a file containing server address properties, authentication credential properties, and SSL properties (if not set as system properties)- Returns:
- a RhinoConnection instance
- Throws:
ConnectionException- if none of the provided servers could be reached
-
connect
public static RhinoConnection connect(Properties properties) throws ConnectionException
Create a Rhino client using connection properties in the given properties object. The names of the properties are defined by the link:../../../../constant-values.html#com.opencloud.slee.remote.RhinoConnectionFactory.RHINO_HOST_ATTRIBUTE[constant field values] of this class. If both a server list and a host/port are in the properties, the server list takes precedence. If the target Rhino server requires SSL, the properties object must contain SSL properties if they have not been set as system properties prior to calling this method. The names of the SSL properties are defined by the link:../../../../constant-values.html#com.opencloud.slee.remote.RhinoSsl.JAVAXSSL_KEYSTORE_ATTRIBUTE[constant field values] in theRhinoSslclass.- Parameters:
properties- a properties object containing server address properties, authentication credential properties, and SSL properties (if not set as system properties)- Returns:
- a RhinoConnection instance
- Throws:
ConnectionException- if none of the provided servers could be reached
-
connect
public static RhinoConnection connect(String host, int port, String username, String password) throws ConnectionException
Create a Rhino client that will connect to the given host and port, and authenticate using the given username and password. If the target Rhino server requires SSL, the SSL system properties must be set prior to calling this method.- Parameters:
host- host to connect toport- port to connect tousername- username to authenticate aspassword- password to authenticate using- Returns:
- a RhinoConnection instance
- Throws:
ConnectionException- if none of the provided servers could be reached
-
connect
public static RhinoConnection connect(String serverList, String username, String password) throws ConnectionException
Create a Rhino client that will attempt connections to the given hosts and ports in the order specified, and authenticate using the given username and password. If the target Rhino server requires SSL, the SSL system properties must be set prior to calling this method.- Parameters:
serverList- list of servers to connect to in format "host1:port1,host2:port2,host3:port3,..."username- username to authenticate aspassword- password to authenticate using- Returns:
- a RhinoConnection instance
- Throws:
ConnectionException- if none of the provided servers could be reached
-
connect
public static RhinoConnection connect(String[] servers, String username, String password) throws ConnectionException
Create a Rhino client that will attempt connections to the given servers in the order specified, and authenticate using the given username and password. If the target Rhino server requires SSL, the SSL system properties must be set prior to calling this method.- Parameters:
servers- list of servers to connect to in format "host:port" in each array elementusername- username to authenticate aspassword- password to authenticate using- Returns:
- a RhinoConnection instance
- Throws:
ConnectionException- if none of the provided servers could be reached
-
connect
@Deprecated public static RhinoConnection connect(String host, int port, String username, String password, Properties sslProps) throws ConnectionException
Deprecated.Initialise SSL properties by callingsetRhinoSslProperties(java.util.Properties)(only once) then use connect methods on this class that do not take SSL properties as an argument. Please note that thesetRhinoSslPropertiesmethod requires a different set of SSL properties than that used by this method.Create a Rhino client that will connect to the given host and port, and authenticate using the given username and password. The `sslProps` properties object can only be used to provide SSL properties, not server addresses or authentication credentials. The names of the SSL properties are defined by the link:../../../../constant-values.html#com.opencloud.slee.remote.RhinoSsl.JAVAXSSL_KEYSTORE_ATTRIBUTE[constant field values] in theRhinoSslclass.- Parameters:
host- host to connect toport- port to connect tousername- username to authenticate aspassword- password to authenticate usingsslProps- properties object containing SSL properties- Returns:
- a RhinoConnection instance
- Throws:
ConnectionException- if none of the provided servers could be reached
-
connect
@Deprecated public static RhinoConnection connect(String[] servers, String username, String password, Properties sslProps) throws ConnectionException
Deprecated.Initialise SSL properties by callingsetRhinoSslProperties(java.util.Properties)(only once) then use connect methods on this class that do not take SSL properties as an argument. Please note that thesetRhinoSslPropertiesmethod requires a different set of SSL properties than that used by this method.Create a Rhino client that will attempt connections to the given servers in the order specified. The `sslProps` properties object can only be used to provide SSL properties, not server addresses or authentication credentials. The names of the SSL properties are defined by the link:../../../../constant-values.html#com.opencloud.slee.remote.RhinoSsl.JAVAXSSL_KEYSTORE_ATTRIBUTE[constant field values] in theRhinoSslclass.- Parameters:
servers- list of servers to connect to in format "host:port" in each array elementusername- username to authenticate aspassword- password to authenticate usingsslProps- properties object containing SSL properties- Returns:
- a RhinoConnection instance
- Throws:
ConnectionException- if none of the provided servers could be reached
-
recreateSslContext
public static void recreateSslContext()
Force the SSL context and client socket factory to be recreated. This can used when the trust store or keystore file has changed on disk. The SSL context and socket factory will be recreated the next time a connection is needed.
-
-