diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketMessageHandler.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketMessageHandler.java index 3f4995d7abd0..d88f6cba8e5d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketMessageHandler.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/websocket/WebSocketMessageHandler.java @@ -31,6 +31,7 @@ import java.util.Optional; import com.fasterxml.jackson.core.JsonGenerator.Feature; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @@ -46,6 +47,10 @@ public class WebSocketMessageHandler { + private static final ObjectMapper jsonObjectMapper = + new ObjectMapper() + .registerModule(new Jdk8Module()); // Handle JDK8 Optionals (de)serialization + private static final Logger LOG = LoggerFactory.getLogger(WebSocketMessageHandler.class); private static final ObjectWriter JSON_OBJECT_WRITER = new ObjectMapper() @@ -161,6 +166,7 @@ public void handle( } private void replyToClient(final ServerWebSocket websocket, final Object result) { + traceResponse(result); try { // underlying output stream lifecycle is managed by the json object writer JSON_OBJECT_WRITER.writeValue(new JsonResponseStreamer(websocket), result); @@ -172,4 +178,12 @@ private void replyToClient(final ServerWebSocket websocket, final Object result) private JsonRpcResponse errorResponse(final Object id, final RpcErrorType error) { return new JsonRpcErrorResponse(id, error); } + + private void traceResponse(final Object response) { + try { + LOG.trace(jsonObjectMapper.writeValueAsString(response)); + } catch (JsonProcessingException e) { + LOG.error("Error tracing JSON-RPC response", e); + } + } }