RhinoConnectionFactory.setLogWriter(new PrintWriter(System.out, true));
public class RhinoConnectionFactory extends Object
Factory class to create connections to Rhino.
Modifier and Type | Field and Description |
---|---|
static String |
RHINO_HOST_ATTRIBUTE |
static String |
RHINO_KEYSTORE_ATTRIBUTE |
static String |
RHINO_KEYSTOREPASS_ATTRIBUTE |
static String |
RHINO_PASSWORD_ATTRIBUTE |
static String |
RHINO_PORT_ATTRIBUTE |
static String |
RHINO_SERVERLIST_ATTRIBUTE |
static String |
RHINO_TRUSTSTORE_ATTRIBUTE |
static String |
RHINO_TRUSTSTOREPASS_ATTRIBUTE |
static String |
RHINO_USERNAME_ATTRIBUTE |
Modifier and Type | Method and Description |
---|---|
static RhinoConnection |
connect(File propertiesFile)
Create a Rhino client using connection properties in the given properties file.
|
static RhinoConnection |
connect(Properties properties)
Create a Rhino client using connection properties in the given properties object.
|
static RhinoConnection |
connect(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 RhinoConnection |
connect(String[] servers,
String username,
String password,
Properties sslProps)
Deprecated.
Initialise SSL properties by calling
setRhinoSslProperties(java.util.Properties) (only once) then use connect methods on this class that do not take SSL properties as an argument.
Please note that the setRhinoSslProperties method requires a different set of SSL properties than that used by this method. |
static RhinoConnection |
connect(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 RhinoConnection |
connect(String host,
int port,
String username,
String password,
Properties sslProps)
Deprecated.
Initialise SSL properties by calling
setRhinoSslProperties(java.util.Properties) (only once) then use connect methods on this class that do not take SSL properties as an argument.
Please note that the setRhinoSslProperties method requires a different set of SSL properties than that used by this method. |
static RhinoConnection |
connect(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 PrintWriter |
getLogWriter()
Retrieves the log writer.
|
static void |
recreateSslContext()
Force the SSL context and client socket factory to be recreated.
|
static void |
setLogWriter(PrintWriter out)
Sets the logging/tracing PrintWriter object that is used by the RhinoConnectionFactory and all connections.
|
static void |
setRhinoSslProperties(Properties sslProps)
Set the SSL properties.
|
static void |
setRhinoSslProperties(Properties sslProps,
boolean useJavaxSslProperties)
Set the SSL properties.
|
public static final String RHINO_HOST_ATTRIBUTE
public static final String RHINO_PORT_ATTRIBUTE
public static final String RHINO_SERVERLIST_ATTRIBUTE
public static final String RHINO_USERNAME_ATTRIBUTE
public static final String RHINO_PASSWORD_ATTRIBUTE
public static final String RHINO_TRUSTSTORE_ATTRIBUTE
public static final String RHINO_TRUSTSTOREPASS_ATTRIBUTE
public static final String RHINO_KEYSTORE_ATTRIBUTE
public static final String RHINO_KEYSTOREPASS_ATTRIBUTE
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:
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:
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()));
out
- the new logging/tracing PrintWriter object; null to disable logging and tracingpublic static PrintWriter getLogWriter()
Retrieves the log writer.
public static void setRhinoSslProperties(Properties sslProps) throws IllegalArgumentException
Set the SSL properties.
The values will be used by the RhinoSslRMIClientSocketFactory
to 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 use RhinoSsl.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 to RhinoSsl.checkSslProperties(java.util.Properties)
.
sslProps
- a properties object containing properties with names of the String constant values RHINO_TRUSTSTORE_ATTRIBUTE
, RHINO_TRUSTSTOREPASS_ATTRIBUTE
, RHINO_KEYSTORE_ATTRIBUTE
and RHINO_KEYSTOREPASS_ATTRIBUTE
.IllegalArgumentException
public static void setRhinoSslProperties(Properties sslProps, boolean useJavaxSslProperties) throws IllegalArgumentException
Set the SSL properties.
The values will be used by the RhinoSslRMIClientSocketFactory
to 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 use RhinoSsl.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 to RhinoSsl.checkSslProperties(java.util.Properties)
.
Note: The useJavaxSslProperties flag affects which properties are used.
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 values RhinoSsl.JAVAXSSL_TRUSTSTORE_ATTRIBUTE
, RhinoSsl.JAVAXSSL_TRUSTSTOREPASS_ATTRIBUTE
, RhinoSsl.JAVAXSSL_KEYSTORE_ATTRIBUTE
and RhinoSsl.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 values RHINO_TRUSTSTORE_ATTRIBUTE
, RHINO_TRUSTSTOREPASS_ATTRIBUTE
, RHINO_KEYSTORE_ATTRIBUTE
and RHINO_KEYSTOREPASS_ATTRIBUTE
.useJavaxSslProperties
- Controls which properties in sslProps are read from (see sslProps above).IllegalArgumentException
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 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 constant field values in the RhinoSsl
class.
propertiesFile
- a file containing server address properties, authentication credential properties, and SSL properties (if not set as system properties)ConnectionException
- if none of the provided servers could be reachedpublic 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 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 constant field values in the RhinoSsl
class.
properties
- a properties object containing server address properties, authentication credential properties, and SSL properties (if not set as system properties)ConnectionException
- if none of the provided servers could be reachedpublic 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.
host
- host to connect toport
- port to connect tousername
- username to authenticate aspassword
- password to authenticate usingConnectionException
- if none of the provided servers could be reachedpublic 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.
serverList
- list of servers to connect to in format "host1:port1,host2:port2,host3:port3,…"username
- username to authenticate aspassword
- password to authenticate usingConnectionException
- if none of the provided servers could be reachedpublic 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.
servers
- list of servers to connect to in format "host:port" in each array elementusername
- username to authenticate aspassword
- password to authenticate usingConnectionException
- if none of the provided servers could be reachedpublic static RhinoConnection connect(String host, int port, String username, String password, Properties sslProps) throws ConnectionException
setRhinoSslProperties(java.util.Properties)
(only once) then use connect methods on this class that do not take SSL properties as an argument.
Please note that the setRhinoSslProperties
method 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 constant field values in the RhinoSsl
class.
host
- host to connect toport
- port to connect tousername
- username to authenticate aspassword
- password to authenticate usingsslProps
- properties object containing SSL propertiesConnectionException
- if none of the provided servers could be reachedpublic static RhinoConnection connect(String[] servers, String username, String password, Properties sslProps) throws ConnectionException
setRhinoSslProperties(java.util.Properties)
(only once) then use connect methods on this class that do not take SSL properties as an argument.
Please note that the setRhinoSslProperties
method 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 constant field values in the RhinoSsl
class.
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 propertiesConnectionException
- if none of the provided servers could be reachedpublic 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.