private static String normalizeClusterUrl ( String clusterIdentifier ) { try { URI uri = new URI ( clusterIdentifier . trim ( ) ) ; // URIs without protocol prefix if ( ! uri . isOpaque ( ) && null != uri . getHost ( ) ) { clusterIdentifier = uri . getHost ( ) ; } else { clusterIdentifier = uri . toString ( ) . replaceAll ( "[/:]" , " " ) . trim ( ) . replaceAll ( " " , "_" ) ; } } catch ( URISyntaxException e ) { //leave ID as is } return clusterIdentifier ; }
Strip out the port number if it is a valid URI