List of usage examples for io.vertx.core.json JsonObject getString
public String getString(String key)
From source file:de.fraunhofer.fokus.redistest.DoInterestingThings.java
License:Creative Commons License
/** * transfer hash table from redis into Entry * @param json - JsonObject stored in redis, all fields are of type string * @return Entry/*from w ww. ja va2 s . com*/ */ private JsonObject toEntry(JsonObject json) { Entry entry = new Entry().setHandle(json.getString(Constants.KEY_RECORD_ID)); json.remove(Constants.KEY_RECORD_ID); for (String fn : json.fieldNames()) { switch (fn) { case Constants.KEY_DICE_VALUE: case Constants.KEY_FAMILYNAME: case Constants.KEY_FIRSTNAME: case Constants.KEY_DAY_OF_BIRTH: case Constants.KEY_MONTH_OF_BIRTH: case Constants.KEY_YEAR_OF_BIRTH: case Constants.KEY_PLACE_OF_BIRTH: case Constants.KEY_GENDER: json.put(fn, Double.parseDouble(json.getString(fn))); break; } } return entry.setDiceJson(json); }
From source file:de.neofonie.deployer.DeployerVerticle.java
License:Open Source License
/** * Iterate and deploy verticles/*from w w w. ja va 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:de.openflorian.alarm.AlarmFaxEventMessageCodec.java
License:Open Source License
@Override public AlarmFaxEvent decodeFromWire(int position, Buffer buffer) { // My custom message starting from this *position* of buffer int _pos = position; // Length of JSON int length = buffer.getInt(_pos); String jsonStr = buffer.getString(_pos += 4, _pos += length); JsonObject contentJson = new JsonObject(jsonStr); String fileName = contentJson.getString(JSON_PROPERTY_FILENAME); return new AlarmFaxEvent(new File(fileName)); }
From source file:docoverride.json.Examples.java
License:Open Source License
public void example2(JsonObject jsonObject) { String val = jsonObject.getString("some-key"); int intVal = jsonObject.getInteger("some-other-key"); }
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();// w ww . 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:eu.rethink.mn.component.AllocationManager.java
License:Apache License
@Override public void handle(PipeContext ctx) { final PipeMessage msg = ctx.getMessage(); final JsonObject body = msg.getBody(); if (msg.getType().equals("create")) { //process JSON msg requesting a number of available addresses final JsonObject msgBodyValue = body.getJsonObject("value"); final String scheme = body.getString("scheme"); int number = msgBodyValue.getInteger("number", 5); final List<String> allocated = allocate(ctx, scheme, number); final PipeMessage reply = new PipeMessage(); reply.setId(msg.getId());//from w w w . java 2 s . c o m reply.setFrom(name); reply.setTo(msg.getFrom()); reply.setReplyCode(ReplyCode.OK); final JsonObject value = new JsonObject(); value.put("allocated", new JsonArray(allocated)); reply.getBody().put("value", value); ctx.reply(reply); } else if (msg.getType().equals("delete")) { //process JSON msg releasing an address final String resource = body.getString("resource"); final JsonArray childrenResourcesList = body.getJsonArray("childrenResources"); if (resource != null) { deallocate(ctx, resource); } else { for (Object childrenResource : childrenResourcesList) { deallocate(ctx, childrenResource.toString()); } } ctx.replyOK(name); } }
From source file:eu.rethink.mn.component.ObjectAllocationManager.java
License:Apache License
@Override public void handle(PipeContext ctx) { final PipeMessage msg = ctx.getMessage(); final JsonObject body = msg.getBody(); if (msg.getType().equals("create")) { //process JSON msg requesting a number of available addresses final String scheme = body.getString("scheme"); //on value final JsonObject msgBodyValue = body.getJsonObject("value"); final int number = msgBodyValue.getInteger("number", 5); final List<String> allocated = allocate(ctx, scheme, number); final PipeMessage reply = new PipeMessage(); reply.setId(msg.getId());/*from ww w.j a va 2s. c o m*/ reply.setFrom(name); reply.setTo(msg.getFrom()); reply.setReplyCode(ReplyCode.OK); final JsonObject value = new JsonObject(); value.put("allocated", new JsonArray(allocated)); reply.getBody().put("value", value); ctx.reply(reply); } else if (msg.getType().equals("delete")) { //process JSON msg releasing an address final String resource = body.getString("resource"); deallocate(ctx, resource); ctx.replyOK(name); } }
From source file:eu.rethink.mn.pipeline.handlers.ValidatorPipeHandler.java
License:Apache License
@Override public void handle(PipeContext ctx) { final PipeMessage msg = ctx.getMessage(); //header validation... final JsonObject json = msg.getJson(); if (!json.containsKey("id")) { ctx.fail(NAME, "No mandatory field 'id'"); }// w w w. ja v a2 s . c o m if (!json.containsKey("type")) { ctx.fail(NAME, "No mandatory field 'type'"); } final String from = json.getString("from"); if (from == null) { ctx.fail(NAME, "No mandatory field 'from'"); } final String to = json.getString("to"); if (to == null) { ctx.fail(NAME, "No mandatory field 'to'"); } ctx.next(); }
From source file:fr.wseduc.pages.controllers.PagesController.java
License:Open Source License
@Put("/share/json/:id") @ApiDoc("Share a page.") @SecuredAction(value = "page.manager", type = ActionType.RESOURCE) public void shareSubmit(final HttpServerRequest request) { UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() { @Override// w w w . j ava 2s.co m public void handle(final UserInfos user) { if (user != null) { final String id = request.params().get("id"); if (id == null || id.trim().isEmpty()) { badRequest(request, "invalid.id"); return; } JsonObject params = new JsonObject() .put("uri", "/userbook/annuaire#" + user.getUserId() + "#" + user.getType()) .put("username", user.getUsername()).put("pageUri", "/pages#/website/" + id); params.put("resourceUri", params.getString("pageUri")); JsonObject pushNotif = new JsonObject().put("title", "pages.push.notif.shared").put("body", I18n.getInstance().translate("pages.push.notif.shared.body", getHost(request), I18n.acceptLanguage(request), user.getUsername())); params.put("pushNotif", pushNotif); shareJsonSubmit(request, "pages.shared", false, params, "title"); } } }); }
From source file:fr.wseduc.pages.controllers.PagesController.java
License:Open Source License
@Put("/share/resource/:id") @ApiDoc("Share a page.") @SecuredAction(value = "page.manager", type = ActionType.RESOURCE) public void shareResource(final HttpServerRequest request) { UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() { @Override/*from w w w . j av a 2 s. c om*/ public void handle(final UserInfos user) { if (user != null) { final String id = request.params().get("id"); if (id == null || id.trim().isEmpty()) { badRequest(request, "invalid.id"); return; } JsonObject params = new JsonObject() .put("uri", "/userbook/annuaire#" + user.getUserId() + "#" + user.getType()) .put("username", user.getUsername()).put("pageUri", "/pages#/website/" + id); params.put("resourceUri", params.getString("pageUri")); shareResource(request, "pages.shared", false, params, "title"); } } }); }