Skip to content

Commit

Permalink
Merge pull request #42122 from phillip-kruger/chappie-requirements
Browse files Browse the repository at this point in the history
Add support for CompletableFuture when using JsonRPC in Dev UI
  • Loading branch information
phillip-kruger authored Jul 25, 2024
2 parents d283bde + 0b95549 commit 089a116
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ConcurrentHashMap;

import jakarta.enterprise.event.Observes;
Expand Down Expand Up @@ -233,8 +234,22 @@ private void route(JsonRpcRequest jsonRpcRequest, ServerWebSocket s) {
}
} else if (this.jsonRpcToDeploymentClassPathJava.contains(jsonRpcMethodName)) { // Route to extension (deployment)
Object item = DevConsoleManager.invoke(jsonRpcMethodName, getArgsAsMap(jsonRpcRequest));
codec.writeResponse(s, jsonRpcRequest.getId(), item,
MessageType.Response);

// Support for Mutiny is diffcult because we are between the runtime and deployment classpath.
// Supporting something like CompletableFuture that is in the JDK works fine
if (item instanceof CompletionStage) {
CompletionStage<?> future = (CompletionStage) item;
future.thenAccept(r -> {
codec.writeResponse(s, jsonRpcRequest.getId(), r,
MessageType.Response);
}).exceptionally(throwable -> {
codec.writeErrorResponse(s, jsonRpcRequest.getId(), jsonRpcMethodName, throwable);
return null;
});
} else {
codec.writeResponse(s, jsonRpcRequest.getId(), item,
MessageType.Response);
}
} else {
// Method not found
codec.writeMethodNotFoundResponse(s, jsonRpcRequest.getId(), jsonRpcMethodName);
Expand Down

0 comments on commit 089a116

Please sign in to comment.