Docs/Server SDKs/Java SDK

Java SDK

com.emitwave:emitwave — a dependency-free server-side SDK that HMAC-signs and publishes events to the gateway.

Server SDK· 3 min read

Install

build.gradle
// Gradle
implementation "com.emitwave:emitwave:0.1.0"

// Maven
// <dependency>
//   <groupId>com.emitwave</groupId>
//   <artifactId>emitwave</artifactId>
//   <version>0.1.0</version>
// </dependency>

Requires Java 11+, an application ID, and an active server credential (public key + one-time secret). No runtime dependencies — it uses java.net.http and javax.crypto from the JDK. Keep the secret on the server — never in client code, public env vars, logs, or API responses.

The key and secret are a server credential, not the browser public application key. For every request the SDK hashes the exact JSON body and signs the method, path, canonical query, and body hash with HMAC-SHA256.

Publish an event

trigger(channel, event, data) serializes the event, signs the body, and sends it to /apps/{appId}/events. The 3-arg Config uses the live gateway; a 4-arg Config(gatewayUrl, appId, key, secret) targets another environment. data may be a Map, List, String, Number, Boolean, or null.

Publish.java
import com.emitwave.Client;
import java.util.Map;

Client client = new Client(new Client.Config(
    "app_...",
    "ew_pk_live_...",   // server credential public key
    "ew_sk_live_..."    // server credential secret
));

client.trigger("orders", "order.created", Map.of("id", "ord_123", "total", 4900));

Error handling

EmitwaveException represents a non-2xx gateway response and carries getStatus() and getBody(); the body never includes your secret.

Errors.java
import com.emitwave.EmitwaveException;

try {
    client.trigger("orders", "order.created", Map.of("id", "ord_123"));
} catch (EmitwaveException e) {
    System.err.println("Emitwave rejected the event " + e.getStatus() + ": " + e.getBody());
}
This SDK publishes the provided JSON as-is. It does not build the ciphertext envelope for a private-encrypted channel — see Encryption.