List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:org.lendingclub.mercator.bind.BindScanner.java
@SuppressWarnings("unchecked") private void scanRecordSetByZone() { Instant startTime = Instant.now(); List<String> zones = getBindClient().getZones(); Preconditions.checkNotNull(getProjector().getNeoRxClient(), "neorx client must be set"); zones.forEach(zone -> {//from w w w .j a v a 2s . c o m logger.info("Scanning the zone {}", zone); Optional<List> recordsStream = getBindClient().getRecordsbyZone(zone); if (!recordsStream.get().isEmpty()) { logger.info("Found {} records in {} zone", recordsStream.get().size(), zone); recordsStream.get().forEach(record -> { String line = record.toString(); if (!line.startsWith(";")) { ResourceRecordSet<Map<String, Object>> dnsRecord = getRecord(line); ObjectNode recordNode = dnsRecord.toJson(); String cypher = "MATCH (z:BindHostedZone {zoneName:{zone}}) " + "MERGE (m:BindHostedZoneRecord {domainName:{dn}, type:{type}, zoneName:{zone}}) " + "ON CREATE SET m.ttl={ttl}, m.class={class}, m+={props}, m.createTs = timestamp(), m.updateTs=timestamp() " + "ON MATCH SET m+={props}, m.updateTs=timestamp() " + "MERGE (z)-[:CONTAINS]->(m);"; getProjector().getNeoRxClient().execCypher(cypher, "dn", recordNode.get("name").asText(), "type", recordNode.get("type").asText(), "ttl", recordNode.get("ttl").asText(), "class", recordNode.get("class").asText(), "props", recordNode.get("rData"), "zone", zone); } }); } else { logger.error("Failed to obtain any records in {} zone", zone); } }); Instant endTime = Instant.now(); logger.info(" Took {} secs to project Bind records to Neo4j", Duration.between(startTime, endTime).getSeconds()); }
From source file:com.almende.eve.rpc.jsonrpc.JSONRPC.java
/** * Cast a JSONArray or JSONObject params to the desired paramTypes. * /*from w w w . ja v a 2 s.com*/ * @param params * the params * @param annotatedParams * the annotated params * @param requestParams * the request params * @return the object[] */ private static Object[] castParams(final Object realDest, final Object params, final List<AnnotatedParam> annotatedParams, final RequestParams requestParams) { if (annotatedParams.size() == 0) { if (realDest != null) { return new Object[] { realDest }; } else { return new Object[0]; } } if (params instanceof ObjectNode) { // JSON-RPC 2.0 with named parameters in a JSONObject if (annotatedParams.size() == 1 && annotatedParams.get(0).getType().equals(ObjectNode.class) && annotatedParams.get(0).getAnnotations().size() == 0) { // the method expects one parameter of type JSONObject // feed the params object itself to it. if (realDest != null) { return new Object[] { realDest, params }; } else { return new Object[] { params }; } } else { final ObjectNode paramsObject = (ObjectNode) params; int offset = 0; if (realDest != null) { offset = 1; } final Object[] objects = new Object[annotatedParams.size() + offset]; if (realDest != null) { objects[0] = realDest; } for (int i = 0; i < annotatedParams.size(); i++) { final AnnotatedParam p = annotatedParams.get(i); final Annotation a = getRequestAnnotation(p, requestParams); if (a != null) { // this is a systems parameter objects[i + offset] = requestParams.get(a); } else { final String name = getName(p); if (name != null) { // this is a named parameter if (paramsObject.has(name)) { objects[i + offset] = TypeUtil.inject(paramsObject.get(name), p.getGenericType()); } else { if (isRequired(p)) { throw new ClassCastException("Required parameter '" + name + "' missing."); } else if (p.getType().isPrimitive()) { // TODO: should this test be moved to // isAvailable()? throw new ClassCastException( "Parameter '" + name + "' cannot be both optional and " + "a primitive type (" + p.getType().getSimpleName() + ")"); } else { objects[i + offset] = null; } } } else { // this is a problem throw new ClassCastException("Name of parameter " + i + " not defined"); } } } return objects; } } else { throw new ClassCastException("params must be a JSONObject"); } }
From source file:com.almende.eve.transport.xmpp.XmppService.java
@Override public void reconnect(final String agentId) throws IOException { final ArrayNode conns = getConns(agentId); if (conns != null) { for (final JsonNode conn : conns) { final ObjectNode params = (ObjectNode) conn; LOG.info("Initializing connection:" + agentId + " --> " + params); try { final String encryptedUsername = params.has("username") ? params.get("username").textValue() : null;/* w w w. j a v a2 s. c o m*/ final String encryptedPassword = params.has("password") ? params.get("password").textValue() : null; final String encryptedResource = params.has("resource") ? params.get("resource").textValue() : null; if (encryptedUsername != null && encryptedPassword != null) { final String username = EncryptionUtil.decrypt(encryptedUsername); final String password = EncryptionUtil.decrypt(encryptedPassword); String resource = null; if (encryptedResource != null) { resource = EncryptionUtil.decrypt(encryptedResource); } connect(agentId, username, password, resource); } } catch (final Exception e) { throw new IOException("Failed to connect XMPP.", e); } } } }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void putValueSohrt() { ObjectNode parent = new ObjectNode(factory); String name = "foo"; Short value = 123;// ww w . j a v a 2s . c o m parser.putValue(parent, name, value); JsonNode x = parent.get(name); Assert.assertNotNull(x); Assert.assertEquals(value.shortValue(), x.shortValue()); }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void putValueString() { ObjectNode parent = new ObjectNode(factory); String name = "foo"; String value = "bar"; parser.putValue(parent, name, value); JsonNode x = parent.get(name);//from w w w.j a v a 2 s .c o m Assert.assertNotNull(x); Assert.assertEquals(value, x.textValue()); }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void putString() { ObjectNode parent = new ObjectNode(factory); String name = "foo"; String value = "bar"; parser.putString(parent, name, value); JsonNode x = parent.get(name);// ww w . j a v a 2 s . c o m Assert.assertNotNull(x); Assert.assertEquals(value, x.textValue()); }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void putValueLong() { ObjectNode parent = new ObjectNode(factory); String name = "foo"; Long value = 1272722l;//from w w w . j av a 2 s . c o m parser.putValue(parent, name, value); JsonNode x = parent.get(name); Assert.assertNotNull(x); Assert.assertEquals(value.longValue(), x.longValue()); }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void putValueInteger() { ObjectNode parent = new ObjectNode(factory); String name = "foo"; Integer value = 123444;/*from w ww.j a v a 2 s . co m*/ parser.putValue(parent, name, value); JsonNode x = parent.get(name); Assert.assertNotNull(x); Assert.assertEquals(value.intValue(), x.intValue()); }
From source file:com.googlecode.jsonrpc4j.JsonRpcHttpAsyncClient.java
/** * Reads a JSON-PRC response from the server. This blocks until a response * is received.//from www . jav a 2s.c o m * * @param returnType * the expected return type * @param ips * the {@link InputStream} to read from * @return the object returned by the JSON-RPC response * @throws Throwable * on error */ private <T> T readResponse(Type returnType, InputStream ips) throws Throwable { // read the response JsonNode response = mapper.readTree(new NoCloseInputStream(ips)); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "JSON-PRC Response: " + response.toString()); } // bail on invalid response if (!response.isObject()) { throw new JsonRpcClientException(0, "Invalid JSON-RPC response", response); } ObjectNode jsonObject = ObjectNode.class.cast(response); // detect errors if (jsonObject.has("error") && jsonObject.get("error") != null && !jsonObject.get("error").isNull()) { // resolve and throw the exception if (exceptionResolver == null) { throw DefaultExceptionResolver.INSTANCE.resolveException(jsonObject); } else { throw exceptionResolver.resolveException(jsonObject); } } // convert it to a return object if (jsonObject.has("result") && !jsonObject.get("result").isNull() && jsonObject.get("result") != null) { JsonParser returnJsonParser = mapper.treeAsTokens(jsonObject.get("result")); JavaType returnJavaType = TypeFactory.defaultInstance().constructType(returnType); return mapper.readValue(returnJsonParser, returnJavaType); } // no return type return null; }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void putValueBoolean() { ObjectNode parent = new ObjectNode(factory); String name = "foo"; Boolean value = Boolean.TRUE; parser.putValue(parent, name, value); JsonNode x = parent.get(name);/* w ww . j av a 2 s.c o m*/ Assert.assertNotNull(x); Assert.assertEquals(value.booleanValue(), x.booleanValue()); }