Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly forward websocket errors in DevUIJsonRPCTest #39109

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ private JsonNode objectResultFromJsonRPC(int id) throws InterruptedException, Js
}

private JsonNode objectResultFromJsonRPC(int id, int loopCount) throws InterruptedException, JsonProcessingException {
if (MESSAGES.containsKey(id)) {
String response = MESSAGES.remove(id);
if (RESPONSES.containsKey(id)) {
WebSocketResponse response = RESPONSES.remove(id);
if (response != null) {
ObjectNode json = (ObjectNode) new ObjectMapper().readTree(response);
ObjectNode json = (ObjectNode) new ObjectMapper().readTree(response.message());
JsonNode result = json.get("result");
if (result != null) {
return result.get("object");
Expand Down Expand Up @@ -212,25 +212,48 @@ private int sendRequest(String methodName, Map<String, Object> params) throws IO
socket.frameHandler((e) -> {
Buffer b = accumulatedBuffer.appendBuffer(e.binaryData());
if (e.isFinal()) {
MESSAGES.put(id, b.toString());
RESPONSES.put(id, new WebSocketResponse(b.toString()));
}
});

socket.writeTextMessage(request);

socket.exceptionHandler((e) -> {
e.printStackTrace();
RESPONSES.put(id, new WebSocketResponse(e));
vertx.close();
});
socket.closeHandler(v -> {
vertx.close();
});
} else {
RESPONSES.put(id, new WebSocketResponse(ar.cause()));
vertx.close();
}
});
return id;
}

private static final ConcurrentHashMap<Integer, String> MESSAGES = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<Integer, WebSocketResponse> RESPONSES = new ConcurrentHashMap<>();

private static class WebSocketResponse {
private final String message;
private final Throwable throwable;

public WebSocketResponse(String message) {
this.message = message;
this.throwable = null;
}

public WebSocketResponse(Throwable throwable) {
this.message = null;
this.throwable = throwable;
}

String message() {
if (throwable != null) {
throw new IllegalStateException("Request failed: " + throwable.getMessage(), throwable);
}
return message;
}
}
}
Loading