use of com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcResponse in project stetho by facebook.
the class ChromeDevtoolsServer method handleRemoteResponse.
private void handleRemoteResponse(JsonRpcPeer peer, JSONObject responseNode) throws MismatchedResponseException {
JsonRpcResponse response = mObjectMapper.convertValue(responseNode, JsonRpcResponse.class);
PendingRequest pendingRequest = peer.getAndRemovePendingRequest(response.id);
if (pendingRequest == null) {
throw new MismatchedResponseException(response.id);
}
if (pendingRequest.callback != null) {
pendingRequest.callback.onResponse(peer, response);
}
}
use of com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcResponse in project stetho by facebook.
the class ChromeDevtoolsServer method handleRemoteRequest.
private void handleRemoteRequest(JsonRpcPeer peer, JSONObject requestNode) throws MessageHandlingException {
JsonRpcRequest request;
request = mObjectMapper.convertValue(requestNode, JsonRpcRequest.class);
JSONObject result = null;
JSONObject error = null;
try {
result = mMethodDispatcher.dispatch(peer, request.method, request.params);
} catch (JsonRpcException e) {
logDispatchException(e);
error = mObjectMapper.convertValue(e.getErrorMessage(), JSONObject.class);
}
if (request.id != null) {
JsonRpcResponse response = new JsonRpcResponse();
response.id = request.id;
response.result = result;
response.error = error;
JSONObject jsonObject = mObjectMapper.convertValue(response, JSONObject.class);
String responseString;
try {
responseString = jsonObject.toString();
} catch (OutOfMemoryError e) {
// JSONStringer can cause an OOM when the Json to handle is too big.
response.result = null;
response.error = mObjectMapper.convertValue(e.getMessage(), JSONObject.class);
jsonObject = mObjectMapper.convertValue(response, JSONObject.class);
responseString = jsonObject.toString();
}
peer.getWebSocket().sendText(responseString);
}
}
Aggregations