use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.
the class RskWebSocketJsonRpcHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder msg) {
ByteBuf content = msg.copy().content();
try (ByteBufInputStream source = new ByteBufInputStream(content)) {
final JsonNode jsonNodeRequest = mapper.readTree(source);
RskWebSocketJsonParameterValidator.Result validationResult = parameterValidator.validate(jsonNodeRequest);
RskJsonRpcRequest request = mapper.treeToValue(jsonNodeRequest, RskJsonRpcRequest.class);
JsonRpcResultOrError resultOrError = null;
if (validationResult.isValid()) {
// TODO(mc) we should support the ModuleDescription method filters
resultOrError = request.accept(this, ctx);
} else {
resultOrError = new JsonRpcError(JsonRpcError.INVALID_PARAMS, validationResult.getMessage());
}
JsonRpcIdentifiableMessage response = resultOrError.responseFor(request.getId());
ctx.writeAndFlush(new TextWebSocketFrame(getJsonWithTypedId(jsonNodeRequest, response)));
return;
} catch (IOException e) {
LOGGER.trace("Not a known or valid JsonRpcRequest", e);
// We need to release this resource, netty only takes care about 'ByteBufHolder msg'
content.release(content.refCnt());
}
// delegate to the next handler if the message can't be matched to a known JSON-RPC request
ctx.fireChannelRead(msg);
}
use of co.rsk.rpc.modules.RskJsonRpcRequest in project rskj by rsksmart.
the class JacksonBasedRpcSerializerTest method testIntegerId_then_convertSuccessfully.
@Test
public void testIntegerId_then_convertSuccessfully() throws IOException {
String messageInt = "{\"jsonrpc\": \"2.0\",\"method\": \"eth_subscribe\",\"params\": [\"newHeads\"],\"id\": 64}";
RskJsonRpcRequest requestFromIntId = convertJson(messageInt);
Assert.assertEquals(new Integer(64), requestFromIntId.getId());
}
Aggregations