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;
}
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;
}
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();
}
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);
}
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);
}
Aggregations