@Override protected ConnectionUriInvalidException doBuild(final DittoHeaders dittoHeaders, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new ConnectionUriInvalidException(dittoHeaders, message, description, cause, href); } }
/** * 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 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(); }
/** * 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 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(); } }
@Override protected ConnectionUriInvalidException doBuild(final DittoHeaders dittoHeaders, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new ConnectionUriInvalidException(dittoHeaders, message, description, cause, href); } }
/** * 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(); } }