}
protected String buildServerURL() throws TeiidSQLException {
if ( this.alternateServers == null || this.alternateServers.length() == 0) {
// Format: "mm://server:port"
return new TeiidURL(this.serverName, this.portNumber, this.secure).getAppServerURL();
}
// Format: "mm://server1:port,server2:port,..."
String serverURL = this.secure ? TeiidURL.SECURE_PROTOCOL : TeiidURL.DEFAULT_PROTOCOL;
if (this.serverName.indexOf(':') != -1 && !this.serverName.startsWith("[")) { //$NON-NLS-1$
serverURL += "[" + this.serverName + "]"; //$NON-NLS-1$ //$NON-NLS-2$
} else {
serverURL += this.serverName;
}
serverURL += TeiidURL.COLON_DELIMITER + this.portNumber;
//add in the port number if not specified
String[] as = this.alternateServers.split( TeiidURL.COMMA_DELIMITER);
for ( int i = 0; i < as.length; i++ ) {
String server = as[i].trim();
//ipv6 without port
if (server.startsWith("[") && server.endsWith("]")) { //$NON-NLS-1$ //$NON-NLS-2$
String msg = reasonWhyInvalidServerName(server.substring(1, server.length() - 1));
if (msg != null) {
throw createConnectionError(JDBCPlugin.Util.getString("MMDataSource.alternateServer_is_invalid", msg)); //$NON-NLS-1$
}
serverURL += (TeiidURL.COMMA_DELIMITER +as[i] + TeiidURL.COLON_DELIMITER + this.portNumber);
} else {
String[] serverParts = server.split(TeiidURL.COLON_DELIMITER, 2);
String msg = reasonWhyInvalidServerName(serverParts[0]);
if (msg != null) {
throw createConnectionError(JDBCPlugin.Util.getString("MMDataSource.alternateServer_is_invalid", msg)); //$NON-NLS-1$
}
serverURL += (TeiidURL.COMMA_DELIMITER + serverParts[0] + TeiidURL.COLON_DELIMITER);
if ( serverParts.length > 1 ) {
try {
TeiidURL.validatePort(serverParts[1]);
} catch (MalformedURLException e) {
throw createConnectionError(JDBCPlugin.Util.getString("MMDataSource.alternateServer_is_invalid", e.getMessage())); //$NON-NLS-1$
}
serverURL += serverParts[1];
} else {
serverURL += this.portNumber;
}
}
}
try {
return new TeiidURL(serverURL).getAppServerURL();
} catch (MalformedURLException e) {
throw TeiidSQLException.create(e);
}
}