List of usage examples for io.vertx.core.json JsonObject put
public JsonObject put(String key, Object value)
From source file:io.nitor.api.backend.PropertiesLauncher.java
License:Apache License
private void override(JsonObject conf, String root) { for (Map.Entry<String, Object> e : conf) { String key = root + e.getKey(); Object value = e.getValue(); if (value instanceof JsonObject) { override((JsonObject) value, key + '.'); return; }/*from w w w . ja v a 2 s. c o m*/ Prop prop = getProp(key); if (prop != null) { conf.put(e.getKey(), convertType(value.getClass(), prop.value)); } } }
From source file:io.nonobot.core.client.impl.BotClientImpl.java
License:Apache License
@Override public void receiveMessage(ReceiveOptions options, String message, Handler<AsyncResult<String>> replyHandler) { String replyAddress = UUID.randomUUID().toString(); Future<String> reply = Future.future(); reply.setHandler(replyHandler);//w w w. j a v a 2 s . co m MessageConsumer<String> consumer = vertx.eventBus().consumer(replyAddress); consumer.handler(msg -> { String content = msg.body(); if (content != null && !reply.isComplete()) { if (msg.replyAddress() != null) { msg.reply(null); } reply.complete(content); consumer.unregister(); } else { if (msg.replyAddress() != null) { msg.fail(0, "Already replied"); } } }); consumer.completionHandler(ar -> { if (ar.succeeded()) { Matcher botMatcher = botPattern.matcher(message); JsonObject msg = new JsonObject().put("replyAddress", replyAddress); msg.put("chatId", options.getChatId()); if (botMatcher.find()) { msg.put("respond", true); msg.put("content", botMatcher.group(1)); } else { msg.put("respond", false); msg.put("content", message); } vertx.eventBus().publish(inboundAddress, msg); vertx.setTimer(options.getTimeout(), timerID -> { if (!reply.isComplete()) { consumer.unregister(); reply.fail(new Exception("timeout")); } }); } else { replyHandler.handle(Future.failedFuture(ar.cause())); } }); }
From source file:io.openshift.booster.CrudApplication.java
License:Apache License
private void updateOne(RoutingContext ctx) { long id = getId(ctx); if (id == -1) { error(ctx, 404, "unknown fruit"); return;/*w w w .ja va 2s .c om*/ } JsonObject item; try { item = ctx.getBodyAsJson(); } catch (RuntimeException e) { error(ctx, 400, "invalid payload"); return; } if (item == null) { error(ctx, 400, "invalid payload"); return; } store.update(id, item).subscribe(() -> ctx.response().putHeader("Content-Type", "application/json") .setStatusCode(200).end(item.put("id", id).encodePrettily()), err -> writeError(ctx, err)); }
From source file:io.openshift.booster.service.impl.JdbcProductStore.java
License:Apache License
@Override public Single<JsonObject> create(JsonObject item) { if (item == null) { return Single.error(new IllegalArgumentException("The item must not be null")); }/*from w ww.j a va 2 s .co m*/ if (item.getString("name") == null || item.getString("name").isEmpty()) { return Single.error(new IllegalArgumentException("The name must not be null or empty")); } if (item.getInteger("stock", 0) < 0) { return Single.error(new IllegalArgumentException("The stock must greater or equal to 0")); } if (item.containsKey("id")) { return Single.error(new IllegalArgumentException("The created item already contains an 'id'")); } return db.rxGetConnection().flatMap(conn -> { JsonArray params = new JsonArray().add(item.getValue("name")).add(item.getValue("stock", 0)); return conn.rxUpdateWithParams(INSERT, params).map(ur -> item.put("id", ur.getKeys().getLong(0))) .doAfterTerminate(conn::close); }); }
From source file:io.reactiverse.pgclient.impl.PgConnectionUriParser.java
License:Apache License
private static void parseUserandPassword(String userInfo, JsonObject configuration) { if (userInfo == null || userInfo.isEmpty()) { return;/*from w w w. j a va 2 s . c o m*/ } if (occurExactlyOnce(userInfo, ":")) { int index = userInfo.indexOf(":"); String user = userInfo.substring(0, index); if (user.isEmpty()) { throw new IllegalArgumentException("Can not only specify the password without a concrete user"); } String password = userInfo.substring(index + 1); configuration.put("user", decodeUrl(user)); configuration.put("password", decodeUrl(password)); } else if (!userInfo.contains(":")) { configuration.put("user", decodeUrl(userInfo)); } else { throw new IllegalArgumentException("Can not use multiple delimiters to delimit user and password"); } }
From source file:io.reactiverse.pgclient.impl.PgConnectionUriParser.java
License:Apache License
private static void parsePort(String portInfo, JsonObject configuration) { if (portInfo == null || portInfo.isEmpty()) { return;/*w ww.j a va 2 s . c o m*/ } int port; try { port = parseInt(decodeUrl(portInfo)); } catch (NumberFormatException e) { throw new IllegalArgumentException("The post must be a valid integer"); } if (port > 65535 || port <= 0) { throw new IllegalArgumentException("The post can only range in 1-65535"); } configuration.put("port", port); }
From source file:io.reactiverse.pgclient.impl.PgConnectionUriParser.java
License:Apache License
private static void parseDatabaseName(String databaseInfo, JsonObject configuration) { if (databaseInfo == null || databaseInfo.isEmpty()) { return;//from w w w .j a v a2 s . c om } configuration.put("database", decodeUrl(databaseInfo)); }
From source file:io.reactiverse.pgclient.impl.PgConnectionUriParser.java
License:Apache License
private static void parseParameters(String parametersInfo, JsonObject configuration) { if (parametersInfo == null || parametersInfo.isEmpty()) { return;/*w w w .j a v a 2 s .co m*/ } for (String parameterPair : parametersInfo.split("&")) { if (parameterPair.isEmpty()) { continue; } int indexOfDelimiter = parameterPair.indexOf("="); if (indexOfDelimiter < 0) { throw new IllegalArgumentException( format("Missing delimiter '=' of parameters \"%s\" in the part \"%s\"", parametersInfo, parameterPair)); } else { String key = parameterPair.substring(0, indexOfDelimiter).toLowerCase(); String value = decodeUrl(parameterPair.substring(indexOfDelimiter + 1).trim()); switch (key) { case "port": parsePort(value, configuration); break; case "host": parseNetLocationValue(value, configuration); break; case "hostaddr": configuration.put("host", value); break; case "user": configuration.put("user", value); break; case "password": configuration.put("password", value); break; case "dbname": configuration.put("database", value); break; case "sslmode": configuration.put("sslMode", SslMode.of(value)); break; default: configuration.put(key, value); break; } } } }
From source file:io.reactiverse.pgclient.impl.PgConnectionUriParser.java
License:Apache License
private static void parseNetLocationValue(String hostValue, JsonObject configuration) { if (isRegardedAsIpv6Address(hostValue)) { configuration.put("host", hostValue.substring(1, hostValue.length() - 1)); } else {/* w w w . j a v a2 s .c o m*/ configuration.put("host", hostValue); } }
From source file:io.rebind.vertx.orientdb.model.ConnectionConverter.java
License:Apache License
public static void toJson(Connection obj, JsonObject json) { if (obj.getLabel() != null) { json.put("label", obj.getLabel()); }//from w w w . ja v a 2s. c om if (obj.getRecord() != null) { json.put("record", obj.getRecord().toJson()); } }