Search in sources :

Example 96 with JsonNode

use of org.codehaus.jackson.JsonNode in project openhab1-addons by openhab.

the class HueBridge method processPairingResponse.

private boolean processPairingResponse(String response) {
    try {
        JsonNode node = convertToJsonNode(response);
        if (node.has("success")) {
            String userName = node.path("success").path("username").getTextValue();
            logger.info("########################################");
            logger.info("# Hue bridge successfully paired!");
            logger.info("# Please set the following secret in your openhab.cfg (and restart openHAB):");
            logger.info("# " + userName);
            logger.info("########################################");
            return true;
        }
    } catch (IOException e) {
        logger.error("Could not read Settings-Json from Hue Bridge.", e);
    }
    return false;
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException)

Example 97 with JsonNode

use of org.codehaus.jackson.JsonNode in project openhab1-addons by openhab.

the class HueBridge method convertToJsonNode.

private JsonNode convertToJsonNode(String response) throws IOException {
    JsonNode rootNode;
    ObjectMapper mapper = new ObjectMapper();
    JsonNode arrayWrappedNode = mapper.readTree(response);
    // element of the array has to be extracted
    if (arrayWrappedNode.has(0)) {
        rootNode = arrayWrappedNode.get(0);
    } else {
        throw new IOException("Unexpected response from hue bridge (not an array)");
    }
    return rootNode;
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 98 with JsonNode

use of org.codehaus.jackson.JsonNode in project openhab1-addons by openhab.

the class MyqData method login.

/**
     * Validates Username and Password then saved sercurityToken to a variable
     */
private void login() throws InvalidLoginException, IOException {
    logger.trace("attempting to login");
    String url = String.format("%s/api/v4/User/Validate", websiteUrl);
    String message = String.format("{\"username\":\"%s\",\"password\":\"%s\"}", userName, password);
    JsonNode data = request("POST", url, message, "application/json", true);
    LoginData login = new LoginData(data);
    sercurityToken = login.getSecurityToken();
}
Also used : JsonNode(org.codehaus.jackson.JsonNode)

Example 99 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class TransactionIT method should_include_graph_format_when_requested.

@Test
public void should_include_graph_format_when_requested() throws Exception {
    long initialData = countNodes("Foo");
    // given
    http.POST("/db/data/transaction/commit", singleStatement("CREATE (n:Foo:Bar)"));
    // when
    Response response = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'MATCH (n:Foo) RETURN n', 'resultDataContents':['row'," + "'graph'] } ] }"));
    // then
    assertThat(response.status(), equalTo(200));
    JsonNode data = response.get("results").get(0).get("data");
    assertTrue("data is a list", data.isArray());
    assertEquals("one entry", initialData + 1, data.size());
    JsonNode entry = data.get(0);
    assertTrue("entry has row", entry.has("row"));
    assertTrue("entry has graph", entry.has("graph"));
    JsonNode nodes = entry.get("graph").get("nodes"), rels = entry.get("graph").get("relationships");
    assertTrue("nodes is a list", nodes.isArray());
    assertTrue("relationships is a list", rels.isArray());
    assertEquals("one node", 1, nodes.size());
    assertEquals("no relationships", 0, rels.size());
    Set<String> labels = new HashSet<>();
    for (JsonNode node : nodes.get(0).get("labels")) {
        labels.add(node.getTextValue());
    }
    assertEquals("labels", asSet("Foo", "Bar"), labels);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 100 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class TransactionIT method restFormatNodesShouldHaveSensibleUris.

@Test
public void restFormatNodesShouldHaveSensibleUris() throws Throwable {
    // given
    final String hostname = "localhost";
    final String scheme = "http";
    // when
    Response rs = http.POST("/db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'CREATE (n:Foo:Bar) RETURN n', 'resultDataContents':['rest'] } ] }"));
    // then
    JsonNode restNode = rs.get("results").get(0).get("data").get(0).get("rest").get(0);
    assertPath(restNode.get("labels"), "/node/\\d+/labels", hostname, scheme);
    assertPath(restNode.get("outgoing_relationships"), "/node/\\d+/relationships/out", hostname, scheme);
    assertPath(restNode.get("traverse"), "/node/\\d+/traverse/\\{returnType\\}", hostname, scheme);
    assertPath(restNode.get("all_typed_relationships"), "/node/\\d+/relationships/all/\\{-list\\|&\\|types\\}", hostname, scheme);
    assertPath(restNode.get("self"), "/node/\\d+", hostname, scheme);
    assertPath(restNode.get("property"), "/node/\\d+/properties/\\{key\\}", hostname, scheme);
    assertPath(restNode.get("properties"), "/node/\\d+/properties", hostname, scheme);
    assertPath(restNode.get("outgoing_typed_relationships"), "/node/\\d+/relationships/out/\\{-list\\|&\\|types\\}", hostname, scheme);
    assertPath(restNode.get("incoming_relationships"), "/node/\\d+/relationships/in", hostname, scheme);
    assertPath(restNode.get("create_relationship"), "/node/\\d+/relationships", hostname, scheme);
    assertPath(restNode.get("paged_traverse"), "/node/\\d+/paged/traverse/\\{returnType\\}\\{\\?pageSize," + "leaseTime\\}", "localhost", scheme);
    assertPath(restNode.get("all_relationships"), "/node/\\d+/relationships/all", hostname, scheme);
    assertPath(restNode.get("incoming_typed_relationships"), "/node/\\d+/relationships/in/\\{-list\\|&\\|types\\}", hostname, scheme);
}
Also used : Response(org.neo4j.test.server.HTTP.Response) JsonNode(org.codehaus.jackson.JsonNode) Test(org.junit.Test)

Aggregations

JsonNode (org.codehaus.jackson.JsonNode)191 Test (org.junit.Test)51 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)47 IOException (java.io.IOException)39 HashMap (java.util.HashMap)20 ArrayList (java.util.ArrayList)19 HTTP (org.neo4j.test.server.HTTP)18 Resource (com.netflix.simianarmy.Resource)17 AWSResource (com.netflix.simianarmy.aws.AWSResource)17 ObjectNode (org.codehaus.jackson.node.ObjectNode)14 Response (org.neo4j.test.server.HTTP.Response)12 Map (java.util.Map)9 ArrayNode (org.codehaus.jackson.node.ArrayNode)9 RpcException (cz.metacentrum.perun.core.api.exceptions.RpcException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)7 Date (java.util.Date)6 List (java.util.List)6 Description (org.hamcrest.Description)6 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)6