private static void validateJsonArrayValue(final String key, @Nullable final CharSequence value) { final String headerValue = String.valueOf(value); try { final JsonArray jsonArray = JsonFactory.newArray(headerValue); final List<JsonValue> nonStringArrayValues = jsonArray.stream() .filter(jsonValue -> !jsonValue.isString()) .collect(Collectors.toList()); if (!nonStringArrayValues.isEmpty()) { final String msgTemplate = "JSON array for ''{0}'' contained non-String values."; throw DittoHeaderInvalidException.newCustomMessageBuilder(MessageFormat.format(msgTemplate, key)) .build(); } } catch (final JsonParseException e) { throw DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "JSON array").build(); } }
private Builder(final String headerName, final String headerValue, final String headerType) { message(format(MESSAGE_TEMPLATE, requireNonNull(headerValue), requireNonNull(headerName), requireNonNull(headerType))); description(format(DESCRIPTION_TEMPLATE, requireNonNull(headerName), requireNonNull(headerType))); }
/** * Constructs a new {@link DittoHeaderInvalidException} 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 {@link DittoHeaderInvalidException}. * @throws NullPointerException if any argument is {@code null}. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link * JsonFields#MESSAGE} field. */ public static DittoHeaderInvalidException 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 {@link DittoHeaderInvalidException} 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 {@link DittoHeaderInvalidException}. * @throws NullPointerException if any argument is {@code null}. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link * JsonFields#MESSAGE} field. */ public static DittoHeaderInvalidException 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 void validateJsonArrayValue(final String key, @Nullable final CharSequence value) { final String headerValue = String.valueOf(value); try { final JsonArray jsonArray = JsonFactory.newArray(headerValue); final List<JsonValue> nonStringArrayValues = jsonArray.stream() .filter(jsonValue -> !jsonValue.isString()) .collect(Collectors.toList()); if (!nonStringArrayValues.isEmpty()) { final String msgTemplate = "JSON array for ''{0}'' contained non-String values."; throw DittoHeaderInvalidException.newCustomMessageBuilder(MessageFormat.format(msgTemplate, key)) .build(); } } catch (final JsonParseException e) { throw DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "JSON array").build(); } }
private Builder(final String customMessage) { this(); message(customMessage); }
private Builder() { message(DEFAULT_MESSAGE); description(DEFAULT_DESCRIPTION); }
private static void validateBooleanValue(final String key, @Nullable final CharSequence value) { final String headerValue = String.valueOf(value); if (!"true".equals(headerValue) && !"false".equals(headerValue)) { throw DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "boolean").build(); } }
@SuppressWarnings({"ResultOfMethodCallIgnored", "squid:S2201"}) private static void validateLongValue(final String key, @Nullable final CharSequence value) { final String headerValue = String.valueOf(value); try { Long.parseLong(headerValue); } catch (final NumberFormatException e) { throw DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "long").build(); } }
private EntityTag(final boolean weak, final String opaqueTag) { if (!isValid(opaqueTag)) { final String errorMessage = String.format(VALIDATION_ERROR_MESSAGE_TEMPLATE, opaqueTag); throw DittoHeaderInvalidException.newCustomMessageBuilder(errorMessage).build(); } this.weak = weak; this.opaqueTag = opaqueTag; }
private Builder(final String customMessage) { this(); message(customMessage); }
private Builder() { message(DEFAULT_MESSAGE); description(DEFAULT_DESCRIPTION); }
/** * A mutable builder for a {@link DittoHeaderInvalidException} with a custom message. * * @param customMessage the custom message * @return the builder. */ public static DittoHeaderInvalidException.Builder newCustomMessageBuilder(final String customMessage) { return new DittoHeaderInvalidException.Builder(customMessage); }
@SuppressWarnings({"ResultOfMethodCallIgnored", "squid:S2201"}) private static void validateIntegerValue(final String key, @Nullable final CharSequence value) { final String headerValue = String.valueOf(value); try { Integer.parseInt(headerValue); } catch (final NumberFormatException e) { throw DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "int").build(); } }
/** * A mutable builder for a {@link DittoHeaderInvalidException} in case of an invalid type. * * @param headerName the key of the header. * @param headerValue the value of the header. * @param headerType the type of the header. (int, String, entity-tag...) * @return the builder. */ public static DittoHeaderInvalidException.Builder newInvalidTypeBuilder(final String headerName, final String headerValue, final String headerType) { return new DittoHeaderInvalidException.Builder(headerName, headerValue, headerType); }
/** * A mutable builder for a {@link DittoHeaderInvalidException} with a custom message. * * @param customMessage the custom message * @return the builder. */ public static DittoHeaderInvalidException.Builder newCustomMessageBuilder(final String customMessage) { return new DittoHeaderInvalidException.Builder(customMessage); }
/** * A mutable builder for a {@link DittoHeaderInvalidException} in case of an invalid type. * * @param headerName the key of the header. * @param headerValue the value of the header. * @param headerType the type of the header. (int, String, entity-tag...) * @return the builder. */ public static DittoHeaderInvalidException.Builder newInvalidTypeBuilder(final String headerName, final String headerValue, final String headerType) { return new DittoHeaderInvalidException.Builder(headerName, headerValue, headerType); }
private EntityTag(final boolean weak, final String opaqueTag) { if (!isValid(opaqueTag)) { final String errorMessage = String.format(VALIDATION_ERROR_MESSAGE_TEMPLATE, opaqueTag); throw DittoHeaderInvalidException.newCustomMessageBuilder(errorMessage).build(); } this.weak = weak; this.opaqueTag = opaqueTag; }
private static void validateBooleanValue(final String key, @Nullable final CharSequence value) { final String headerValue = String.valueOf(value); if (!"true".equals(headerValue) && !"false".equals(headerValue)) { throw DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "boolean").build(); } }
@SuppressWarnings({"ResultOfMethodCallIgnored", "squid:S2201"}) private static void validateLongValue(final String key, @Nullable final CharSequence value) { final String headerValue = String.valueOf(value); try { Long.parseLong(headerValue); } catch (final NumberFormatException e) { throw DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "long").build(); } }