List of usage examples for io.vertx.core.json JsonArray getList
public List getList()
From source file:com.groupon.vertx.utils.MainVerticle.java
License:Apache License
static void registerMessageCodecs(final Vertx vertx, final JsonObject config, final boolean abortOnFailure) throws CodecRegistrationException { final JsonArray messageCodecs = config.getJsonArray(MESSAGE_CODECS_FIELD); if (messageCodecs != null) { for (final Object messageCodecClassNameObject : messageCodecs.getList()) { if (messageCodecClassNameObject instanceof String) { final String messageCodecClassName = (String) messageCodecClassNameObject; try { final MessageCodec<?, ?> messageCodec = (MessageCodec<?, ?>) Class .forName(messageCodecClassName).newInstance(); vertx.eventBus().registerCodec(messageCodec); } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) { log.warn("registerMessageCodecs", "start", new String[] { "message", "messageCodecClassName" }, "Failed to instantiate message codec", messageCodecClassName, e); if (abortOnFailure) { throw new CodecRegistrationException( String.format("Failed to instantiate message codec %s", messageCodecClassName), e);/*from w w w. j av a2 s . c o m*/ } } } else { log.warn("registerMessageCodecs", "start", new String[] { "message", "messageCodecClassName" }, "Ignoring non-string message codec class name", messageCodecClassNameObject); if (abortOnFailure) { throw new CodecRegistrationException("Ignoring non-string message codec class name"); } } } } }
From source file:com.hpe.sw.cms.verticle.WatcherVerticle.java
License:Apache License
private void populateAndSendImage(JsonObject imageObj) { try {// w w w.j a v a 2s. c o m String protocol = config().getString("registry.protocol"); String host = config().getString("registry.host"); httpClient.getAbs(protocol + host + "/v2/" + imageObj.getString("name") + "/manifests/" + imageObj.getString("tag"), new Handler<HttpClientResponse>() { @Override public void handle(HttpClientResponse httpClientResponse) { httpClientResponse.bodyHandler(new Handler<Buffer>() { @Override public void handle(Buffer buffer) { JsonObject maniFestLib = buffer.toJsonObject(); JsonArray signs = maniFestLib.getJsonArray("signatures"); if (signs != null && signs.size() > 0) { StringBuffer fullSign = new StringBuffer(); for (Object sign : signs.getList()) { fullSign.append(((Map) sign).get("signature")).append("|"); } imageObj.put(Image.SIGN, fullSign); imageObj.put(Image.IS_SCANNED, false); imageObj.put(Image.IS_ENRICHED, false); imageObj.put(Image.IS_SCANNED_FAILED, false); if (imageObj.getLong(Image.TIMESTAMP) == null) { imageObj.put(Image.TIMESTAMP, new Date().getTime()); } vertx.eventBus().publish(Events.NEW_IMAGE.name(), imageObj); LOG.info("Event Image with populateSignToImage", imageObj); } } }); } }).end(); } catch (Exception e) { LOG.error("error in populateSignToImage", e); } }
From source file:de.neofonie.deployer.DeployerVerticle.java
License:Open Source License
/** * Iterate and deploy verticles//from w w w .j a v a 2 s.co m */ private void deployVerticle(final Message<JsonObject> event) { // iterate over all candidates to be deployed Set<String> candidates = this.workingCopy.fieldNames(); // detach from underlying json Map<String, JsonObject> initiants = new HashMap<>(); candidates.forEach(id -> { JsonObject info = this.workingCopy.getJsonObject(id); JsonArray dependsOn = info.getJsonArray("dependsOn"); if (dependsOn != null && deployed.getList().containsAll(dependsOn.getList()) || dependsOn == null || dependsOn.isEmpty()) { initiants.put(id, info); } }); // remove the initiants initiants.keySet().forEach(id -> this.workingCopy.remove(id)); // setup latch for the reply CountDownLatch latch = new CountDownLatch(initiants.size()); if (initiants.isEmpty()) { event.reply(Boolean.TRUE); return; } // run over all dependencies initiants.forEach((id, info) -> { // get the name of the verticle String name = info.getString("name"); final JsonObject localConfig = new JsonObject(); localConfig.mergeIn(globalConfig); localConfig.mergeIn(info.getJsonObject("config", new JsonObject())); Handler<AsyncResult<String>> handler = innerEvent -> { if (innerEvent.succeeded()) { // add service to deployed-list deployed.add(id); // re-emit vertx.eventBus().send(LOOPBACK, workingCopy, (AsyncResult<Message<Boolean>> recursiveReply) -> { // always decrease latch latch.countDown(); if (recursiveReply.succeeded() && recursiveReply.result().body()) { if (latch.getCount() == 0) { event.reply(recursiveReply.result().body() & Boolean.TRUE); } } else { event.fail(500, this.getFailure(id, recursiveReply)); } }); } else { event.fail(500, id + " >> " + innerEvent.cause().getMessage()); } }; LOG.log(Level.INFO, "Deploying: ''{0}''", new Object[] { id }); DeploymentOptions deploymentOptions = new DeploymentOptions(info); vertx.deployVerticle(name, deploymentOptions.setConfig(localConfig), handler); }); }
From source file:enmasse.kafka.bridge.converter.JsonMessageConverter.java
License:Apache License
@Override public Message toAmqpMessage(String amqpAddress, ConsumerRecord<String, byte[]> record) { Message message = Proton.message();//from w w w . j av a 2 s. c o m message.setAddress(amqpAddress); // get the root JSON JsonObject json = new JsonObject(new String(record.value())); // get AMQP properties from the JSON JsonObject jsonProperties = json.getJsonObject(JsonMessageConverter.PROPERTIES); if (jsonProperties != null) { for (Entry<String, Object> entry : jsonProperties) { if (entry.getValue() != null) { if (entry.getKey().equals(JsonMessageConverter.MESSAGE_ID)) { message.setMessageId(entry.getValue()); } else if (entry.getKey().equals(JsonMessageConverter.TO)) { message.setAddress(entry.getValue().toString()); } else if (entry.getKey().equals(JsonMessageConverter.SUBJECT)) { message.setSubject(entry.getValue().toString()); } else if (entry.getKey().equals(JsonMessageConverter.REPLY_TO)) { message.setReplyTo(entry.getValue().toString()); } else if (entry.getKey().equals(JsonMessageConverter.CORRELATION_ID)) { message.setCorrelationId(entry.getValue()); } } } } // get AMQP application properties from the JSON JsonObject jsonApplicationProperties = json.getJsonObject(JsonMessageConverter.APPLICATION_PROPERTIES); if (jsonApplicationProperties != null) { Map<Symbol, Object> applicationPropertiesMap = new HashMap<>(); for (Entry<String, Object> entry : jsonApplicationProperties) { applicationPropertiesMap.put(Symbol.valueOf(entry.getKey()), entry.getValue()); } ApplicationProperties applicationProperties = new ApplicationProperties(applicationPropertiesMap); message.setApplicationProperties(applicationProperties); } // put message annotations about partition, offset and key (if not null) Map<Symbol, Object> messageAnnotationsMap = new HashMap<>(); messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_PARTITION_ANNOTATION), record.partition()); messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_OFFSET_ANNOTATION), record.offset()); if (record.key() != null) messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_KEY_ANNOTATION), record.key()); messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_TOPIC_ANNOTATION), record.topic()); // get AMQP message annotations from the JSON JsonObject jsonMessageAnnotations = json.getJsonObject(JsonMessageConverter.MESSAGE_ANNOTATIONS); if (jsonMessageAnnotations != null) { for (Entry<String, Object> entry : jsonMessageAnnotations) { messageAnnotationsMap.put(Symbol.valueOf(entry.getKey()), entry.getValue()); } } MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap); message.setMessageAnnotations(messageAnnotations); // get the AMQP message body from the JSON JsonObject jsonBody = json.getJsonObject(JsonMessageConverter.BODY); if (jsonBody != null) { // type attribtute for following sectin : AMQP value or raw data/binary String type = jsonBody.getString(JsonMessageConverter.SECTION_TYPE); if (type.equals(JsonMessageConverter.SECTION_AMQP_VALUE_TYPE)) { // section is an AMQP value Object jsonSection = jsonBody.getValue(JsonMessageConverter.SECTION); // encoded as String if (jsonSection instanceof String) { message.setBody(new AmqpValue(jsonSection)); // encoded as an array/List } else if (jsonSection instanceof JsonArray) { JsonArray jsonArray = (JsonArray) jsonSection; message.setBody(new AmqpValue(jsonArray.getList())); // encoded as a Map } else if (jsonSection instanceof JsonObject) { JsonObject jsonObject = (JsonObject) jsonSection; message.setBody(new AmqpValue(jsonObject.getMap())); } } else if (type.equals(JsonMessageConverter.SECTION_DATA_TYPE)) { // section is a raw binary data // get the section from the JSON (it's base64 encoded) byte[] value = jsonBody.getBinary(JsonMessageConverter.SECTION); message.setBody(new Data(new Binary(Base64.getDecoder().decode(value)))); } } return message; }
From source file:io.flowly.auth.ExtJwtAuthProvider.java
License:Open Source License
@Override public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) { try {//from ww w. j a v a 2 s.c o m final JsonObject payload = jwt.decode(authInfo.getString("jwt")); final JsonObject options = authInfo.getJsonObject("options", EMPTY_OBJECT); // All dates in JWT are of type NumericDate // a NumericDate is: numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until // the specified UTC date/time, ignoring leap seconds final long now = System.currentTimeMillis() / 1000; if (payload.containsKey("exp") && !options.getBoolean("ignoreExpiration", false)) { if (now >= payload.getLong("exp")) { resultHandler.handle(Future.failedFuture("Expired JWT token: exp <= now")); return; } } if (payload.containsKey("iat")) { Long iat = payload.getLong("iat"); // issue at must be in the past if (iat > now) { resultHandler.handle(Future.failedFuture("Invalid JWT token: iat > now")); return; } } if (payload.containsKey("nbf")) { Long nbf = payload.getLong("nbf"); // not before must be after now if (nbf > now) { resultHandler.handle(Future.failedFuture("Invalid JWT token: nbf > now")); return; } } if (options.containsKey("audience")) { JsonArray audiences = options.getJsonArray("audience", EMPTY_ARRAY); JsonArray target = payload.getJsonArray("aud", EMPTY_ARRAY); if (Collections.disjoint(audiences.getList(), target.getList())) { resultHandler .handle(Future.failedFuture("Invalid JWT audience. expected: " + audiences.encode())); return; } } if (options.containsKey("issuer")) { if (!options.getString("issuer").equals(payload.getString("iss"))) { resultHandler.handle(Future.failedFuture("Invalid JWT issuer")); return; } } resultHandler.handle(Future.succeededFuture(new ExtJwtUser(payload, permissionsClaimKey))); } catch (RuntimeException e) { resultHandler.handle(Future.failedFuture(e)); } }
From source file:io.flowly.auth.manager.BaseManager.java
License:Open Source License
/** * Revoke and grant permissions based on the specification. * Sequence - remove specified permissions, update specified permissions and then add specified permissions. * * @param vertex the node that represents a user or group vertex. * @param jsonObject JSON object representing the user or group permissions. *//* w w w. j a v a 2 s. c o m*/ protected void redoPermissions(Vertex vertex, JsonObject jsonObject) { // Remove permissions. JsonArray permissionsToRemove = jsonObject.getJsonArray(Permission.PERMISSIONS_TO_REMOVE); if (permissionsToRemove != null) { graph.traversal().V(vertex).outE(Schema.E_HAS_PERMISSION).as("e").inV() .has(T.id, P.within(permissionsToRemove.getList().toArray())).<Edge>select("e").drop().toList(); } // Update permissions. JsonArray permissionsToUpdate = jsonObject.getJsonArray(Permission.PERMISSIONS_TO_UPDATE); if (permissionsToUpdate != null) { for (Object prm : permissionsToUpdate) { Permission permission = new Permission((JsonObject) prm); Long resourceVertexId = permission.getResourceVertexId(); graph.traversal().V(vertex).outE(Schema.E_HAS_PERMISSION).as("e").inV().has(T.id, resourceVertexId) .<Edge>select("e").property(Schema.E_P_RWX, permission.getRWX()).toList(); } } // Add permissions. JsonArray permissionsToAdd = jsonObject.getJsonArray(Permission.PERMISSIONS_TO_ADD); if (permissionsToAdd != null) { Set<Long> existingIds = new HashSet<>(); Long[] idsToAdd = new Long[permissionsToAdd.size()]; for (int i = 0; i < permissionsToAdd.size(); i++) { idsToAdd[i] = permissionsToAdd.getJsonObject(i).getLong(Permission.RESOURCE_VERTEX_ID); } graph.traversal().V(vertex).outE(Schema.E_HAS_PERMISSION).inV().has(T.id, P.within(idsToAdd)) .sideEffect(s -> { existingIds.add((Long) s.get().id()); }).toList(); grantPermissions(vertex, permissionsToAdd, existingIds); } }
From source file:io.flowly.auth.manager.BaseManager.java
License:Open Source License
/** * Add and remove users based on the specifications. * Sequence: remove and then add.//from w w w .j a v a 2 s . com * * @param vertex the node that represents a group or user vertex. * @param isOwner indicates if the given vertex is an owner or member. * @param idsToAdd list of ids representing user or group vertices to be added. * @param idsToRemove list of ids representing user or group vertices to be removed. */ protected void redoMemberships(Vertex vertex, boolean isOwner, JsonArray idsToAdd, JsonArray idsToRemove) { if (idsToRemove != null) { graph.traversal().V(vertex).bothE(Schema.E_MEMBER, Schema.E_MEMBER_OF).as("e").otherV() .has(T.id, P.within(idsToRemove.getList().toArray())).<Edge>select("e").drop().toList(); } if (idsToAdd != null) { Set<Long> existingIds = new HashSet<>(); graph.traversal().V(vertex).bothE(isOwner ? Schema.E_MEMBER : Schema.E_MEMBER_OF).otherV() .has(T.id, P.within(idsToAdd.getList().toArray())).sideEffect(s -> { existingIds.add((Long) s.get().id()); }).toList(); grantMemberships(vertex, isOwner, idsToAdd, existingIds); } }
From source file:io.flowly.core.data.FlowInstanceStep.java
License:Open Source License
@SuppressWarnings("unchecked") public List<String> getConnectingObjectIds() { JsonArray connectingObjectIds = getJsonArray(_FLOW_OBJECT_CONNECTING_OBJECT_IDS); return connectingObjectIds != null ? connectingObjectIds.getList() : null; }
From source file:io.mewbase.bson.BsonArray.java
License:Open Source License
/** * Create an instance from a JsonArray// w w w.j ava2 s . c om * * @param jsonArray the JsonArray to create the BsonArray from */ public BsonArray(JsonArray jsonArray) { this.list = jsonArray.getList(); }
From source file:io.rhiot.kafka.bridge.JsonMessageConverter.java
License:Apache License
@Override public Message toAmqpMessage(String amqpAddress, ConsumerRecord<String, byte[]> record) { Message message = Proton.message();//from w w w . jav a2s .c om message.setAddress(amqpAddress); // get the root JSON JsonObject json = new JsonObject(new String(record.value())); // get AMQP properties from the JSON JsonObject jsonProperties = json.getJsonObject(JsonMessageConverter.PROPERTIES); if (jsonProperties != null) { for (Entry<String, Object> entry : jsonProperties) { if (entry.getValue() != null) { if (entry.getKey().equals(JsonMessageConverter.MESSAGE_ID)) { message.setMessageId(entry.getValue()); } else if (entry.getKey().equals(JsonMessageConverter.TO)) { message.setAddress(entry.getValue().toString()); } else if (entry.getKey().equals(JsonMessageConverter.SUBJECT)) { message.setSubject(entry.getValue().toString()); } else if (entry.getKey().equals(JsonMessageConverter.REPLY_TO)) { message.setReplyTo(entry.getValue().toString()); } else if (entry.getKey().equals(JsonMessageConverter.CORRELATION_ID)) { message.setCorrelationId(entry.getValue()); } } } } // get AMQP application properties from the JSON JsonObject jsonApplicationProperties = json.getJsonObject(JsonMessageConverter.APPLICATION_PROPERTIES); if (jsonApplicationProperties != null) { Map<Symbol, Object> applicationPropertiesMap = new HashMap<>(); for (Entry<String, Object> entry : jsonApplicationProperties) { applicationPropertiesMap.put(Symbol.valueOf(entry.getKey()), entry.getValue()); } ApplicationProperties applicationProperties = new ApplicationProperties(applicationPropertiesMap); message.setApplicationProperties(applicationProperties); } // put message annotations about partition, offset and key (if not null) Map<Symbol, Object> messageAnnotationsMap = new HashMap<>(); messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_PARTITION_ANNOTATION), record.partition()); messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_OFFSET_ANNOTATION), record.offset()); if (record.key() != null) messageAnnotationsMap.put(Symbol.valueOf(Bridge.AMQP_KEY_ANNOTATION), record.key()); // get AMQP message annotations from the JSON JsonObject jsonMessageAnnotations = json.getJsonObject(JsonMessageConverter.MESSAGE_ANNOTATIONS); if (jsonMessageAnnotations != null) { for (Entry<String, Object> entry : jsonMessageAnnotations) { messageAnnotationsMap.put(Symbol.valueOf(entry.getKey()), entry.getValue()); } } MessageAnnotations messageAnnotations = new MessageAnnotations(messageAnnotationsMap); message.setMessageAnnotations(messageAnnotations); // get the AMQP message body from the JSON JsonObject jsonBody = json.getJsonObject(JsonMessageConverter.BODY); if (jsonBody != null) { // type attribtute for following sectin : AMQP value or raw data/binary String type = jsonBody.getString(JsonMessageConverter.SECTION_TYPE); if (type.equals(JsonMessageConverter.SECTION_AMQP_VALUE_TYPE)) { // section is an AMQP value Object jsonSection = jsonBody.getValue(JsonMessageConverter.SECTION); // encoded as String if (jsonSection instanceof String) { message.setBody(new AmqpValue(jsonSection)); // encoded as an array/List } else if (jsonSection instanceof JsonArray) { JsonArray jsonArray = (JsonArray) jsonSection; message.setBody(new AmqpValue(jsonArray.getList())); // encoded as a Map } else if (jsonSection instanceof JsonObject) { JsonObject jsonObject = (JsonObject) jsonSection; message.setBody(new AmqpValue(jsonObject.getMap())); } } else if (type.equals(JsonMessageConverter.SECTION_DATA_TYPE)) { // section is a raw binary data // get the section from the JSON (it's base64 encoded) byte[] value = jsonBody.getBinary(JsonMessageConverter.SECTION); message.setBody(new Data(new Binary(Base64.getDecoder().decode(value)))); } } return message; }