List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:org.eel.kitchen.jsonschema.validator.JsonResolverTest.java
@Test public void multipleDangligRefIsDetected() { JsonNode node;//from w w w . jav a 2 s . c om final ObjectNode schema = factory.objectNode(); node = factory.objectNode().put("$ref", "#/b"); schema.put("a", node); node = factory.objectNode().put("$ref", "#/c"); schema.put("b", node); container = new SchemaContainer(schema); schemaNode = new SchemaNode(container, schema.get("a")); try { resolver.resolve(schemaNode); } catch (JsonSchemaException e) { msg = e.getValidationMessage(); verifyMessageParams(msg, Domain.REF_RESOLVING, "$ref"); assertEquals(msg.getMessage(), "dangling JSON Reference"); assertEquals(msg.getInfo("ref"), factory.textNode("#/c")); } }
From source file:com.almende.pi5.common.agents.GraphAgent.java
@Override protected void onReady() { final ObjectNode config = getConfig(); this.myParentUrl = config.hasNonNull(PARENT_URL_KEY) ? URI.create(config.get(PARENT_URL_KEY).asText()) : null;/*from w w w. j a va 2 s.c o m*/ this.loggerUrl = config.hasNonNull(LOGGER_URL_KEY) ? URI.create(config.get(LOGGER_URL_KEY).asText()) : null; this.sendOffset = config.hasNonNull(SEND_OFFSET_KEY) ? config.get(SEND_OFFSET_KEY).asInt(SEND_OFFSET_DEFAULT) : 0; this.sendInterval = config.hasNonNull(SEND_INTERVAL_KEY) ? config.get(SEND_INTERVAL_KEY).asInt(SEND_INTERVAL_DEFAULT) : 0; repeatUpdateTime(); repeatSendReportOn15(); repeatSendReportOnInterval(); schedule(sendReport, null, DateTime.now().plusMinutes(1)); super.onReady(); }
From source file:com.palominolabs.crm.sf.rest.RestConnectionImpl.java
@Override @Nonnull// ww w.j a v a 2s . c o m public DescribeGlobalResult describeGlobal() throws IOException { Timer.Context context = describeGlobalTimer.time(); String describeGlobalJson; try { describeGlobalJson = this.getHttpApiClient().describeGlobal(); } finally { context.stop(); } ObjectNode objectNode = this.objectReader.withType(ObjectNode.class).readValue(describeGlobalJson); String encoding = objectNode.get("encoding").textValue(); int maxBatchSize = objectNode.get("maxBatchSize").intValue(); ArrayNode descriptionsNode = this.objectReader.withType(ArrayNode.class) .readValue(objectNode.get("sobjects")); Iterator<JsonNode> elements = descriptionsNode.elements(); List<GlobalSObjectDescription> descriptions = Lists.newArrayList(); while (elements.hasNext()) { JsonNode node = elements.next(); descriptions.add(this.objectReader.readValue(node.traverse(), BasicSObjectMetadata.class)); } return new DescribeGlobalResult(encoding, maxBatchSize, descriptions); }
From source file:com.almende.pi5.lch.DERSimAgent.java
public void onReady() { final ObjectNode config = getConfig(); if (config.has("category")) { category = Categories.valueOf(config.get("category").asText()); }//from ww w .java2s . co m if (config.has("maxConsumption")) { maxConsumption = config.get("maxConsumption").asInt(); } if (config.has("maxFlex")) { maxFlex = config.get("maxFlex").asDouble(); } if (config.has("minFlex")) { minFlex = config.get("minFlex").asDouble(); } if (config.has("timespread")) { timespread = new TypeUtil<ArrayList<Timestep>>() { }.inject(config.get("timespread")); } if (config.has("forecastHorizon")) { forecastHorizon = config.get("forecastHorizon").asLong(); } repeatRandomOffset(); super.onReady(); }
From source file:org.gitana.platform.client.tenant.TenantImpl.java
private ResultMap<ObjectNode> toObjects(Response response) { ResultMap<ObjectNode> results = new ResultMapImpl<ObjectNode>(); List<ObjectNode> objects = response.getObjectNodes(); for (ObjectNode object : objects) { String id = object.get("_doc").textValue(); results.put(id, object);/*from w ww . j av a 2 s . co m*/ } return results; }
From source file:samza.examples.rss.system.RssFeed.java
/** * Reads the url and queues the data//from w w w . j av a2 s .co m * * @param feedDetail feedDetails object * @return set of all article urls that were read from the feed * @throws IOException when it cannot connect to the url or the url is malformed * @throws com.sun.syndication.io.FeedException when it cannot reed the feed. */ protected Set<String> queueFeedEntries(FeedDetails feedDetail, List<Datum> dataQueue) throws IOException, FeedException { URL feedUrl = new URL(feedDetail.getUrl()); URLConnection connection = feedUrl.openConnection(); connection.setConnectTimeout(this.timeOut); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new InputStreamReader(connection.getInputStream())); Set<String> batch = Sets.newConcurrentHashSet(); for (Object entryObj : feed.getEntries()) { SyndEntry entry = (SyndEntry) entryObj; ObjectNode nodeEntry = this.serializer.deserialize(entry); nodeEntry.put(RSS_KEY, feedDetail.getUrl()); String entryId = determineId(nodeEntry); batch.add(entryId); Datum datum = new Datum(nodeEntry, entryId, DateTime.now()); JsonNode published = nodeEntry.get(DATE_KEY); if (published != null) { try { DateTime date = RFC3339Utils.parseToUTC(published.asText()); if (date.isAfter(this.publishedSince) && (!seenBefore(entryId, feedDetail.getUrl()))) { dataQueue.add(datum); log.debug("Added entry, {}, to provider queue.", entryId); } } catch (Exception e) { log.trace("Failed to parse date from object node, attempting to add node to queue by default."); if (!seenBefore(entryId, feedDetail.getUrl())) { dataQueue.add(datum); log.debug("Added entry, {}, to provider queue.", entryId); } } } else { log.debug("No published date present, attempting to add node to queue by default."); if (!seenBefore(entryId, feedDetail.getUrl())) { dataQueue.add(datum); log.debug("Added entry, {}, to provider queue.", entryId); } } } return batch; }
From source file:org.agatom.springatom.cmp.action.DefaultActionsModelReader.java
private void setSecurity(final ObjectNode node, final AbstractAction action) { final boolean isSecurityEnabled = node.has("security"); if (isSecurityEnabled) { final JsonNode security = node.get("security"); if (security.size() == 0) { action.disableSecurity();//from ww w .ja v a2 s . c o m return; } boolean authenticated = security.has("authenticated") && security.get("authenticated").asBoolean(false); boolean hasRoles = security.has("roles"); authenticated = authenticated | hasRoles; final ActionSecurityCheck check = new ActionSecurityCheck(); check.setAuthenticated(authenticated); if (hasRoles) { final ActionRoleMap.Connector[] connectors = ActionRoleMap.Connector.values(); final JsonNode roles = security.get("roles"); check.setRoles(this.resolveSecurityRoles(roles, connectors)); } action.setSecurity(check); } else { action.disableSecurity(); } }
From source file:org.apache.streams.rss.provider.RssStreamProviderTask.java
/** * Reads the url and queues the data/* w w w.ja v a 2s . c om*/ * @param feedUrl rss feed url * @return set of all article urls that were read from the feed * @throws IOException when it cannot connect to the url or the url is malformed * @throws FeedException when it cannot reed the feed. */ @VisibleForTesting protected Set<String> queueFeedEntries(URL feedUrl) throws IOException, FeedException { Set<String> batch = Sets.newConcurrentHashSet(); URLConnection connection = feedUrl.openConnection(); connection.setConnectTimeout(this.timeOut); connection.setConnectTimeout(this.timeOut); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new InputStreamReader(connection.getInputStream())); for (Object entryObj : feed.getEntries()) { SyndEntry entry = (SyndEntry) entryObj; ObjectNode nodeEntry = this.serializer.deserialize(entry); nodeEntry.put(RSS_KEY, this.rssFeed); String entryId = determineId(nodeEntry); batch.add(entryId); StreamsDatum datum = new StreamsDatum(nodeEntry); try { JsonNode published = nodeEntry.get(DATE_KEY); if (published != null) { try { DateTime date = RFC3339Utils.parseToUTC(published.asText()); if (date.isAfter(this.publishedSince) && (!this.perpetual || !seenBefore(entryId, this.rssFeed))) { this.dataQueue.put(datum); LOGGER.debug("Added entry, {}, to provider queue.", entryId); } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } catch (Exception e) { LOGGER.trace( "Failed to parse date from object node, attempting to add node to queue by default."); if (!this.perpetual || !seenBefore(entryId, this.rssFeed)) { this.dataQueue.put(datum); LOGGER.debug("Added entry, {}, to provider queue.", entryId); } } } else { LOGGER.debug("No published date present, attempting to add node to queue by default."); if (!this.perpetual || !seenBefore(entryId, this.rssFeed)) { this.dataQueue.put(datum); LOGGER.debug("Added entry, {}, to provider queue.", entryId); } } } catch (InterruptedException ie) { LOGGER.error("Interupted Exception."); Thread.currentThread().interrupt(); } } return batch; }
From source file:com.almende.eve.agent.google.GoogleDirectionsAgent.java
/** * Gets the directions.//ww w. j a v a2 s .c om * * @param origin * the origin * @param destination * the destination * @return the directions * @throws IOException * Signals that an I/O exception has occurred. * @throws InvalidKeyException * the invalid key exception * @throws NoSuchAlgorithmException * the no such algorithm exception * @throws URISyntaxException * the uRI syntax exception */ public ObjectNode getDirections(@Name("origin") final String origin, @Name("destination") final String destination) throws IOException, InvalidKeyException, NoSuchAlgorithmException, URISyntaxException { // TODO: use java API instead of URL fetch? -> I get OVER_QUERY_LIMIT // issues // when deployed. final String url = DIRECTIONS_SERVICE_URL + "?origin=" + URLEncoder.encode(origin, "UTF-8") + "&destination=" + URLEncoder.encode(destination, "UTF-8") // + "&mode=driving" // driving, walking, or bicycling // + "&language=nl" // nl, en, ... + "&sensor=false" // + "&key=" + keyString // TODO: check if adding this key solves the // issue... ; // * Does not work when deployed on google app engine, we need to sign // with key final String response = HttpUtil.get(url); // */ /* * TODO: use url signing * // Convert the string to a URL so we can parse it * System.out.println("key: " + keyString); * * URL u = new URL(url); * String clientID = ... * UrlSigner signer = new UrlSigner(cientId); * String request = u.getProtocol() + "://" + u.getHost() + * signer.signRequest(u.getPath(), u.getQuery()); * * System.out.println("url: " + url); * System.out.println("request: " + request); * * String response = fetch(request); * * System.out.println("response: " + response); * // */ final ObjectMapper mapper = JOM.getInstance(); final ObjectNode directions = mapper.readValue(response, ObjectNode.class); // Check if status is "OK". Error status can for example be "NOT_FOUND" String status = null; if (directions.has("status")) { status = directions.get("status").asText(); } if (!status.equals("OK")) { throw new RuntimeException(status); } return directions; }
From source file:com.joyent.manta.client.multipart.ServerSideMultipartManagerTest.java
public void canCreateCommitRequestBody() throws IOException { MantaMultipartUploadTuple[] unsortedTuples = new MantaMultipartUploadTuple[] { new MantaMultipartUploadTuple(5, new UUID(0L, 5L)), new MantaMultipartUploadTuple(3, new UUID(0L, 3L)), new MantaMultipartUploadTuple(1, new UUID(0L, 1L)), new MantaMultipartUploadTuple(2, new UUID(0L, 2L)), new MantaMultipartUploadTuple(4, new UUID(0L, 4L)) }; Stream<MantaMultipartUploadTuple> partsStream = Arrays.stream(unsortedTuples); byte[] jsonRequest = ServerSideMultipartManager.createCommitRequestBody(partsStream).getLeft(); ObjectNode objectNode = MantaObjectMapper.INSTANCE.readValue(jsonRequest, ObjectNode.class); @SuppressWarnings("unchecked") ArrayNode partsNode = (ArrayNode) objectNode.get("parts"); // Verify that the parts are in the correct order try {/*from ww w. j av a2s . com*/ Assert.assertEquals(partsNode.get(0).textValue(), unsortedTuples[2].getEtag()); Assert.assertEquals(partsNode.get(1).textValue(), unsortedTuples[3].getEtag()); Assert.assertEquals(partsNode.get(2).textValue(), unsortedTuples[1].getEtag()); Assert.assertEquals(partsNode.get(3).textValue(), unsortedTuples[4].getEtag()); Assert.assertEquals(partsNode.get(4).textValue(), unsortedTuples[0].getEtag()); } catch (AssertionError e) { System.err.println(new String(jsonRequest, StandardCharsets.UTF_8)); throw e; } }