예제 #1
0
 public static void fromJson(JsonObject json, VertxApiRequest obj) {
   if (json.getValue("apiKey") instanceof String) {
     obj.setApiKey((String) json.getValue("apiKey"));
   }
   if (json.getValue("destination") instanceof String) {
     obj.setDestination((String) json.getValue("destination"));
   }
   if (json.getValue("headers") instanceof JsonObject) {
     HeaderMap map = new HeaderMap();
     json.getJsonObject("headers")
         .forEach(
             entry -> {
               if (entry.getValue() instanceof String)
                 map.put(entry.getKey(), (String) entry.getValue());
             });
     obj.setHeaders(map);
   }
   if (json.getValue("queryParams") instanceof JsonObject) {
     QueryMap map = new QueryMap();
     json.getJsonObject("queryParams")
         .forEach(
             entry -> {
               if (entry.getValue() instanceof String)
                 map.put(entry.getKey(), (String) entry.getValue());
             });
     obj.setQueryParams(map);
   }
   if (json.getValue("rawRequest") instanceof Object) {
     obj.setRawRequest(json.getValue("rawRequest"));
   }
   if (json.getValue("remoteAddr") instanceof String) {
     obj.setRemoteAddr((String) json.getValue("remoteAddr"));
   }
   if (json.getValue("serviceId") instanceof String) {
     obj.setApiId((String) json.getValue("serviceId"));
   }
   if (json.getValue("serviceOrgId") instanceof String) {
     obj.setApiOrgId((String) json.getValue("serviceOrgId"));
   }
   if (json.getValue("serviceVersion") instanceof String) {
     obj.setApiVersion((String) json.getValue("serviceVersion"));
   }
   if (json.getValue("transportSecure") instanceof Boolean) {
     obj.setTransportSecure((Boolean) json.getValue("transportSecure"));
   }
   if (json.getValue("type") instanceof String) {
     obj.setType((String) json.getValue("type"));
   }
 }
  /*
   * TotalDebt = MarginDebt + DfDebt+dfOustandingDebt +accumulatedDepositFee + overdueDepositFee
   */
  public Optional<JsonObject> parse(String json) {
    try {
      final JsonObject body = new JsonObject(json);
      final String type = body.getString(ATDAccountMastKey.MSG_TYPE);
      if (!isATDAccountMastMessage(type)) return Optional.empty();
      System.out.println(body);
      final JsonObject jsonData = body.getJsonObject("data");
      if (jsonData == null) return Optional.empty();
      JsonObject result = new JsonObject();
      result
          .put(ATDAccountMastKey.ACCOUNT, jsonData.getString(ATDAccountMastKey.ACCOUNT))
          .put(
              ATDAccountMastKey.RECEIVING,
              string2Double(jsonData.getString(ATDAccountMastKey.RECEIVING)))
          .put(
              ATDAccountMastKey.BALANCE,
              string2Double(jsonData.getString(ATDAccountMastKey.BALANCE)))
          .put(
              ATDAccountMastKey.TOTALDEBT,
              string2Double(jsonData.getString(ATDAccountMastKey.TOTALDEBT)));
      return Optional.of(result);

    } catch (DecodeException e) {
      LOGGER.error("Cannot decode message to json: ", e);
    }
    return Optional.empty();
  }
  /**
   * Start the deployer.
   *
   * @param startFuture
   */
  @Override
  public void start(final Future<Void> startFuture) {

    // load the deployer.json when available
    JsonObject configuration = this.loadConfiguration();

    if (configuration != null) {

      deployed = new JsonArray();

      // assign loopback to this handler
      vertx.eventBus().localConsumer(LOOPBACK, this::deployVerticle);

      // copy the current verticle configuration
      workingCopy = configuration.getJsonObject(VERTICLES, new JsonObject()).copy();

      // set the global configuration
      globalConfig = configuration.getJsonObject(CONFIG, new JsonObject());

      // start iterations
      vertx
          .eventBus()
          .send(
              LOOPBACK,
              null,
              (AsyncResult<Message<Boolean>> event) -> {
                if (event.succeeded() && event.result().body()) {
                  LOG.log(
                      Level.INFO,
                      "Deployed {0} Verticles: {1}",
                      new Object[] {this.deployed.size(), deployed});
                  startFuture.complete();
                } else {
                  LOG.log(Level.SEVERE, "Deployment stopped: {0}", event.cause().getMessage());
                  startFuture.fail(event.cause());
                }
              });
    } else {
      LOG.info("No deployer.json found on the classpath.");
    }
  }
예제 #4
0
 public static Customer fromJson(JsonObject jsonObject) {
   checkArgument(jsonObject != null);
   return Customer.newBuilder()
       .withId(jsonObject.getString("id"))
       .withFirstname(jsonObject.getString("firstname"))
       .withLastname(jsonObject.getString("lastname"))
       .withTaxNumber(jsonObject.getString("taxnumber"))
       .withTaxCountry(Country.fromJson(jsonObject.getJsonObject("taxCountry")))
       .withAddresses(unmarshal(jsonObject.getJsonArray("addresses"), Address::fromJson))
       .withContacts(unmarshal(jsonObject.getJsonArray("contacts"), Contact::fromJson))
       .build();
 }
예제 #5
0
  private PersistableEvent<? extends SourcedEvent> makePersistableEventFromJson(
      final JsonObject event) {
    Class<? extends SourcedEvent> clazz = null;
    try {
      //noinspection unchecked
      clazz = (Class<? extends SourcedEvent>) Class.forName(event.getString("clazz"));
    } catch (final ClassNotFoundException e) {
      log.warn(e.getMessage());
    }

    return new PersistableEvent<>(clazz, event.getJsonObject("payload").encode());
  }
예제 #6
0
 // Process the failover of a deployment
 private void processFailover(JsonObject failedVerticle) {
   if (failDuringFailover) {
     throw new VertxException("Oops!");
   }
   // This method must block until the failover is complete - i.e. the verticle is successfully
   // redeployed
   final String verticleName = failedVerticle.getString("verticle_name");
   final CountDownLatch latch = new CountDownLatch(1);
   final AtomicReference<Throwable> err = new AtomicReference<>();
   // Now deploy this verticle on this node
   ContextImpl ctx = vertx.getContext();
   if (ctx != null) {
     // We could be on main thread in which case we don't want to overwrite tccl
     ContextImpl.setContext(null);
   }
   JsonObject options = failedVerticle.getJsonObject("options");
   try {
     doDeployVerticle(
         verticleName,
         new DeploymentOptions(options),
         result -> {
           if (result.succeeded()) {
             log.info("Successfully redeployed verticle " + verticleName + " after failover");
           } else {
             log.error("Failed to redeploy verticle after failover", result.cause());
             err.set(result.cause());
           }
           latch.countDown();
           Throwable t = err.get();
           if (t != null) {
             throw new VertxException(t);
           }
         });
   } finally {
     if (ctx != null) {
       ContextImpl.setContext(ctx);
     }
   }
   try {
     if (!latch.await(120, TimeUnit.SECONDS)) {
       throw new VertxException("Timed out waiting for redeploy on failover");
     }
   } catch (InterruptedException e) {
     throw new IllegalStateException(e);
   }
 }
예제 #7
0
  @Override
  public void start(final Future<Void> startedResult) {
    try {
      JsonObject config = config();
      svrConfig = new ObjectMapper().readValue(config.toString(), ServerConfig.class);
      svrConfig.cassandra = config.getJsonObject("cassandra");
    } catch (IOException e) {
      logger.error("Failed to load the server config", e);
      stop();
    }

    // attempt to become the initializer thread
    sharedData = vertx.sharedData().getLocalMap(SHARED_DATA);
    sharedData.putIfAbsent(INITIALIZER_THREAD_KEY, Thread.currentThread().getId());

    Router router = Router.router(vertx);

    // initialize the storage
    JsonCassandraConfigurator configurator = new JsonCassandraConfigurator(vertx);
    session = new DefaultCassandraSession(Cluster.builder(), configurator, vertx);

    // listen for the initialized message, the sending thread receives this also
    EventBusTools.oneShotLocalConsumer(vertx.eventBus(), INITIALIZED_MSG, getStartupHandler());

    if (isInitializerThread()) {
      // initialize the type registry
      try {
        svrConfig.registry = config().getJsonObject("registry");
        registry = new TypeRegistry(svrConfig.registry);
        vertx.eventBus().publish(INITIALIZED_MSG, new JsonObject());
      } catch (Exception e) {
        logger.error("Failed to initialized registry", e);
        stop();
      }
    }
  }
예제 #8
0
 @CodeTranslate
 public void getJsonObject() {
   JsonObject obj = JsonTest.object;
   obj = JsonConverter.fromJsonObject(obj);
   JsonTest.o = obj.getJsonObject("foo").encodePrettily();
 }
예제 #9
0
 @CodeTranslate
 public void getObjectFromIdentifier() throws Exception {
   JsonObject obj = new JsonObject().put("nested", new JsonObject().put("foo", "bar"));
   JsonObject nested = obj.getJsonObject("nested");
   JsonTest.o = JsonConverter.toJsonObject(nested);
 }
 /**
  * Constructor from JSON
  *
  * @param mongoClientUpdateResultJson
  */
 public MongoClientUpdateResult(JsonObject mongoClientUpdateResultJson) {
   docMatched = mongoClientUpdateResultJson.getLong(DOC_MATCHED, DEFAULT_DOCMATCHED);
   docUpsertedId = mongoClientUpdateResultJson.getJsonObject(UPSERTED_ID, null);
   docModified = mongoClientUpdateResultJson.getLong(DOC_MODIFIED, DEFAULT_DOCMODIFIED);
 }