protected DittoHeaderInvalidException doBuild(DittoHeaders dittoHeaders, @Nullable String message, @Nullable String description, @Nullable Throwable cause, @Nullable URI href) { return new DittoHeaderInvalidException(dittoHeaders, message, description, cause, href); } }
@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(); } }
/** * 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 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; }
/** * 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 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; }
@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(); } }
protected DittoHeaderInvalidException doBuild(DittoHeaders dittoHeaders, @Nullable String message, @Nullable String description, @Nullable Throwable cause, @Nullable URI href) { return new DittoHeaderInvalidException(dittoHeaders, message, description, cause, href); } }
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 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 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(); } }
private void validateEntityTagMatcher(final String key, @Nullable final CharSequence charSequence) { final String headerValue = String.valueOf(charSequence); if (!EntityTagMatcher.isValid(headerValue)) { final DittoRuntimeExceptionBuilder<DittoHeaderInvalidException> exceptionBuilder = DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "entity-tag"); try { exceptionBuilder.href(new URI(RFC_7232_SECTION_2_3)); } catch (final URISyntaxException e) { // Do nothing. If this happens, there is no href appended to the exception builder. } throw exceptionBuilder.build(); } }
private void validateEntityTag(final String key, @Nullable final CharSequence charSequence) { final String headerValue = String.valueOf(charSequence); if (!EntityTag.isValid(headerValue)) { final DittoRuntimeExceptionBuilder<DittoHeaderInvalidException> exceptionBuilder = DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "entity-tag"); try { exceptionBuilder.href(new URI(RFC_7232_SECTION_2_3)); } catch (final URISyntaxException e) { // Do nothing. If this happens, there is no href appended to the exception builder. } throw exceptionBuilder.build(); } } }
private void validateEntityTagMatcher(final String key, @Nullable final CharSequence charSequence) { final String headerValue = String.valueOf(charSequence); if (!EntityTagMatcher.isValid(headerValue)) { final DittoRuntimeExceptionBuilder<DittoHeaderInvalidException> exceptionBuilder = DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "entity-tag"); try { exceptionBuilder.href(new URI(RFC_7232_SECTION_2_3)); } catch (final URISyntaxException e) { // Do nothing. If this happens, there is no href appended to the exception builder. } throw exceptionBuilder.build(); } }
private void validateEntityTag(final String key, @Nullable final CharSequence charSequence) { final String headerValue = String.valueOf(charSequence); if (!EntityTag.isValid(headerValue)) { final DittoRuntimeExceptionBuilder<DittoHeaderInvalidException> exceptionBuilder = DittoHeaderInvalidException.newInvalidTypeBuilder(key, headerValue, "entity-tag"); try { exceptionBuilder.href(new URI(RFC_7232_SECTION_2_3)); } catch (final URISyntaxException e) { // Do nothing. If this happens, there is no href appended to the exception builder. } throw exceptionBuilder.build(); } } }