Search in sources :

Example 1 with JsonRpcError

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

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

use of com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError 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 4 with JsonRpcError

use of com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError 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)4 JsonRpcError (com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError)4 ChromeDevtoolsMethod (com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod)3 JSONObject (org.json.JSONObject)2 SQLiteException (android.database.sqlite.SQLiteException)1 ResponseBodyData (com.facebook.stetho.inspector.network.ResponseBodyData)1