/** * 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 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(); } }
/** * Creates a new {@code Target} object from the specified JSON object. Decides which specific {@link Target} * implementation to choose depending on the given {@link ConnectionType}. * * @param jsonObject a JSON object which provides the data for the Target to be created. * @param type the connection type required to decide which iplementation of {@link Source} to choose * @return a new Source Target is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Target targetFromJson(final JsonObject jsonObject, final ConnectionType type) { switch (type) { case AMQP_091: case AMQP_10: return ImmutableTarget.fromJson(jsonObject); case MQTT: return ImmutableMqttTarget.fromJson(jsonObject); default: throw ConnectionConfigurationInvalidException .newBuilder("Unexpected connection type <" + type + ">") .build(); } }
/** * Creates a new {@code Source} object from the specified JSON object. Decides which specific {@link Source} * implementation to choose depending on the given {@link ConnectionType}. * * @param jsonObject a JSON object which provides the data for the Source to be created. * @param index the index to distinguish between sources that would otherwise be different * @param type the connection type required to decide which iplementation of {@link Source} to choose * @return a new Source which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Source sourceFromJson(final JsonObject jsonObject, final int index, final ConnectionType type) { switch (type) { case AMQP_091: case AMQP_10: return ImmutableSource.fromJson(jsonObject, index); case MQTT: return ImmutableMqttSource.fromJson(jsonObject, index); default: throw ConnectionConfigurationInvalidException .newBuilder("Unexpected connection type <" + type + ">") .build(); } }
/** * Creates a new {@code Source} object from the specified JSON object. Decides which specific {@link Source} * implementation to choose depending on the given {@link ConnectionType}. * * @param jsonObject a JSON object which provides the data for the Source to be created. * @param index the index to distinguish between sources that would otherwise be different * @param type the connection type required to decide which iplementation of {@link Source} to choose * @return a new Source which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Source sourceFromJson(final JsonObject jsonObject, final int index, final ConnectionType type) { switch (type) { case AMQP_091: case AMQP_10: return ImmutableSource.fromJson(jsonObject, index); case MQTT: return ImmutableMqttSource.fromJson(jsonObject, index); default: throw ConnectionConfigurationInvalidException .newBuilder("Unexpected connection type <" + type + ">") .build(); } }
/** * Creates a new {@code Target} object from the specified JSON object. Decides which specific {@link Target} * implementation to choose depending on the given {@link ConnectionType}. * * @param jsonObject a JSON object which provides the data for the Target to be created. * @param type the connection type required to decide which iplementation of {@link Source} to choose * @return a new Source Target is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static Target targetFromJson(final JsonObject jsonObject, final ConnectionType type) { switch (type) { case AMQP_091: case AMQP_10: return ImmutableTarget.fromJson(jsonObject); case MQTT: return ImmutableMqttTarget.fromJson(jsonObject); default: throw ConnectionConfigurationInvalidException .newBuilder("Unexpected connection type <" + type + ">") .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); }
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(); } }