private ConnectionUri(final String theUriString) { final URI uri; try { uri = new URI(theUriString).parseServerAuthority(); } catch (final URISyntaxException e) { throw ConnectionUriInvalidException.newBuilder(theUriString).build(); } // validate self if (!isValid(uri)) { throw ConnectionUriInvalidException.newBuilder(theUriString).build(); } uriString = uri.toASCIIString(); protocol = uri.getScheme(); hostname = uri.getHost(); port = uri.getPort(); path = uri.getPath(); // initialize nullable fields final String userInfo = uri.getUserInfo(); if (userInfo != null && userInfo.contains(USERNAME_PASSWORD_SEPARATOR)) { final int separatorIndex = userInfo.indexOf(USERNAME_PASSWORD_SEPARATOR); userName = userInfo.substring(0, separatorIndex); password = userInfo.substring(separatorIndex + 1); } else { userName = null; password = null; } // must be initialized after all else uriStringWithMaskedPassword = createUriStringWithMaskedPassword(); }
private ConnectionUri(final String theUriString) { final URI uri; try { uri = new URI(theUriString).parseServerAuthority(); } catch (final URISyntaxException e) { throw ConnectionUriInvalidException.newBuilder(theUriString).build(); } // validate self if (!isValid(uri)) { throw ConnectionUriInvalidException.newBuilder(theUriString).build(); } uriString = uri.toASCIIString(); protocol = uri.getScheme(); hostname = uri.getHost(); port = uri.getPort(); path = uri.getPath(); // initialize nullable fields final String userInfo = uri.getUserInfo(); if (userInfo != null && userInfo.contains(USERNAME_PASSWORD_SEPARATOR)) { final int separatorIndex = userInfo.indexOf(USERNAME_PASSWORD_SEPARATOR); userName = userInfo.substring(0, separatorIndex); password = userInfo.substring(separatorIndex + 1); } else { userName = null; password = null; } // must be initialized after all else uriStringWithMaskedPassword = createUriStringWithMaskedPassword(); }
/** * Check whether the URI scheme of the connection belongs to an accepted scheme. * * @param connection the connection to check. * @param dittoHeaders headers of the command that triggered the connection validation. * @param acceptedSchemes valid URI schemes for the connection type. * @param protocolName protocol name of the connection type. * @throws DittoRuntimeException if the URI scheme is not accepted. */ protected static void validateUriScheme(final Connection connection, final DittoHeaders dittoHeaders, final Collection<String> acceptedSchemes, final String protocolName) { if (!acceptedSchemes.contains(connection.getProtocol())) { final String message = MessageFormat.format("The URI scheme ''{0}'' is not valid for {1}.", connection.getProtocol(), protocolName); final String description = MessageFormat.format("Accepted URI schemes are: {0}", String.join(", ", acceptedSchemes)); throw ConnectionUriInvalidException.newBuilder(connection.getUri()) .message(message) .description(description) .dittoHeaders(dittoHeaders) .build(); } }
/** * Check whether the URI scheme of the connection belongs to an accepted scheme. * * @param connection the connection to check. * @param dittoHeaders headers of the command that triggered the connection validation. * @param acceptedSchemes valid URI schemes for the connection type. * @param protocolName protocol name of the connection type. * @throws DittoRuntimeException if the URI scheme is not accepted. */ protected static void validateUriScheme(final Connection connection, final DittoHeaders dittoHeaders, final Collection<String> acceptedSchemes, final String protocolName) { if (!acceptedSchemes.contains(connection.getProtocol())) { final String message = MessageFormat.format("The URI scheme ''{0}'' is not valid for {1}.", connection.getProtocol(), protocolName); final String description = MessageFormat.format("Accepted URI schemes are: {0}", String.join(", ", acceptedSchemes)); throw ConnectionUriInvalidException.newBuilder(connection.getUri()) .message(message) .description(description) .dittoHeaders(dittoHeaders) .build(); } }