Skip to content

Commit

Permalink
Fix bad request (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored Mar 21, 2024
1 parent 4805f8c commit 6f573b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public <Req> CompletableFuture<String> sendAsync(
public AwakeableHandle awakeableHandle(String id) {
return new AwakeableHandle() {
@Override
public <T> CompletableFuture<Void> resolve(Serde<T> serde, @NonNull T payload) {
public <T> CompletableFuture<Void> resolveAsync(Serde<T> serde, @NonNull T payload) {
// Prepare request
var reqBuilder =
HttpRequest.newBuilder().uri(URI.create("/restate/awakeables/" + id + "/resolve"));
HttpRequest.newBuilder().uri(baseUri.resolve("/restate/awakeables/" + id + "/resolve"));

// Add content-type
if (serde.contentType() != null) {
Expand Down Expand Up @@ -132,11 +132,11 @@ public <T> CompletableFuture<Void> resolve(Serde<T> serde, @NonNull T payload) {
}

@Override
public CompletableFuture<Void> reject(String reason) {
public CompletableFuture<Void> rejectAsync(String reason) {
// Prepare request
var reqBuilder =
HttpRequest.newBuilder()
.uri(URI.create("/restate/awakeables/" + id + "/reject"))
.uri(baseUri.resolve("/restate/awakeables/" + id + "/reject"))
.header("content-type", "text-plain");

// Add headers
Expand Down
28 changes: 26 additions & 2 deletions sdk-common/src/main/java/dev/restate/sdk/client/IngressClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,44 @@ default <Req> String send(Target target, Serde<Req> reqSerde, Req req) throws In
* ingress
*/
interface AwakeableHandle {
/** Same as {@link #resolve(Serde, Object)} but async. */
<T> CompletableFuture<Void> resolveAsync(Serde<T> serde, @NonNull T payload);

/**
* Complete with success the Awakeable.
*
* @param serde used to serialize the Awakeable result payload.
* @param payload the result payload. MUST NOT be null.
*/
<T> CompletableFuture<Void> resolve(Serde<T> serde, @NonNull T payload);
default <T> void resolve(Serde<T> serde, @NonNull T payload) {
try {
resolveAsync(serde, payload).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e.getCause());
}
}

/** Same as {@link #reject(String)} but async. */
CompletableFuture<Void> rejectAsync(String reason);

/**
* Complete with failure the Awakeable.
*
* @param reason the rejection reason. MUST NOT be null.
*/
CompletableFuture<Void> reject(String reason);
default void reject(String reason) {
try {
rejectAsync(reason).join();
} catch (CompletionException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw new RuntimeException(e.getCause());
}
}
}

static IngressClient defaultClient(String baseUri) {
Expand Down

0 comments on commit 6f573b9

Please sign in to comment.