private static ConnectionConfigurationInvalidException.Builder invalidValueForConfig(final Object value, final String configName, final String location) { final String message = MessageFormat.format("Invalid value ''{0}'' for configuration ''{1}'' in {2}", value, configName, location); return ConnectionConfigurationInvalidException.newBuilder(message); } }
@Override protected ConnectionConfigurationInvalidException doBuild(final DittoHeaders dittoHeaders, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new ConnectionConfigurationInvalidException(dittoHeaders, message, description, cause, href); }
/** * Constructs a new {@code ConnectionConfigurationInvalidException} 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 ConnectionConfigurationInvalidException. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link * JsonFields#MESSAGE} field. */ public static ConnectionConfigurationInvalidException 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 ConnectionConfigurationInvalidException} 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 ConnectionConfigurationInvalidException. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link * JsonFields#MESSAGE} field. */ public static ConnectionConfigurationInvalidException 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 static ConnectionConfigurationInvalidException.Builder invalidValueForConfig(final Object value, final String configName, final String location) { final String message = MessageFormat.format("Invalid value ''{0}'' for configuration ''{1}'' in {2}", value, configName, location); return ConnectionConfigurationInvalidException.newBuilder(message); } }
@Override protected ConnectionConfigurationInvalidException doBuild(final DittoHeaders dittoHeaders, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new ConnectionConfigurationInvalidException(dittoHeaders, message, description, cause, href); }
private void checkSourceAndTargetAreValid() { if (sources.isEmpty() && targets.isEmpty()) { throw ConnectionConfigurationInvalidException.newBuilder("Either a source or a target must be " + "specified in the configuration of a connection!").build(); } }
private void checkSourceAndTargetAreValid() { if (sources.isEmpty() && targets.isEmpty()) { throw ConnectionConfigurationInvalidException.newBuilder("Either a source or a target must be " + "specified in the configuration of a connection!").build(); } }
private DittoRuntimeExceptionBuilder<ConnectionConfigurationInvalidException> badFormat( final JsonPointer errorLocation, final String label, final String binaryFormat) { final String message = String.format("%s: bad format. " + "Expect PEM-encoded %s data specified by RFC-7468 starting with '-----BEGIN %s-----'", errorLocation.toString(), binaryFormat, label); return ConnectionConfigurationInvalidException.newBuilder(message) .dittoHeaders(dittoHeaders); }
private DittoRuntimeExceptionBuilder<ConnectionConfigurationInvalidException> badFormat( final JsonPointer errorLocation, final String label, final String binaryFormat) { final String message = String.format("%s: bad format. " + "Expect PEM-encoded %s data specified by RFC-7468 starting with '-----BEGIN %s-----'", errorLocation.toString(), binaryFormat, label); return ConnectionConfigurationInvalidException.newBuilder(message) .dittoHeaders(dittoHeaders); }
private static DittoRuntimeException emptyAddressesError(final String location, final DittoHeaders dittoHeaders) { final String message = location + ": addresses may not be empty."; return ConnectionConfigurationInvalidException.newBuilder(message) .dittoHeaders(dittoHeaders) .build(); } }
private static DittoRuntimeException emptyAddressesError(final String location, final DittoHeaders dittoHeaders) { final String message = location + ": addresses may not be empty."; return ConnectionConfigurationInvalidException.newBuilder(message) .dittoHeaders(dittoHeaders) .build(); } }
private static void validateAddress(final String address, final boolean wildcardAllowed, final DittoHeaders dittoHeaders) { validateMqttTopic(address, wildcardAllowed, errorMessage -> { final String message = MessageFormat.format(INVALID_TOPIC_FORMAT, address, errorMessage); return ConnectionConfigurationInvalidException.newBuilder(message) .dittoHeaders(dittoHeaders) .build(); }); }
private static void validateAddress(final String address, final boolean wildcardAllowed, final DittoHeaders dittoHeaders) { validateMqttTopic(address, wildcardAllowed, errorMessage -> { final String message = MessageFormat.format(INVALID_TOPIC_FORMAT, address, errorMessage); return ConnectionConfigurationInvalidException.newBuilder(message) .dittoHeaders(dittoHeaders) .build(); }); }
/** * If no context is set on connection level each target and source must have its own context. */ private void checkAuthorizationContextsAreValid() { // if the auth context on connection level is empty, // an auth context is required to be set on each source/target final Set<String> sourcesWithoutAuthContext = sources.stream() .filter(source -> source.getAuthorizationContext().isEmpty()) .flatMap(source -> source.getAddresses().stream()) .collect(Collectors.toSet()); final Set<String> targetsWithoutAuthContext = targets.stream() .filter(target -> target.getAuthorizationContext().isEmpty()) .map(Target::getAddress) .collect(Collectors.toSet()); if (!sourcesWithoutAuthContext.isEmpty() || !targetsWithoutAuthContext.isEmpty()) { final StringBuilder message = new StringBuilder("The "); if (!sourcesWithoutAuthContext.isEmpty()) { message.append("Sources ").append(sourcesWithoutAuthContext); } if (!sourcesWithoutAuthContext.isEmpty() && !targetsWithoutAuthContext.isEmpty()) { message.append(" and "); } if (!targetsWithoutAuthContext.isEmpty()) { message.append("Targets ").append(targetsWithoutAuthContext); } message.append(" are missing an authorization context."); throw ConnectionConfigurationInvalidException.newBuilder(message.toString()).build(); } }
/** * If no context is set on connection level each target and source must have its own context. */ private void checkAuthorizationContextsAreValid() { // if the auth context on connection level is empty, // an auth context is required to be set on each source/target final Set<String> sourcesWithoutAuthContext = sources.stream() .filter(source -> source.getAuthorizationContext().isEmpty()) .flatMap(source -> source.getAddresses().stream()) .collect(Collectors.toSet()); final Set<String> targetsWithoutAuthContext = targets.stream() .filter(target -> target.getAuthorizationContext().isEmpty()) .map(Target::getAddress) .collect(Collectors.toSet()); if (!sourcesWithoutAuthContext.isEmpty() || !targetsWithoutAuthContext.isEmpty()) { final StringBuilder message = new StringBuilder("The "); if (!sourcesWithoutAuthContext.isEmpty()) { message.append("Sources ").append(sourcesWithoutAuthContext); } if (!sourcesWithoutAuthContext.isEmpty() && !targetsWithoutAuthContext.isEmpty()) { message.append(" and "); } if (!targetsWithoutAuthContext.isEmpty()) { message.append("Targets ").append(targetsWithoutAuthContext); } message.append(" are missing an authorization context."); throw ConnectionConfigurationInvalidException.newBuilder(message.toString()).build(); } }
private <T> String validateTemplate(final String template, final Placeholder<T> placeholder, final DittoHeaders headers, final boolean allowUnresolved) { try { return PlaceholderFilter.validate(template, placeholder, allowUnresolved); } catch (final DittoRuntimeException exception) { throw ConnectionConfigurationInvalidException .newBuilder(MessageFormat.format(ENFORCEMENT_ERROR_MESSAGE, template, placeholder.getClass().getSimpleName())) .cause(exception) .dittoHeaders(headers) .build(); } } }
private <T> String validateTemplate(final String template, final Placeholder<T> placeholder, final DittoHeaders headers, final boolean allowUnresolved) { try { return PlaceholderFilter.validate(template, placeholder, allowUnresolved); } catch (final DittoRuntimeException exception) { throw ConnectionConfigurationInvalidException .newBuilder(MessageFormat.format(ENFORCEMENT_ERROR_MESSAGE, template, placeholder.getClass().getSimpleName())) .cause(exception) .dittoHeaders(headers) .build(); } } }
static RabbitMQTarget fromTargetAddress(final String targetAddress) { final Supplier<DittoRuntimeException> exceptionSupplier = () -> ConnectionConfigurationInvalidException.newBuilder( "The target address '" + targetAddress + "' must be specified " + "in the format 'exchange/routingKey'.") .build(); final String exchange = getExchangeFromTarget(targetAddress).orElseThrow(exceptionSupplier); final String routingKey = getRoutingKeyFromTarget(targetAddress).orElseThrow(exceptionSupplier); return new RabbitMQTarget(exchange, routingKey); }
static RabbitMQTarget fromTargetAddress(final String targetAddress) { final Supplier<DittoRuntimeException> exceptionSupplier = () -> ConnectionConfigurationInvalidException.newBuilder( "The target address '" + targetAddress + "' must be specified " + "in the format 'exchange/routingKey'.") .build(); final String exchange = getExchangeFromTarget(targetAddress).orElseThrow(exceptionSupplier); final String routingKey = getRoutingKeyFromTarget(targetAddress).orElseThrow(exceptionSupplier); return new RabbitMQTarget(exchange, routingKey); }