diff --git a/java/lib/src/main/java/com/svix/Message.java b/java/lib/src/main/java/com/svix/Message.java index f7922e81c..d224be2dd 100644 --- a/java/lib/src/main/java/com/svix/Message.java +++ b/java/lib/src/main/java/com/svix/Message.java @@ -1,6 +1,9 @@ package com.svix; +import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import com.svix.exceptions.ApiException; import com.svix.internal.api.MessageApi; @@ -16,18 +19,54 @@ public final class Message { api = new MessageApi(); } + private static MessageIn messageInEmptyPayload() { + return new MessageIn() + .payload(Collections.emptyMap()); + } + + /** + * Creates a MessageIn with the payload already being serialized. + * + * The payload is not normalized on the server (usually whitespace outside + * of string literals, unnecessarily escaped characters in string and such + * are fixed up by the server). The default Content-Type of application/json + * is used. See the other overload if you want to send non-JSON payloads. + * + * @param payload Serialized message payload + */ + public static MessageIn messageInRaw(final String payload) { + return messageInEmptyPayload().transformationsParams( + Collections.singletonMap("rawPayload", payload) + ); + } + + /** + * Creates a MessageIn with the payload already being serialized. + * + * This overload is intended for non-JSON payloads. + * + * @param payload Serialized message payload + * @param contentType The value to use for the Content-Type header + */ + public static MessageIn messageInRaw(final String payload, final String contentType) { + HashMap trParam = new HashMap<>(); + trParam.put("rawPayload", payload); + trParam.put("headers", Collections.singletonMap("content-type", contentType)); + return messageInEmptyPayload().transformationsParams(trParam); + } + public ListResponseMessageOut list(final String appId, final MessageListOptions options) throws ApiException { try { return api.v1MessageList( - appId, - options.getLimit(), - options.getIterator(), - options.getChannel(), - options.getBefore(), - options.getAfter(), - options.getWithContent(), - options.getTag(), - new HashSet<>(options.getEventTypes()) + appId, + options.getLimit(), + options.getIterator(), + options.getChannel(), + options.getBefore(), + options.getAfter(), + options.getWithContent(), + options.getTag(), + new HashSet<>(options.getEventTypes()) ); } catch (com.svix.internal.ApiException e) { throw Utils.wrapInternalApiException(e);