Package com.streambase.sb.client
Class StreamBaseURI
- java.lang.Object
-
- com.streambase.sb.client.StreamBaseURI
-
public final class StreamBaseURI extends Object
A Uniform Resource Identifier containing information necessary to connect to a StreamBase server. For more information about URIs, please see the StreamBase documentation.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_CONTAINERThe default container ("default")static StringDEFAULT_HOSTThe default StreamBase server ("localhost").static intDEFAULT_PORTThe default StreamBase TCP port number (10000).static StreamBaseURIDEFAULT_URIThe default URI (sb://localhost:10000/) pointing to localhost, no container, port 10000).static StringKEY_PASS_PARAMURI parameter used for the passphrase for a key within a keystore for SSL with client authentication (2-way ssl).static StringKEY_PASSWORD_MASKdefault keypass maskstatic StringKEYSTORE_PARAMURI parameter used for a keystore for SSL with client authentication (2-way ssl).static StringKEYSTORE_PASS_PARAMURI parameter used for the passphrase for a keystore for SSL with client authentication (2-way ssl).static Set<String>MASKED_PARAMSdefault set of parameter containing sensitive datastatic StringNO_CONTAINERNo container specified ("")static StringPASSWORD_PARAMURI parameter used for password.static StringQT_PARAMURI parameter used internally as part of container table connection logicstatic StringSECONDARY_HOST_PARAMURI parameter used for secondary host name.static StringSECONDARY_PORT_PARAMURI parameter used for secondary port name.static StringSTREAM_PARAMURI parameter used internally (only) as part of container stream connection logicstatic StringSYSTEM_CONTAINERThe system container ("system")static StringURI_ENVIRONMENT_VARIABLEThat environment variable used to define the uri to the serverstatic StringURI_PROPERTY_NAMEThat java property used to define the uri to the serverstatic StringUSER_PARAMURI parameter used for username.
-
Constructor Summary
Constructors Constructor Description StreamBaseURI(String uri)Constructor that parses a StreamBase URI passed in as a String.StreamBaseURI(String host, int port)Constructor roughly equivalent tonew StreamBaseURI("sb://host:port/").StreamBaseURI(String host, int port, Map<String,String> params)Equivalent to StreamBaseURI(host, NO_CONTAINER, port, params)StreamBaseURI(String host, String container, int port)Constructor roughly equivalent tonew StreamBaseURI("sb://host:port/container").StreamBaseURI(String host, String container, int port, boolean useSSL, Map<String,String> params)Constructor roughly equivalent tonew StreamBaseURI("scheme://host:port/container;param1=value1(...)"), where scheme is either "sb" or "sbs" depending on whether useSSL is true or false, and param1=value1(...) stands for every entry in theparamsMapStreamBaseURI(String host, String container, int port, String user, String password)Constructor roughly equivalent tonew StreamBaseURI("sb://host:port/container;user=user;password=password").StreamBaseURI(String host, String container, int port, Map<String,String> params)Equivalent to StreamBaseURI(host, container, port, false, params)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Compares this URI against the supplied one.static StreamBaseURIfromEnvironment()Returns the URI found by searching the following property and environment variables: Using the string value found in thestreambase.urisystem property, if set Using the string value found in theSTREAMBASE_URIenvironment variable, if set Using the string value found in theSTREAMBASE_SERVERenvironment variable, if setDEFAULT_URIif no value has been found aboveStreamBaseURIgetBaseURI()Return a copy of this URI without any paramsStringgetBasicAuthenticationString()Returns a Base64-encoded username + password if authentication is enabled, or null otherwise.StringgetContainer()Returns the container name component of the URI.StringgetHost()Returns the host name component of the URI.StringgetKeyPassphrase()Return the passphrase for the key within the keystore for the connection.StringgetKeystore()Return the keystore for the connection.StringgetKeystorePassphrase()Return the passphrase for the keystore for the connection.intgetNumParameters()Return the number of URI parametersStringgetParam(String key)Returns a parameter with a given key, or null if none exists.StringgetParameter(String key)Returns a parameter with a given key, or null if none exists.Map<String,String>getParams()Returns an unmodifiable map of all parameters.StringgetPassword()Return the password for the connection.intgetPort()Returns the port number.StringgetUser()Return the user name for the connection.static booleanhasPrefix(String s)booleanisSSL()static List<StreamBaseURI>listFromEnvironment()Returns the list of URIs found by searching the following property and environment variables for a comma separated URI list: Using the string value found in thestreambase.urisystem property, if set Using the string value found in theSTREAMBASE_URIenvironment variable, if set Using the string value found in theSTREAMBASE_SERVERenvironment variable, if setDEFAULT_URIif no value has been above The supplied URIs must conform to a valid High Availability URI list, for example they must all reference the same container.static List<StreamBaseURI>listFromString(String uriStrings)Parse a comma-separated list of URIs in a string into a List<StreamBaseURI>.StringsafeString()LiketoString()except that all sensitive data defined in the setMASKED_PARAMSare masked withKEY_PASSWORD_MASKstatic StringtoSafeString(Collection<StreamBaseURI> uris)Create a string representation of a list of uris, that is safe for logging.StringtoString()Returns a string representation of the URI.static StringtoString(Collection<StreamBaseURI> uris)Create a string representation of a list of uris.
-
-
-
Field Detail
-
DEFAULT_PORT
public static final int DEFAULT_PORT
The default StreamBase TCP port number (10000).- See Also:
- Constant Field Values
-
DEFAULT_HOST
public static final String DEFAULT_HOST
The default StreamBase server ("localhost").- See Also:
- Constant Field Values
-
DEFAULT_CONTAINER
public static final String DEFAULT_CONTAINER
The default container ("default")- See Also:
- Constant Field Values
-
SYSTEM_CONTAINER
public static final String SYSTEM_CONTAINER
The system container ("system")- See Also:
- Constant Field Values
-
NO_CONTAINER
public static final String NO_CONTAINER
No container specified ("")- See Also:
- Constant Field Values
-
DEFAULT_URI
public static final StreamBaseURI DEFAULT_URI
The default URI (sb://localhost:10000/) pointing to localhost, no container, port 10000).
-
USER_PARAM
public static final String USER_PARAM
URI parameter used for username.- See Also:
- Constant Field Values
-
PASSWORD_PARAM
public static final String PASSWORD_PARAM
URI parameter used for password.- See Also:
- Constant Field Values
-
SECONDARY_HOST_PARAM
public static final String SECONDARY_HOST_PARAM
URI parameter used for secondary host name. ("host2")- See Also:
- Constant Field Values
-
SECONDARY_PORT_PARAM
public static final String SECONDARY_PORT_PARAM
URI parameter used for secondary port name. ("port2")- See Also:
- Constant Field Values
-
KEYSTORE_PARAM
public static final String KEYSTORE_PARAM
URI parameter used for a keystore for SSL with client authentication (2-way ssl). ("keystore")- See Also:
- Constant Field Values
-
KEYSTORE_PASS_PARAM
public static final String KEYSTORE_PASS_PARAM
URI parameter used for the passphrase for a keystore for SSL with client authentication (2-way ssl). ("keystorepass")- See Also:
- Constant Field Values
-
KEY_PASS_PARAM
public static final String KEY_PASS_PARAM
URI parameter used for the passphrase for a key within a keystore for SSL with client authentication (2-way ssl). ("keypass")- See Also:
- Constant Field Values
-
STREAM_PARAM
public static final String STREAM_PARAM
URI parameter used internally (only) as part of container stream connection logic- See Also:
- Constant Field Values
-
QT_PARAM
public static final String QT_PARAM
URI parameter used internally as part of container table connection logic- See Also:
- Constant Field Values
-
URI_PROPERTY_NAME
public static final String URI_PROPERTY_NAME
That java property used to define the uri to the server- See Also:
- Constant Field Values
-
URI_ENVIRONMENT_VARIABLE
public static final String URI_ENVIRONMENT_VARIABLE
That environment variable used to define the uri to the server- See Also:
- Constant Field Values
-
KEY_PASSWORD_MASK
public static final String KEY_PASSWORD_MASK
default keypass mask- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StreamBaseURI
public StreamBaseURI(String uri) throws URIException
Constructor that parses a StreamBase URI passed in as a String. The format for a StreamBase URI is:scheme://host[:port][/container][/][[;param=value]...]- scheme: use
sborsbs, the latter to enable a secure SSL connection - host: an ip address or hostname of the target server
- port: (optional) target TCP port number, defaults to
DEFAULT_PORT - container: (optional) target container name, defaults to
NO_CONTAINER - ;param=value: (optional) each occurrence sets a key/value parameter mapping for additional arguments; unknown arguments result in a URIException being thrown. Refer to the documentation or the public constants defined in StreamBaseURI ending in _PARAM for valid parameter names
- Parameters:
uri- a URI to parse- Throws:
URIException- if the URI syntax is invalid, or if an unknown parameter name is found
- scheme: use
-
StreamBaseURI
public StreamBaseURI(String host, String container, int port)
Constructor roughly equivalent tonew StreamBaseURI("sb://host:port/container").- Parameters:
host- a host name to connect tocontainer- a container to connect toport- a port number to connect to- See Also:
StreamBaseURI(String)
-
StreamBaseURI
public StreamBaseURI(String host, int port)
Constructor roughly equivalent tonew StreamBaseURI("sb://host:port/").- Parameters:
host- a host name to connect toport- a port number to connect to- See Also:
StreamBaseURI(String)
-
StreamBaseURI
public StreamBaseURI(String host, String container, int port, String user, String password)
Constructor roughly equivalent tonew StreamBaseURI("sb://host:port/container;user=user;password=password").- Parameters:
host- a host name to connect tocontainer- a container to connect toport- a port number to connect touser- a user name for the connectionpassword- a password for the connection- See Also:
StreamBaseURI(String)
-
StreamBaseURI
public StreamBaseURI(String host, String container, int port, boolean useSSL, Map<String,String> params)
Constructor roughly equivalent tonew StreamBaseURI("scheme://host:port/container;param1=value1(...)"), where scheme is either "sb" or "sbs" depending on whether useSSL is true or false, and param1=value1(...) stands for every entry in theparamsMap- Parameters:
host- a host name to connect tocontainer- a container to connect toport- a port number to connect touseSSL- whether to use an SSL connection to the server or notparams- a Map of String parameters for the URI, or null to indicate no parameters. This map is not checked for correctness.
-
StreamBaseURI
public StreamBaseURI(String host, String container, int port, Map<String,String> params)
Equivalent to StreamBaseURI(host, container, port, false, params)- Parameters:
host- a host name to connect tocontainer- a container to connect toport- a port number to connect toparams- a Map of String parameters for the URI, or null to indicate no parameters. This map is not checked for correctness.- See Also:
StreamBaseURI(String, String, int, boolean, Map)
-
StreamBaseURI
public StreamBaseURI(String host, int port, Map<String,String> params)
Equivalent to StreamBaseURI(host, NO_CONTAINER, port, params)- Parameters:
host- a host name to connect toport- a port number to connect toparams- a Map of String parameters for the URI, or null to indicate no parameters. This map is not checked for correctness.- See Also:
StreamBaseURI(String, String, int, Map)
-
-
Method Detail
-
listFromString
public static List<StreamBaseURI> listFromString(String uriStrings) throws URIException
Parse a comma-separated list of URIs in a string into a List<StreamBaseURI>. The string of URIs supplied must conform to a valid HA URI list, for example they must all reference the same container.- Parameters:
uriStrings-- Returns:
- list of StreamBaseURI's
- Throws:
URIException
-
toString
public static String toString(Collection<StreamBaseURI> uris)
Create a string representation of a list of uris.
Use
toSafeString(Collection)if sensitive data need to be masked.- Parameters:
uris-- Returns:
- string representation of a list of uris
- Since:
- 6.1
-
toSafeString
public static String toSafeString(Collection<StreamBaseURI> uris)
Create a string representation of a list of uris, that is safe for logging. SeesafeString()- Parameters:
uris-- Returns:
- string representation of a list of uris
- Since:
- 10.4
-
toString
public String toString()
Returns a string representation of the URI.
Log messages should use
safeString()instead, where sensitive data are masked.
-
safeString
public String safeString()
LiketoString()except that all sensitive data defined in the setMASKED_PARAMSare masked withKEY_PASSWORD_MASK
-
getBaseURI
public StreamBaseURI getBaseURI()
Return a copy of this URI without any params
-
getHost
public String getHost()
Returns the host name component of the URI.
-
getContainer
public String getContainer()
Returns the container name component of the URI. May return an empty string if no container was specified.
-
getPort
public int getPort()
Returns the port number.
-
getParam
public String getParam(String key)
Returns a parameter with a given key, or null if none exists.- Parameters:
key- the key for the parameter or null if not found
-
getParameter
public String getParameter(String key)
Returns a parameter with a given key, or null if none exists.- Parameters:
key- the key for the parameter or null if not found
-
getNumParameters
public int getNumParameters()
Return the number of URI parameters- Returns:
- number of URI parameters
-
getUser
public String getUser()
Return the user name for the connection.- Returns:
- The user name for the connection, or
nullif none.
-
getPassword
public String getPassword()
Return the password for the connection.- Returns:
- The password for the connection, or
nullif none.
-
getKeystore
public String getKeystore()
Return the keystore for the connection.- Returns:
- The keystore for the connection, or
nullif none.
-
getKeystorePassphrase
public String getKeystorePassphrase()
Return the passphrase for the keystore for the connection.- Returns:
- The passphrase for the keystore for the connection, or
nullif none.
-
getKeyPassphrase
public String getKeyPassphrase()
Return the passphrase for the key within the keystore for the connection.- Returns:
- The passphrase for the key within the keystore for the connection, or
nullif none. - Since:
- 7.3.10
-
isSSL
public boolean isSSL()
- Returns:
- true if this is an SSL URI.
-
fromEnvironment
public static StreamBaseURI fromEnvironment() throws URIException
Returns the URI found by searching the following property and environment variables:- Using the string value found in the
streambase.urisystem property, if set - Using the string value found in the
STREAMBASE_URIenvironment variable, if set - Using the string value found in the
STREAMBASE_SERVERenvironment variable, if set DEFAULT_URIif no value has been found above
- Throws:
URIException- if the URI found in any of the search locations is invalid
- Using the string value found in the
-
listFromEnvironment
public static List<StreamBaseURI> listFromEnvironment() throws URIException
Returns the list of URIs found by searching the following property and environment variables for a comma separated URI list:- Using the string value found in the
streambase.urisystem property, if set - Using the string value found in the
STREAMBASE_URIenvironment variable, if set - Using the string value found in the
STREAMBASE_SERVERenvironment variable, if set DEFAULT_URIif no value has been above
- Throws:
URIException- if any URI found is invalid
- Using the string value found in the
-
getBasicAuthenticationString
public String getBasicAuthenticationString()
Returns a Base64-encoded username + password if authentication is enabled, or null otherwise.
-
equals
public boolean equals(Object obj)
Compares this URI against the supplied one. Note that the host names must textually match exactly (i.e., no cleverness is applied to implement "host equality").
-
hasPrefix
public static boolean hasPrefix(String s)
- Parameters:
s-- Returns:
- true iff the supplied string looks like the beginning of a StreamBase URI
-
-