Skip to content
Merged
Show file tree
Hide file tree
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 @@ -424,8 +424,8 @@ public Mono<Void> sendMessage(JSONRPCMessage message) {
.flatMap(body -> sendHttpPost(messageEndpointUri, body).handle((response, sink) -> {
if (response.statusCode() != 200 && response.statusCode() != 201 && response.statusCode() != 202
&& response.statusCode() != 206) {
sink.error(new RuntimeException(
"Sending message failed with a non-OK HTTP code: " + response.statusCode()));
sink.error(new RuntimeException("Sending message failed with a non-OK HTTP code: "
+ response.statusCode() + " - " + response.body()));
}
else {
sink.next(response);
Expand Down Expand Up @@ -453,15 +453,15 @@ private Mono<String> serializeMessage(final JSONRPCMessage message) {
});
}

private Mono<HttpResponse<Void>> sendHttpPost(final String endpoint, final String body) {
private Mono<HttpResponse<String>> sendHttpPost(final String endpoint, final String body) {
final URI requestUri = Utils.resolveUri(baseUri, endpoint);
final HttpRequest request = this.requestBuilder.copy()
.uri(requestUri)
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();

// TODO: why discard the body?
return Mono.fromFuture(httpClient.sendAsync(request, HttpResponse.BodyHandlers.discarding()));
return Mono.fromFuture(httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ void cleanup() {
container.stop();
}

@Test
void testErrorOnBogusMessage() {
// bogus message
JSONRPCRequest bogusMessage = new JSONRPCRequest(null, null, "test-id", Map.of("key", "value"));

StepVerifier.create(transport.sendMessage(bogusMessage))
.verifyErrorMessage(
"Sending message failed with a non-OK HTTP code: 400 - Invalid message: {\"id\":\"test-id\",\"params\":{\"key\":\"value\"}}");
}

@Test
void testMessageProcessing() {
// Create a test message
Expand Down