use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcNoResponse in project besu by hyperledger.
the class JsonRpcExecutor method execute.
public JsonRpcResponse execute(final Optional<User> optionalUser, final Tracer tracer, final Context spanContext, final Supplier<Boolean> alive, final JsonObject jsonRpcRequest, final Function<JsonObject, JsonRpcRequest> requestBodyProvider) {
try {
final JsonRpcRequest requestBody = requestBodyProvider.apply(jsonRpcRequest);
final JsonRpcRequestId id = new JsonRpcRequestId(requestBody.getId());
// Handle notifications
if (requestBody.isNotification()) {
// Notifications aren't handled so create empty result for now.
return new JsonRpcNoResponse();
}
final Span span;
if (tracer != null) {
span = tracer.spanBuilder(requestBody.getMethod()).setSpanKind(SpanKind.INTERNAL).setParent(spanContext).startSpan();
} else {
span = Span.getInvalid();
}
final Optional<JsonRpcError> unavailableMethod = validateMethodAvailability(requestBody);
if (unavailableMethod.isPresent()) {
span.setStatus(StatusCode.ERROR, "method unavailable");
return new JsonRpcErrorResponse(id, unavailableMethod.get());
}
final JsonRpcMethod method = rpcMethods.get(requestBody.getMethod());
return rpcProcessor.process(id, method, span, new JsonRpcRequestContext(requestBody, optionalUser, alive));
} catch (IllegalArgumentException e) {
try {
final Integer id = jsonRpcRequest.getInteger("id", null);
return new JsonRpcErrorResponse(id, INVALID_REQUEST);
} catch (ClassCastException idNotIntegerException) {
return new JsonRpcErrorResponse(null, INVALID_REQUEST);
}
}
}
Aggregations