/** * 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(); } }
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(); } }
/** * Constructs a new {@code ConnectionUriInvalidException} object with the exception message extracted from the given * JSON object. * * @param jsonObject the JSON to read the {@link JsonFields#MESSAGE} field from. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new ConnectionUriInvalidException. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link * JsonFields#MESSAGE} field. */ public static ConnectionUriInvalidException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(readMessage(jsonObject)) .description(readDescription(jsonObject).orElse(DEFAULT_DESCRIPTION)) .href(readHRef(jsonObject).orElse(null)) .build(); }
/** * Constructs a new {@code ConnectionUriInvalidException} object with the exception message extracted from the given * JSON object. * * @param jsonObject the JSON to read the {@link JsonFields#MESSAGE} field from. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new ConnectionUriInvalidException. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link * JsonFields#MESSAGE} field. */ public static ConnectionUriInvalidException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(readMessage(jsonObject)) .description(readDescription(jsonObject).orElse(DEFAULT_DESCRIPTION)) .href(readHRef(jsonObject).orElse(null)) .build(); }
private Builder() { description(DEFAULT_DESCRIPTION); }
private Builder() { description(DEFAULT_DESCRIPTION); }
private Builder(final String uri) { this(); message(MessageFormat.format(MESSAGE_TEMPLATE, uri)); }
/** * Constructs a new {@code ConnectionUriInvalidException} object with given message. * * @param message detail message. This message can be later retrieved by the {@link #getMessage()} method. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new ConnectionUriInvalidException. */ public static ConnectionUriInvalidException fromMessage(final String message, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(message) .build(); }
private Builder(final String uri) { this(); message(MessageFormat.format(MESSAGE_TEMPLATE, uri)); }
/** * A mutable builder for a {@code ConnectionUriInvalidException}. * * @param uri the uri. * @return the builder. */ public static Builder newBuilder(final String uri) { return new Builder(uri); }
/** * Constructs a new {@code ConnectionUriInvalidException} object with given message. * * @param message detail message. This message can be later retrieved by the {@link #getMessage()} method. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new ConnectionUriInvalidException. */ public static ConnectionUriInvalidException fromMessage(final String message, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(message) .build(); }
/** * A mutable builder for a {@code ConnectionUriInvalidException}. * * @param uri the uri. * @return the builder. */ public static Builder newBuilder(final String uri) { return new Builder(uri); }