Search in sources :

Example 1 with JsonRpcEntityType

use of org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType in project che by eclipse.

the class JsonRpcMessageReceiver method processObject.

private void processObject(String endpointId, String message) throws JsonRpcException {
    LOG.debug("Processing end object: " + message);
    JsonRpcEntityType type = entityQualifier.qualify(message);
    switch(type) {
        case REQUEST:
            JsonRpcRequest request = jsonRpcFactory.createRequest(message);
            requestDispatcher.dispatch(endpointId, request);
            break;
        case RESPONSE:
            JsonRpcResponse response = jsonRpcFactory.createResponse(message);
            responseDispatcher.dispatch(endpointId, response);
            break;
        case UNDEFINED:
        default:
            String msg = "The JSON sent is not a valid Request object";
            LOG.error(msg);
            throw new JsonRpcException(-32600, msg);
    }
}
Also used : JsonRpcEntityType(org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType)

Example 2 with JsonRpcEntityType

use of org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType in project che by eclipse.

the class JsonRpcEntityQualifierTest method shouldQualifyUndefinedWhenMessageContainsResultAndError.

@Test
public void shouldQualifyUndefinedWhenMessageContainsResultAndError() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("error", "error-value");
    jsonObject.addProperty("result", "result-value");
    JsonRpcEntityType type = qualifier.qualify(jsonObject.toString());
    assertEquals(JsonRpcEntityType.UNDEFINED, type);
}
Also used : JsonRpcEntityType(org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 3 with JsonRpcEntityType

use of org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType in project che by eclipse.

the class JsonRpcEntityQualifierTest method shouldQualifyResponseWhenMessageContainsResult.

@Test
public void shouldQualifyResponseWhenMessageContainsResult() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("result", "result-value");
    JsonRpcEntityType type = qualifier.qualify(jsonObject.toString());
    assertEquals(JsonRpcEntityType.RESPONSE, type);
}
Also used : JsonRpcEntityType(org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 4 with JsonRpcEntityType

use of org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType in project che by eclipse.

the class JsonRpcEntityQualifierTest method shouldQualifyResponseWhenMessageContainsError.

@Test
public void shouldQualifyResponseWhenMessageContainsError() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("error", "error-value");
    JsonRpcEntityType type = qualifier.qualify(jsonObject.toString());
    assertEquals(JsonRpcEntityType.RESPONSE, type);
}
Also used : JsonRpcEntityType(org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 5 with JsonRpcEntityType

use of org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType in project che by eclipse.

the class JsonRpcEntityQualifierTest method shouldQualifyRequestWhenMessageContainsMethod.

@Test
public void shouldQualifyRequestWhenMessageContainsMethod() {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("method", "method-name");
    JsonRpcEntityType type = qualifier.qualify(jsonObject.toString());
    assertEquals(JsonRpcEntityType.REQUEST, type);
}
Also used : JsonRpcEntityType(org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Aggregations

JsonRpcEntityType (org.eclipse.che.api.core.jsonrpc.JsonRpcEntityQualifier.JsonRpcEntityType)6 JsonObject (com.google.gson.JsonObject)5 Test (org.testng.annotations.Test)5