Search in sources :

Example 1 with JsonRpcResponse

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);
    }
}
Also used : JsonRpcResponse(com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcResponse) PendingRequest(com.facebook.stetho.inspector.jsonrpc.PendingRequest)

Example 2 with JsonRpcResponse

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);
    }
}
Also used : JsonRpcResponse(com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcResponse) JsonRpcRequest(com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcRequest) JSONObject(org.json.JSONObject) JsonRpcException(com.facebook.stetho.inspector.jsonrpc.JsonRpcException)

Aggregations

JsonRpcResponse (com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcResponse)2 JsonRpcException (com.facebook.stetho.inspector.jsonrpc.JsonRpcException)1 PendingRequest (com.facebook.stetho.inspector.jsonrpc.PendingRequest)1 JsonRpcRequest (com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcRequest)1 JSONObject (org.json.JSONObject)1