use of com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcRequest in project stetho by facebook.
the class JsonRpcPeer method invokeMethod.
public void invokeMethod(String method, Object paramsObject, @Nullable PendingRequestCallback callback) throws NotYetConnectedException {
Util.throwIfNull(method);
Long requestId = (callback != null) ? preparePendingRequest(callback) : null;
// magic, can basically convert anything for some amount of runtime overhead...
JSONObject params = mObjectMapper.convertValue(paramsObject, JSONObject.class);
JsonRpcRequest message = new JsonRpcRequest(requestId, method, params);
String requestString;
JSONObject jsonObject = mObjectMapper.convertValue(message, JSONObject.class);
requestString = jsonObject.toString();
mPeer.sendText(requestString);
}
use of com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcRequest 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