validateConnection method
Validates connection parameters and throws an exception on error. This method can be overriden in child classes.
correlationId
(optional) transaction id to trace execution through call chain.connection
connection parameters to be validated
Implementation
void validateConnection(String? correlationId, ConnectionParams? connection) {
if (connection == null) {
throw ConfigException(correlationId, 'NO_CONNECTION',
'Connection parameters are not set is not set');
}
// URI usually contains all information
dynamic uri = connection.getUri();
if (uri != null) {
return;
}
dynamic protocol = connection.getProtocol(_defaultProtocol);
if (protocol == null) {
throw ConfigException(
correlationId, 'NO_PROTOCOL", "Connection protocol is not set');
}
if (_supportedProtocols != null &&
!_supportedProtocols!.contains(protocol)) {
throw ConfigException(correlationId, 'UNSUPPORTED_PROTOCOL',
'The protocol ' + protocol + ' is not supported');
}
dynamic host = connection.getHost();
if (host == null) {
throw ConfigException(
correlationId, 'NO_HOST', 'Connection host is not set');
}
dynamic port = connection.getPortWithDefault(_defaultPort);
if (port == 0) {
throw ConfigException(
correlationId, 'NO_PORT', 'Connection port is not set');
}
}