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 @@ -18,8 +18,22 @@
*/
public interface Endpoint {

/**
* Accepts the given request for further processing.
*
* @param method a request method, may not be <code>null</code>
* @param parameter a request parameter
* @return an instance of CompletableFuture representing the result computed in response to the request.
* May not be <code>null</code>.
*/
CompletableFuture<?> request(String method, Object parameter);

/**
* Accepts the given notification for further processing.
*
* @param method a notification method, may not be <code>null</code>
* @param parameter a notification parameter
*/
void notify(String method, Object parameter);

}
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ protected void handleRequest(RequestMessage requestMessage) {
try {
// Forward the request to the local endpoint
future = localEndpoint.request(requestMessage.getMethod(), requestMessage.getParams());
if (future == null) {
throw new IllegalStateException("Local endpoint returned null from its request method, whereas an instance of CompletableFuture is expected");
}
} catch (Throwable throwable) {
// The local endpoint has failed handling the request - reply with an error response
ResponseError errorObject = exceptionHandler.apply(throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
* Annotation to mark a request method on an interface or class.
* <p>
* A request method must have the return type {@link CompletableFuture} with an
* object parameter type or Void and have zero or one argument.
* object parameter type or Void, and have zero or one argument.
* <p>
* According to jsonrpc an argument must be an 'object' (a java bean, not e,g.
* According to jsonrpc an argument must be an 'object' (a java bean, not e.g. a
* String).
* <p>
* A request method is not allowed to return <code>null</code>.
* <p>
* The name of the jsonrpc request will be the optional segment, followed by the
* name of the Java method that is annotated with JsonRequest. The name of the
* jsonrpc request can be customized by using the {@link #value()} field of this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,35 @@ public CompletableFuture<Object> request(String method, Object parameter) {
logMessages.unregister();
}
}
}

@Test
public void testEndpointReturningNull() {
final var logMessages = new LogMessageAccumulator();
try {
// Don't show the exception in the test execution log
logMessages.registerTo(RemoteEndpoint.class);

final var endp = new TestEndpoint() {
@Override
public CompletableFuture<Object> request(String method, Object parameter) {
return null;
}
};
final var consumer = new TestMessageConsumer();
final var endpoint = new RemoteEndpoint(consumer, endp);

endpoint.consume(init(new RequestMessage(), it -> {
it.setId("1");
it.setMethod("foo");
it.setParams("myparam");
}));

assertEquals("Check some response received", 1, consumer.messages.size());
final var response = (ResponseMessage) consumer.messages.get(0);
assertNotNull("Check response has error", response.getError());
assertEquals(ResponseErrorCode.InternalError.getValue(), response.getError().getCode());
} finally {
logMessages.unregister();
}
}
}
Loading