Search in sources :

Example 1 with JsonRpcException

use of com.facebook.stetho.inspector.jsonrpc.JsonRpcException in project stetho by facebook.

the class Database method getDatabaseTableNames.

@ChromeDevtoolsMethod
public JsonRpcResult getDatabaseTableNames(JsonRpcPeer peer, JSONObject params) throws JsonRpcException {
    GetDatabaseTableNamesRequest request = mObjectMapper.convertValue(params, GetDatabaseTableNamesRequest.class);
    String databaseId = request.databaseId;
    DatabaseDriver databaseDriver = getDatabasePeer(databaseId);
    try {
        GetDatabaseTableNamesResponse response = new GetDatabaseTableNamesResponse();
        response.tableNames = databaseDriver.getTableNames(request.databaseId);
        return response;
    } catch (SQLiteException e) {
        throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INVALID_REQUEST, e.toString(), null));
    }
}
Also used : JsonRpcError(com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError) SQLiteException(android.database.sqlite.SQLiteException) JsonRpcException(com.facebook.stetho.inspector.jsonrpc.JsonRpcException) ChromeDevtoolsMethod(com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod)

Example 2 with JsonRpcException

use of com.facebook.stetho.inspector.jsonrpc.JsonRpcException in project stetho by facebook.

the class Runtime method callFunctionOn.

@ChromeDevtoolsMethod
public CallFunctionOnResponse callFunctionOn(JsonRpcPeer peer, JSONObject params) throws JsonRpcException {
    CallFunctionOnRequest args = mObjectMapper.convertValue(params, CallFunctionOnRequest.class);
    Session session = getSession(peer);
    Object object = session.getObjectOrThrow(args.objectId);
    // what this function does by name.
    if (!args.functionDeclaration.startsWith("function protoList(")) {
        throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INTERNAL_ERROR, "Expected protoList, got: " + args.functionDeclaration, null));
    }
    // Since this is really a function call we have to create this fake object to hold the
    // "result" of the function.
    ObjectProtoContainer objectContainer = new ObjectProtoContainer(object);
    RemoteObject result = new RemoteObject();
    result.type = ObjectType.OBJECT;
    result.subtype = ObjectSubType.NODE;
    result.className = object.getClass().getName();
    result.description = getPropertyClassName(object);
    result.objectId = String.valueOf(session.getObjects().putObject(objectContainer));
    CallFunctionOnResponse response = new CallFunctionOnResponse();
    response.result = result;
    response.wasThrown = false;
    return response;
}
Also used : JSONObject(org.json.JSONObject) JsonRpcError(com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError) JsonRpcException(com.facebook.stetho.inspector.jsonrpc.JsonRpcException) ChromeDevtoolsMethod(com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod)

Example 3 with JsonRpcException

use of com.facebook.stetho.inspector.jsonrpc.JsonRpcException 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)

Example 4 with JsonRpcException

use of com.facebook.stetho.inspector.jsonrpc.JsonRpcException in project stetho by facebook.

the class DOM method resolveNode.

@ChromeDevtoolsMethod
public ResolveNodeResponse resolveNode(JsonRpcPeer peer, JSONObject params) throws JsonRpcException {
    final ResolveNodeRequest request = mObjectMapper.convertValue(params, ResolveNodeRequest.class);
    final Object element = mDocument.postAndWait(new UncheckedCallable<Object>() {

        @Override
        public Object call() {
            return mDocument.getElementForNodeId(request.nodeId);
        }
    });
    if (element == null) {
        throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INVALID_PARAMS, "No known nodeId=" + request.nodeId, null));
    }
    int mappedObjectId = Runtime.mapObject(peer, element);
    Runtime.RemoteObject remoteObject = new Runtime.RemoteObject();
    remoteObject.type = Runtime.ObjectType.OBJECT;
    remoteObject.subtype = Runtime.ObjectSubType.NODE;
    remoteObject.className = element.getClass().getName();
    // not a primitive
    remoteObject.value = null;
    // not sure what this does...
    remoteObject.description = null;
    remoteObject.objectId = String.valueOf(mappedObjectId);
    ResolveNodeResponse response = new ResolveNodeResponse();
    response.object = remoteObject;
    return response;
}
Also used : JSONObject(org.json.JSONObject) JsonRpcError(com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError) JsonRpcException(com.facebook.stetho.inspector.jsonrpc.JsonRpcException) ChromeDevtoolsMethod(com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod)

Example 5 with JsonRpcException

use of com.facebook.stetho.inspector.jsonrpc.JsonRpcException in project stetho by facebook.

the class Network method readResponseBody.

private GetResponseBodyResponse readResponseBody(String requestId) throws IOException, JsonRpcException {
    GetResponseBodyResponse response = new GetResponseBodyResponse();
    ResponseBodyData bodyData;
    try {
        bodyData = mResponseBodyFileManager.readFile(requestId);
    } catch (OutOfMemoryError e) {
        throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INTERNAL_ERROR, e.toString(), null));
    }
    response.body = bodyData.data;
    response.base64Encoded = bodyData.base64Encoded;
    return response;
}
Also used : JsonRpcError(com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError) ResponseBodyData(com.facebook.stetho.inspector.network.ResponseBodyData) JsonRpcException(com.facebook.stetho.inspector.jsonrpc.JsonRpcException)

Aggregations

JsonRpcException (com.facebook.stetho.inspector.jsonrpc.JsonRpcException)5 JsonRpcError (com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError)4 ChromeDevtoolsMethod (com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod)3 JSONObject (org.json.JSONObject)3 SQLiteException (android.database.sqlite.SQLiteException)1 JsonRpcRequest (com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcRequest)1 JsonRpcResponse (com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcResponse)1 ResponseBodyData (com.facebook.stetho.inspector.network.ResponseBodyData)1