Package com.uc4.communication
Class Connection
java.lang.Object
com.uc4.communication.Connection
- All Implemented Interfaces:
AEConnection
,Closeable
,AutoCloseable
This class represents a connection to the UC4 Server with a specific UC4 user.
Using the UC4.ApplicationInterface includes this steps:
- Open a connection to the UC4 Server. This is done using the static
open
method. - Login to the UC4 Server using the method
login
. The methodisLoginSuccessful
should be used to test if the login was successful. - Send requests using
sendRequestAndWait
orsendRequest
. - Close the connection with
close
.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a close event listener.void
Adds a kick event listener.void
Adds a notification listener.void
close()
Closes the connection to the UC4 Server.Deprecated.There is no CP list in version 21.0 and higherReturns the address of the Java communication processReturns information about the current UC4 Session.int
Returns the timeout for synchronous application.Returns the listener of trace message ornull
if the trace is not enabled.boolean
isValid()
Returns true if there is an open connection to the AESets the session, this method must be called before a login request is sent.Sets the session, this method must be called before a login request is sent.Sets the session, this method must be called before a login request is sent.login
(AccessTokenConfiguration config) Login using an access tokenlogin
(SamlConfiguration config) Single Sign On using SAMLlogin
(SSOConfiguration config) Single Sign On (Kerberos) using the current OS user.static Connection
Opens a connection to the UC4 Server.static Connection
open
(String servername, int port, Properties options) Opens a connection to the UC4 Server.static Connection
open
(String servername, int port, Properties options, DebugAndTraceListener traceListener) Opens a connection to the UC4 Server.static Connection
open
(String servername, int port, Properties options, DebugAndTraceListener traceListener, String trustedCertFolderPath) Opens a connection to the UC4 Server.void
Removes a close event listener.void
Removes a notification listener.void
Removes a notification listener.sendRequest
(XMLRequest sendableMessage, IResponseHandler handler) Sends an message to the UC4 Server.void
sendRequestAndWait
(XMLRequest sendableMessage) Sends a message to the UC4 Server and waits for the response.void
setClientType
(String clientType) void
setTimeout
(int millis) Sets the timeout in milliseconds.void
setTraceListener
(TraceListener listener) Sets a listener in order to trace the messages that are exchanged between the Automation Engine and the UC4.Application Interface.static void
setTrustedCertFolderPath
(String trustedCertFolderPath) Sets the path to a trusted certificate folder.static void
setUseTrustedCertFolderOnly
(boolean useTrustedCertFolderOnly) Determines wether the certificates in the trusted cert folder should be pinned or nottoString()
-
Method Details
-
setTrustedCertFolderPath
Sets the path to a trusted certificate folder. This path will be used for opening connections.- Parameters:
trustedCertFolderPath
- path to a folder containing trusted certificates
-
setUseTrustedCertFolderOnly
public static void setUseTrustedCertFolderOnly(boolean useTrustedCertFolderOnly) Determines wether the certificates in the trusted cert folder should be pinned or not- Parameters:
useTrustedCertFolderOnly
- true - pinned, false - not
-
setTimeout
public void setTimeout(int millis) Sets the timeout in milliseconds. Use zero to disable the timeout.- Parameters:
millis
- Timeout
-
getTimeout
public int getTimeout()Returns the timeout for synchronous application.- Returns:
- timeout in milliseconds
-
open
Opens a connection to the UC4 Server.- Parameters:
servername
- Name of the Java Communication Process (JCP)port
- WebSocket Port number of the JCP- Returns:
- UC4 Connection
- Throws:
IOException
- if an I/O error occurred
-
open
Opens a connection to the UC4 Server.- Parameters:
servername
- Name of the Java Communication Process (JCP)port
- WebSocket Port number of the JCPoptions
- Advanced connection options, can benull
. Supported parameters:Key Description AGENTNAME Name of the Agent if the connection is created within an UC4 Agent process HOSTNAME Name of the user's host. This value will be shown in the system overview REMOTE_ID Remote ID. This value will be shown in the system overview SECRET_TYPE Optional: Type of the secret in the login method. Values: "ET" (Exit-Token), "TK" (AE-Token) and "PW" (Password) CONNECT_TIMEOUT_MILLIS Optional: Timeout for the initial connection to the JCP in milliseconds - Returns:
- UC4 Connection
- Throws:
IOException
- if an I/O error occurred
-
open
public static Connection open(String servername, int port, Properties options, DebugAndTraceListener traceListener) throws IOException Opens a connection to the UC4 Server.- Parameters:
servername
- Name of the Java Communication Process (JCP)port
- WebSocket Port number of the JCPoptions
- Advanced connection options, can benull
Supported parameters:Key Description AGENTNAME Name of the Agent if the connection is created within an UC4 Agent process HOSTNAME Name of the user's host. This value will be shown in the system overview REMOTE_ID Remote ID. This value will be shown in the system overview SECRET_TYPE Optional: Type of the secret in the login method. Values: "ET" (Exit-Token), "TK" (AE-Token) and "PW" (Password) CONNECT_TIMEOUT_MILLIS Optional: Timeout for the initial connection to the JCP in milliseconds traceListener
- aDebugAndTraceListener
for tracing information regarding the connection- Returns:
- UC4 Connection
- Throws:
IOException
- if an I/O error occurred
-
open
public static Connection open(String servername, int port, Properties options, DebugAndTraceListener traceListener, String trustedCertFolderPath) throws IOException Opens a connection to the UC4 Server.- Parameters:
servername
- Name of the Java Communication Process (JCP)port
- WebSocket Port number of the JCPoptions
- Advanced connection options, can benull
Supported parameters:Key Description AGENTNAME Name of the Agent if the connection is created within an UC4 Agent process HOSTNAME Name of the user's host. This value will be shown in the system overview REMOTE_ID Remote ID. This value will be shown in the system overview SECRET_TYPE Optional: Type of the secret in the login method. Values: "ET" (Exit-Token), "TK" (AE-Token) and "PW" (Password) CONNECT_TIMEOUT_MILLIS Optional: Timeout for the initial connection to the JCP in milliseconds traceListener
- aDebugAndTraceListener
for tracing information regarding the connectiontrustedCertFolderPath
- path to folder containing trusted certificates. Ifnull
, the previously path set bysetTrustedCertFolderPath(String)
is used- Returns:
- UC4 Connection
- Throws:
IOException
- if an I/O error occurred
-
addNotificationListener
Adds a notification listener.- Parameters:
l
- Listener
-
removeNotificationListener
Removes a notification listener.- Parameters:
l
- Listener
-
addKickEventListener
Adds a kick event listener.- Parameters:
l
- Listener
-
removeKickEventListener
Removes a notification listener.- Parameters:
l
- Listener
-
addCloseEventListener
Adds a close event listener.- Parameters:
l
- Listener
-
removeCloseEventListener
Removes a close event listener.- Parameters:
l
- Listener
-
close
Closes the connection to the UC4 Server.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an I/O error occurred
-
sendRequestAndWait
Sends a message to the UC4 Server and waits for the response. This method blocks until the response from the UC4 Server is arrived. The API connection is closed if the Thread is interrupted while waiting for a response. Throws TimeoutException if a timeout has been set and the Server did not respond within that time.When a request is sent with this method, before further processing of the response, the message of the response (see
XMLRequest.getMessageBox()
) has to be always checked for any error. Only if this is empty the processing of the response can continue.
If an error is present, proper error handling has to be implemented on the calling side.
Processing the unsuccessful response might get undefined results!- Specified by:
sendRequestAndWait
in interfaceAEConnection
- Parameters:
sendableMessage
- XML request- Throws:
IOException
- If an I/O error occursTimeoutException
- if a timeout was defined and a response was not received in the API within the specified time
-
sendRequest
Sends an message to the UC4 Server.After the request is sent to the UC4 Server the method call returns immediately. When the response to this request arrives the IResponseHandler will be called.
This method does not support creating folders (request CreateObject with type FOLD). Use the method sendRequestAndWait() in order to create a new folder.- Specified by:
sendRequest
in interfaceAEConnection
- Parameters:
sendableMessage
- Object which implements theXMLRequest
Interfacehandler
- Response Handler- Returns:
- Request Number as String.
- Throws:
IOException
- If an I/O error occurs
-
login
Single Sign On (Kerberos) using the current OS user. Requires the Java Cryptography Extension (JCE) Unlimited Strength.- Parameters:
config
- SSO configuration containing for example the UC4 client- Returns:
- CreateSession, the method isLoginSuccessful can be used to test if the login was successful
- Throws:
IOException
- In case of I/O errorsTimeoutException
- if a timeout was defined and a response was not received in the API within the specified time
-
login
Single Sign On using SAML- Parameters:
config
- configuration containing for example the SAML token or UC4 client- Returns:
CreateSession
the method isLoginSuccessful can be used to test if the login was successful- Throws:
IOException
- In case of I/O errorsTimeoutException
- if a timeout was defined and a response was not received in the API within the specified time
-
login
Login using an access token- Parameters:
config
- configuration containing the token- Returns:
CreateSession
the method isLoginSuccessful can be used to test if the login was successful- Throws:
IOException
- In case of I/O errorsTimeoutException
- if a timeout was defined and a response was not received in the API within the specified time
-
login
Sets the session, this method must be called before a login request is sent. ThrowsIllegalArgumentException
if the client is out of client number range (0-9999). ThrowsNullPointerException
if the username isnull
.- Parameters:
client
- must be between 0 and 9999department
- department may benull
kicks
- Comma separated list of kick messages.- Returns:
- CreateSession, the method isLoginSuccessful can be used to test if the login was successful
- Throws:
IOException
- In case of I/O errorsTimeoutException
- if a timeout was defined and a response was not received in the API within the specified time
-
login
public CreateSession login(int client, String user, String department, String password, char language) throws IOException Sets the session, this method must be called before a login request is sent. ThrowsIllegalArgumentException
if the client is out of client number range (0-9999). ThrowsNullPointerException
if the username isnull
.- Parameters:
client
- must be between 0 and 9999user
- Name of the userdepartment
- department may benull
password
- Ifnull
, an empty string is used as password.language
- Language can be 'D' (German), 'E' (English) and 'F' (French)- Returns:
- CreateSession, the method isLoginSuccessful can be used to test if the login was successful
- Throws:
IOException
- In case of I/O errorsTimeoutException
- if a timeout was defined and a response was not received in the API within the specified time
-
login
public CreateSession login(int client, String user, String department, String password, char language, String kicks) throws IOException Sets the session, this method must be called before a login request is sent. ThrowsIllegalArgumentException
if the client is out of client number range (0-9999). ThrowsNullPointerException
if the username isnull
.- Parameters:
client
- must be between 0 and 9999user
- Name of the userdepartment
- department may benull
password
- Ifnull
, an empty string is used as password.language
- Language can be 'D' (German), 'E' (English) and 'F' (French)kicks
- Comma separated list of kick messages.- Returns:
- CreateSession, the method isLoginSuccessful can be used to test if the login was successful
- Throws:
IOException
- In case of I/O errorsTimeoutException
- if a timeout was defined and a response was not received in the API within the specified time
-
setTraceListener
Sets a listener in order to trace the messages that are exchanged between the Automation Engine and the UC4.Application Interface. If you don't intend to dynamically add this listener, consider passing a DebugAndTraceListener to open(). This listener will then also trace information regarding opening the connection.- Parameters:
listener
- Listener ornull
to deactivate the trace
-
getTraceListener
Returns the listener of trace message ornull
if the trace is not enabled.- Returns:
- Listener instance or
null
if not set
-
setClientType
-
getCpAddress
Returns the address of the Java communication process- Returns:
- the address of the Java communication process
-
getSessionInfo
Returns information about the current UC4 Session.- Specified by:
getSessionInfo
in interfaceAEConnection
- Returns:
- Session information
-
cpIterator
Deprecated.There is no CP list in version 21.0 and higherThisjava.util.Iterator
can be used to get all CP Addresses in this UC4 System.- Returns:
- Iterator of
InetSocketAddress
-
isValid
public boolean isValid()Returns true if there is an open connection to the AE- Returns:
- true if the connection is open and can be used to send requests, false otherwise
-
toString
-