コード例 #1
0
 public void handle(Message<JsonObject> msg) {
   try {
     JsonObject json = msg.body();
     String action = msg.headers().get("action");
     if (action == null) {
       throw new IllegalStateException("action not specified");
     }
     accessed();
     switch (action) {
       case "checkin":
         {
           service.checkin(
               (java.lang.String) json.getValue("name"),
               json.getValue("lat") == null ? null : (json.getDouble("lat").doubleValue()),
               json.getValue("lon") == null ? null : (json.getDouble("lon").doubleValue()),
               createHandler(msg));
           break;
         }
       case "getCheckins":
         {
           service.getCheckins(
               res -> {
                 if (res.failed()) {
                   msg.fail(-1, res.cause().getMessage());
                 } else {
                   msg.reply(
                       new JsonArray(
                           res.result()
                               .stream()
                               .map(Checkin::toJson)
                               .collect(Collectors.toList())));
                 }
               });
           break;
         }
       default:
         {
           throw new IllegalStateException("Invalid action: " + action);
         }
     }
   } catch (Throwable t) {
     msg.fail(-1, t.getMessage());
     throw t;
   }
 }
コード例 #2
0
ファイル: JsObject.java プロジェクト: eformat/vertx-codetrans
 @CodeTranslate
 public void getDoubleFromIdentifier() throws Exception {
   JsonObject obj = new JsonObject().put("port", 8080d);
   JsonTest.o = obj.getDouble("port");
 }