/** * Returns a new instance of {@code MessageDirection} which is based on the specified map. * * @param headers the header key-value-pairs. * @return the instance. * @throws NullPointerException if {@code headers} is {@code null}. * @throws IllegalArgumentException if {@code headers} contains a value that did not represent its appropriate Java * type or if {@code headers} did lack a mandatory header. * @throws SubjectInvalidException if {@code headers} contains an invalid value for * {@link MessageHeaderDefinition#SUBJECT}. */ static MessageHeaders of(final Map<String, String> headers) { return MessageHeadersBuilder.of(headers).build(); }
/** * Returns a new instance of {@code MessageHeaders} which is based on the specified JSON object. * * @param jsonObject the JSON object representation of message headers. * @return the instance. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws IllegalArgumentException if {@code jsonObject} contains a value that did not represent its appropriate * Java type or if {@code jsonObject} did lack a mandatory header. * @throws SubjectInvalidException if {@code jsonObject} contains an invalid value for * {@link MessageHeaderDefinition#SUBJECT}. */ static MessageHeaders of(final JsonObject jsonObject) { return MessageHeadersBuilder.of(jsonObject).build(); }
private Function<ByteBuffer, MessageCommand<?, ?>> buildSendFeatureMessage(final MessageDirection direction, final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId, final String featureId, final String msgSubject, final Duration timeout) { final HttpRequest httpRequest = ctx.getRequest(); return payload -> { final ContentType contentType = httpRequest.entity() .getContentType(); final MessageHeaders headers = MessageHeaders.newBuilder(direction, thingId, normalizeSubject(msgSubject)) .featureId(featureId) .correlationId(dittoHeaders.getCorrelationId().orElse(null)) .contentType(contentType .toString()) .timeout(timeout) .timestamp(OffsetDateTime.now()) .validationUrl(httpRequest.getHeader(X_DITTO_VALIDATION_URL) .map(HttpHeader::value) .orElse(null)) .putHeaders(dittoHeaders) .build(); final MessageBuilder<Object> messageBuilder = initMessageBuilder(payload, contentType, headers); return SendFeatureMessage.of(thingId, featureId, messageBuilder.build(), enhanceHeaders(dittoHeaders)); }; }
private Function<ByteBuffer, MessageCommand<?, ?>> buildSendClaimMessage(final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId, final Duration timeout) { return payload -> { final ContentType contentType = ctx.getRequest() .entity() .getContentType(); final MessageHeaders headers = MessageHeaders.newBuilderForClaiming(thingId) .correlationId(dittoHeaders.getCorrelationId().orElse(null)) .contentType(contentType.toString()) .timeout(timeout) .timestamp(OffsetDateTime.now()) .putHeaders(dittoHeaders) .build(); final MessageBuilder<Object> messageBuilder = initMessageBuilder(payload, contentType, headers); return SendClaimMessage.of(thingId, messageBuilder.build(), enhanceHeaders(dittoHeaders)); }; }
private Function<ByteBuffer, MessageCommand<?, ?>> buildSendThingMessage(final MessageDirection direction, final RequestContext ctx, final DittoHeaders dittoHeaders, final String thingId, final String msgSubject, final Duration timeout) { return payload -> { final HttpRequest httpRequest = ctx.getRequest(); final ContentType contentType = httpRequest.entity().getContentType(); final MessageHeaders headers = MessageHeaders.newBuilder(direction, thingId, normalizeSubject(msgSubject)) .correlationId(dittoHeaders.getCorrelationId().orElse(null)) .contentType(contentType.toString()) .timeout(timeout) .timestamp(OffsetDateTime.now()) .putHeaders(dittoHeaders) .build(); final MessageBuilder<Object> messageBuilder = initMessageBuilder(payload, contentType, headers); return SendThingMessage.of(thingId, messageBuilder.build(), enhanceHeaders(dittoHeaders)); }; }