@Nonnull @Override public String toString() { return getKey(); }
private static void validateMandatoryHeaders(final Map<String, String> headers) { for (final MessageHeaderDefinition mandatoryHeader : MANDATORY_HEADERS) { if (!headers.containsKey(mandatoryHeader.getKey())) { final String msgTemplate = "The headers did not contain a value for mandatory header with key <{0}>!"; throw new IllegalArgumentException(MessageFormat.format(msgTemplate, mandatoryHeader.getKey())); } } }
/** * Returns a new instance of {@code MessageHeadersBuilder}. * * @param direction the direction of the message. * @param thingId the thing ID of the message. * @param subject the subject of the message. * @return the instance. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code thingId} or {@code subject} is empty. * @throws SubjectInvalidException if {@code subject} is invalid. */ public static MessageHeadersBuilder newInstance(final MessageDirection direction, final CharSequence thingId, final CharSequence subject) { checkNotNull(direction, MessageHeaderDefinition.DIRECTION.getKey()); argumentNotEmpty(thingId, MessageHeaderDefinition.THING_ID.getKey()); argumentNotEmpty(subject, MessageHeaderDefinition.SUBJECT.getKey()); final Map<String, String> initialHeaders = new HashMap<>(); initialHeaders.put(MessageHeaderDefinition.DIRECTION.getKey(), direction.toString()); initialHeaders.put(MessageHeaderDefinition.THING_ID.getKey(), thingId.toString()); initialHeaders.put(MessageHeaderDefinition.SUBJECT.getKey(), subject.toString()); return of(initialHeaders); }
/** * Sets the timeout of the Message to build. * * @param timeout the duration of the Message to time out. * @return this builder to allow method chaining. */ public MessageHeadersBuilder timeout(@Nullable final Duration timeout) { final MessageHeaderDefinition definition = MessageHeaderDefinition.TIMEOUT; if (null != timeout) { putCharSequence(definition, String.valueOf(timeout.getSeconds())); } else { removeHeader(definition.getKey()); } return myself; }
/** * Sets the specified URL which is used for message validation. * * @param validationUrl the validation URL to be set. * @return this builder to allow method chaining. * @throws IllegalArgumentException if {@code validationUrl} is empty. */ public MessageHeadersBuilder validationUrl(@Nullable final CharSequence validationUrl) { final MessageHeaderDefinition definition = MessageHeaderDefinition.VALIDATION_URL; if (null != validationUrl) { putCharSequence(definition, validationUrl); } else { removeHeader(definition.getKey()); } return myself; }
/** * Sets the status code of the Message to build. * * @param statusCode the status code. * @return this builder to allow method chaining. */ public MessageHeadersBuilder statusCode(@Nullable final HttpStatusCode statusCode) { final MessageHeaderDefinition definition = MessageHeaderDefinition.STATUS_CODE; if (null != statusCode) { putCharSequence(definition, String.valueOf(statusCode.toInt())); } else { removeHeader(definition.getKey()); } return myself; }
/** * Sets the timestamp of the Message to build. * * @param timestamp the timestamp of the message. * @return this builder to allow method chaining. */ public MessageHeadersBuilder timestamp(@Nullable final OffsetDateTime timestamp) { final MessageHeaderDefinition definition = MessageHeaderDefinition.TIMESTAMP; if (null != timestamp) { putCharSequence(definition, timestamp.toString()); } else { removeHeader(definition.getKey()); } return myself; }
dittoHeadersBuilder.putHeader(THING_ID.getKey(), topicPath.getNamespace() + ":" + topicPath.getId()); dittoHeadersBuilder.putHeader(SUBJECT.getKey(), topicPath.getSubject().orElse("")); adaptable.getPayload().getPath().getDirection().ifPresent(direction -> dittoHeadersBuilder.putHeader(DIRECTION.getKey(), direction.name())); adaptable.getPayload().getPath().getFeatureId().ifPresent(featureId -> dittoHeadersBuilder.putHeader(FEATURE_ID.getKey(), featureId)); adaptable.getPayload().getStatus().ifPresent(statusCode -> dittoHeadersBuilder.putHeader(STATUS_CODE.getKey(), String.valueOf(statusCode.toInt()))); return dittoHeadersBuilder.build(); })
dittoHeadersBuilder.putHeader(THING_ID.getKey(), topicPath.getNamespace() + ":" + topicPath.getId()); dittoHeadersBuilder.putHeader(SUBJECT.getKey(), topicPath.getSubject().orElse("")); adaptable.getPayload().getPath().getDirection().ifPresent(direction -> dittoHeadersBuilder.putHeader(DIRECTION.getKey(), direction.name())); adaptable.getPayload().getPath().getFeatureId().ifPresent(featureId -> dittoHeadersBuilder.putHeader(FEATURE_ID.getKey(), featureId)); adaptable.getPayload().getStatus().ifPresent(statusCode -> dittoHeadersBuilder.putHeader(STATUS_CODE.getKey(), String.valueOf(statusCode.toInt()))); return dittoHeadersBuilder.build(); })