Skip to content

Commit

Permalink
java: Move this to after other operations.
Browse files Browse the repository at this point in the history
This make it more consistent with our other libs
  • Loading branch information
svix-mman committed Mar 3, 2025
1 parent 69fdf40 commit 5f4b0a3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
70 changes: 35 additions & 35 deletions java/lib/src/main/java/com/svix/api/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,6 @@ public Message(SvixHttpClient client) {
this.client = client;
}

/**
* Creates a MessageIn with a raw string payload.
*
* <p>The payload is not normalized on the server. Normally, payloads are required to be JSON,
* and Svix will minify the payload before sending the webhooks (for example, by removing
* extraneous whitespace or unnecessarily escaped characters in strings). With this function,
* the payload will be sent "as is", without any minification or other processing.
*
* @param payload Serialized message payload
*/
public static MessageIn messageInRaw(final String payload) {
MessageIn msg = new MessageIn();
msg.setPayload(new HashMap<>());
msg.setTransformationsParams(Collections.singletonMap("rawPayload", payload));
return msg;
}

/**
* Creates a MessageIn with a raw string payload.
*
* <p>This overload is intended for non-JSON payloads.
*
* @param payload Serialized message payload
* @param contentType The value to use for the Content-Type header of the webhook sent by Svix
*/
public static MessageIn messageInRaw(final String payload, final String contentType) {
HashMap<String, Object> trParam = new HashMap<>();
trParam.put("rawPayload", payload);
trParam.put("headers", Collections.singletonMap("content-type", contentType));
MessageIn msg = new MessageIn();
msg.setPayload(new HashMap<>());
msg.setTransformationsParams(trParam);
return msg;
}

/**
* List all of the application's messages.
*
Expand Down Expand Up @@ -237,4 +202,39 @@ public void expungeContent(final String appId, final String msgId)
.encodedPath(String.format("/api/v1/app/%s/msg/%s/content", appId, msgId));
this.client.executeRequest("DELETE", url.build(), null, null, null);
}

/**
* Creates a MessageIn with a raw string payload.
*
* <p>The payload is not normalized on the server. Normally, payloads are required to be JSON,
* and Svix will minify the payload before sending the webhooks (for example, by removing
* extraneous whitespace or unnecessarily escaped characters in strings). With this function,
* the payload will be sent "as is", without any minification or other processing.
*
* @param payload Serialized message payload
*/
public static MessageIn messageInRaw(final String payload) {
MessageIn msg = new MessageIn();
msg.setPayload(new HashMap<>());
msg.setTransformationsParams(Collections.singletonMap("rawPayload", payload));
return msg;
}

/**
* Creates a MessageIn with a raw string payload.
*
* <p>This overload is intended for non-JSON payloads.
*
* @param payload Serialized message payload
* @param contentType The value to use for the Content-Type header of the webhook sent by Svix
*/
public static MessageIn messageInRaw(final String payload, final String contentType) {
HashMap<String, Object> trParam = new HashMap<>();
trParam.put("rawPayload", payload);
trParam.put("headers", Collections.singletonMap("content-type", contentType));
MessageIn msg = new MessageIn();
msg.setPayload(new HashMap<>());
msg.setTransformationsParams(trParam);
return msg;
}
}
12 changes: 5 additions & 7 deletions java/templates/api_resource.java.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ public class {{ resource_type_name }} {
public {{ resource_type_name }}(SvixHttpClient client) {
this.client = client;
}

{% set api_resource_extra -%}
api_extra/{{ resource.name | to_snake_case }}.java
{%- endset %}
{% include api_resource_extra ignore missing %}


{% for op in resource.operations -%}
{% set throws = "throws IOException, ApiException" -%}
{% set res_type = "void" -%}
Expand Down Expand Up @@ -160,4 +153,9 @@ public class {{ resource_type_name }} {
{% set api_operation_extra -%}api_extra/{{ resource.name | to_snake_case }}_{{ op.name | to_snake_case }}.java{% endset %}
{% include api_operation_extra ignore missing %}
{% endfor %}

{% set api_resource_extra -%}
api_extra/{{ resource.name | to_snake_case }}.java
{%- endset %}
{% include api_resource_extra ignore missing %}
}

0 comments on commit 5f4b0a3

Please sign in to comment.