Search in sources :

Example 1 with RpcMethodTimeoutException

use of org.hyperledger.besu.ethereum.api.handlers.RpcMethodTimeoutException in project besu by hyperledger.

the class WebSocketRequestHandler method process.

private JsonRpcResponse process(final Optional<AuthenticationService> authenticationService, final ServerWebSocket websocket, final Optional<User> user, final WebSocketRpcRequest requestBody, final Collection<String> noAuthApiMethods) {
    if (!methods.containsKey(requestBody.getMethod())) {
        LOG.debug("Can't find method {}", requestBody.getMethod());
        return new JsonRpcErrorResponse(requestBody.getId(), JsonRpcError.METHOD_NOT_FOUND);
    }
    final JsonRpcMethod method = methods.get(requestBody.getMethod());
    try {
        LOG.debug("WS-RPC request -> {}", requestBody.getMethod());
        requestBody.setConnectionId(websocket.textHandlerID());
        if (authenticationService.isEmpty() || (authenticationService.isPresent() && authenticationService.get().isPermitted(user, method, noAuthApiMethods))) {
            final JsonRpcRequestContext requestContext = new JsonRpcRequestContext(requestBody, user, new IsAliveHandler(ethScheduler, timeoutSec));
            return method.response(requestContext);
        } else {
            return new JsonRpcUnauthorizedResponse(requestBody.getId(), JsonRpcError.UNAUTHORIZED);
        }
    } catch (final InvalidJsonRpcParameters e) {
        LOG.debug("Invalid Params", e);
        return new JsonRpcErrorResponse(requestBody.getId(), JsonRpcError.INVALID_PARAMS);
    } catch (final RpcMethodTimeoutException e) {
        LOG.error(JsonRpcError.TIMEOUT_ERROR.getMessage(), e);
        return new JsonRpcErrorResponse(requestBody.getId(), JsonRpcError.TIMEOUT_ERROR);
    } catch (final Exception e) {
        LOG.error(JsonRpcError.INTERNAL_ERROR.getMessage(), e);
        return new JsonRpcErrorResponse(requestBody.getId(), JsonRpcError.INTERNAL_ERROR);
    }
}
Also used : JsonRpcUnauthorizedResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcUnauthorizedResponse) IsAliveHandler(org.hyperledger.besu.ethereum.api.handlers.IsAliveHandler) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) RpcMethodTimeoutException(org.hyperledger.besu.ethereum.api.handlers.RpcMethodTimeoutException) JsonRpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod) InvalidJsonRpcParameters(org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters) DecodeException(io.vertx.core.json.DecodeException) RpcMethodTimeoutException(org.hyperledger.besu.ethereum.api.handlers.RpcMethodTimeoutException) IOException(java.io.IOException) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Aggregations

DecodeException (io.vertx.core.json.DecodeException)1 IOException (java.io.IOException)1 IsAliveHandler (org.hyperledger.besu.ethereum.api.handlers.IsAliveHandler)1 RpcMethodTimeoutException (org.hyperledger.besu.ethereum.api.handlers.RpcMethodTimeoutException)1 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)1 InvalidJsonRpcParameters (org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters)1 JsonRpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod)1 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)1 JsonRpcUnauthorizedResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcUnauthorizedResponse)1