Example usage for io.vertx.core.json JsonObject getBoolean

List of usage examples for io.vertx.core.json JsonObject getBoolean

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject getBoolean.

Prototype

public Boolean getBoolean(String key, Boolean def) 

Source Link

Document

Like #getBoolean(String) but specifying a default value to return if there is no entry.

Usage

From source file:com.github.ithildir.airbot.GeoServiceVerticle.java

License:Open Source License

@Override
protected GeoService getServiceImpl(JsonObject configJsonObject) {
    String key = configJsonObject.getString(ConfigKeys.MAPQUEST_KEY);
    boolean open = configJsonObject.getBoolean(ConfigKeys.MAPQUEST_OPEN, _DEFAULT_MAPQUEST_OPEN);

    return new MapQuestGeoServiceImpl(vertx, key, open);
}

From source file:com.groupon.vertx.redis.RedisCommandHandler.java

License:Apache License

/**
 * This handles the incoming Redis command JSON.
 *
 * @param command - The JsonObject containing the commands to send to Redis.
 *///from  ww  w  .  ja  v a 2 s  .co  m
public void handle(final Message<JsonObject> command) {
    if (command.body() == null || command.body().size() == 0) {
        log.warn("handleCommand", "failure", new String[] { "reason" }, "Missing message body");
        command.reply(buildReply("error", null, "Invalid message with null or empty."));
        return;
    }

    JsonObject inputJson = command.body();
    boolean isMulti = inputJson.getBoolean("isTransaction", false);
    JsonArray commands = inputJson.getJsonArray("commands", new JsonArray());
    if (commands.size() > 0) {
        LinkedList<RedisCommand> transactionRedisCommands = new LinkedList<>();
        for (Object jsonCommand : commands) {
            RedisCommand redisCommand = getRedisCommand((JsonObject) jsonCommand, command, isMulti);
            if (redisCommand == null) {
                log.warn("handleCommand", "failure", new String[] { "reason" }, "Invalid redis command");
                command.reply(buildReply("error", null, "Invalid redis command"));
                return;
            }
            transactionRedisCommands.add(redisCommand);
        }
        if (isMulti) { //Wrap it with a  MULTI and EXEC block
            transactionRedisCommands.addFirst(new RedisCommand(RedisCommandType.MULTI, null));
            transactionRedisCommands.addLast(new RedisCommand(RedisCommandType.EXEC, null));
            setCommandResponseHandler(Collections.singletonList(transactionRedisCommands.getLast()), command,
                    isMulti);
        } else {
            setCommandResponseHandler(transactionRedisCommands, command, isMulti);
        }
        socket.sendCommand(transactionRedisCommands);
    } else {
        log.warn("handleCommand", "failure", new String[] { "reason" }, "Missing commands");
        command.reply(buildReply("error", null, "Invalid message with no commands"));
    }
}

From source file:com.groupon.vertx.utils.config.VerticleConfig.java

License:Apache License

public VerticleConfig(String name, JsonObject deployConfig) {

    if (name == null) {
        throw new IllegalStateException("Field `name` not specified for verticle");
    }//from   w  w  w.  jav a 2 s  .c  om

    if (deployConfig == null) {
        throw new IllegalStateException(String.format("Verticle %s config cannot be null", name));
    }

    this.name = name;
    final Object instancesAsObject = deployConfig.getValue("instances");
    if (instancesAsObject instanceof Integer) {
        instances = (Integer) instancesAsObject;
    } else if (instancesAsObject instanceof String) {
        instances = parseInstances((String) instancesAsObject);
    } else {
        throw new ClassCastException("Unsupported class type for 'instances'");
    }
    className = deployConfig.getString("class");
    config = deployConfig.getValue("config");
    isWorker = deployConfig.getBoolean("worker", false);
    isMultiThreaded = deployConfig.getBoolean("multiThreaded", false);

    JsonArray dependencyJson = deployConfig.getJsonArray("dependencies");
    if (dependencyJson != null) {
        dependencies = new HashSet<>(dependencyJson.size());
        for (Object dep : dependencyJson) {
            if (dep instanceof String) {
                dependencies.add((String) dep);
            }
        }
    } else {
        dependencies = Collections.emptySet();
    }

    if (instances < 1) {
        throw new IllegalStateException(
                String.format("Field `instances` not specified or less than 1 for verticle %s", name));
    }

    if (className == null) {
        throw new IllegalStateException(
                String.format("Field `className` not specified for for verticle %s", name));
    }
}

From source file:com.groupon.vertx.utils.MainVerticle.java

License:Apache License

/**
 * @param startedResult future indicating when all verticles have been deployed successfully
 */// www  . jav a 2 s.co m
@Override
public void start(final Future<Void> startedResult) {
    final JsonObject config = config();
    final boolean abortOnFailure = config.getBoolean(ABORT_ON_FAILURE_FIELD, true);

    try {
        registerMessageCodecs(vertx, config, abortOnFailure);
    } catch (final CodecRegistrationException e) {
        log.error("start", "abort", "Shutting down due to one or more errors", e);
        vertx.close();
        return;
    }

    Future<Void> deployResult = deployVerticles(config);
    deployResult.setHandler(new AsyncResultHandler<Void>() {
        @Override
        public void handle(AsyncResult<Void> result) {
            if (result.succeeded()) {
                startedResult.complete(null);
            } else {
                if (abortOnFailure) {
                    log.warn("start", "abort", new String[] { "message" },
                            "Shutting down due to one or more errors");
                    vertx.close();
                } else {
                    startedResult.fail(result.cause());
                }
            }
        }
    });
}

From source file:de.fraunhofer.fokus.redistest.Query.java

License:Creative Commons License

/**
 * Constructor for a Query object/*ww  w  . j a v a 2 s  .  c  o m*/
 * @param json - JosonObject, a JSON representation of a Query object
 * @param issuer
 */
public Query(JsonObject json, String issuer) {
    familyName = NameHelper.toStringArray(json.getJsonArray("familyName", null));
    firstName = NameHelper.toStringArray(json.getJsonArray("firstName", null));
    placeOfBirth = json.getString("placeOfBirth", null);
    yearOfBirth = DateQuery.toDateQuery(json.getJsonObject("yearOfBirth", null));
    monthOfBirth = DateQuery.toDateQuery(json.getJsonObject("monthOfBirth", null));
    dayOfBirth = DateQuery.toDateQuery(json.getJsonObject("dayOfBirth", null));
    gender = json.getString("gender", null);
    JsonArray tmp = json.getJsonArray("familyNameFltr");
    if (tmp != null) {
        familyNameFltr = NameHelper.toStringArray(tmp);
    }
    tmp = json.getJsonArray("firstNameFltr");
    if (tmp != null) {
        firstNameFltr = NameHelper.toStringArray(tmp);
    }
    String stmp = json.getString("placeOfBirthFltr");
    if (stmp != null) {
        placeOfBirthFltr = stmp;
    }
    this.issuer = issuer;
    pseudonymized = json.getBoolean("pseudonymized", false);

}

From source file:fr.wseduc.rack.controllers.RackController.java

License:Open Source License

private void updateUserQuota(final String userId, long size) {
    JsonObject message = new JsonObject();
    message.put("action", "updateUserQuota");
    message.put("userId", userId);
    message.put("size", size);
    message.put("threshold", threshold);

    eb.send(QUOTA_BUS_ADDRESS, message, new Handler<AsyncResult<Message<JsonObject>>>() {
        @Override//  w  ww  .jav a2 s.c om
        public void handle(AsyncResult<Message<JsonObject>> reply) {
            JsonObject obj = reply.result().body();
            UserUtils.addSessionAttribute(eb, userId, "storage", obj.getLong("storage"), null);
            if (obj.getBoolean("notify", false)) {
                notifyEmptySpaceIsSmall(userId);
            }
        }
    });

}

From source file:fr.wseduc.webdav.WebDav.java

License:Apache License

private Sardine getSardine(String uri, Message<JsonObject> message) {
    String host;//from w w  w . ja  va  2  s  .  c o m
    try {
        host = new URI(uri).getHost();
    } catch (URISyntaxException e) {
        sendError(message, e.getMessage(), e);
        return null;
    }
    JsonObject credential = credentials.getJsonObject(host);
    Sardine sardine;
    if (credential != null) {
        if (credential.getBoolean("insecure", false)) {
            sardine = new SardineImpl() {
                @Override
                protected ConnectionSocketFactory createDefaultSecureSocketFactory() {
                    SSLConnectionSocketFactory sf = null;
                    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

                        @Override
                        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                            return null;
                        }

                        @Override
                        public void checkClientTrusted(java.security.cert.X509Certificate[] certs,
                                String authType) {
                        }

                        @Override
                        public void checkServerTrusted(java.security.cert.X509Certificate[] certs,
                                String authType) {
                        }
                    } };
                    try {
                        SSLContext context = SSLContext.getInstance("TLS");
                        context.init(null, trustAllCerts, null);

                        sf = new SSLConnectionSocketFactory(context,
                                SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                    } catch (NoSuchAlgorithmException | KeyManagementException e) {
                        logger.error(e.getMessage(), e);
                    }
                    return sf;
                }
            };
            sardine.setCredentials(credential.getString("username"), credential.getString("password"));
        } else {
            sardine = SardineFactory.begin(credential.getString("username"), credential.getString("password"));
        }
        sardine.enablePreemptiveAuthentication(host);
    } else {
        sardine = SardineFactory.begin();
    }
    return sardine;
}

From source file:io.engagingspaces.graphql.query.QueryResult.java

License:Open Source License

/**
 * Creates a new {@link QueryResult} from
 * its json representation./*from w  w  w . j a  v  a2  s.c om*/
 *
 * @param json the json object
 */
public QueryResult(JsonObject json) {
    this.data = json.getJsonObject("data", new JsonObject());
    this.succeeded = json.getBoolean("succeeded", false);
    List<QueryError> queryErrors = json.getJsonArray("errors", new JsonArray()).stream()
            .map(error -> new QueryError((JsonObject) error)).collect(Collectors.toList());
    this.errors = queryErrors == null ? Collections.emptyList() : Collections.unmodifiableList(queryErrors);
}

From source file:io.flowly.auth.ExtJwtAuthProvider.java

License:Open Source License

@Override
public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) {
    try {/*from   w w  w .j a v a  2 s .  co 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.engine.App.java

License:Open Source License

public static App toApp(JsonObject jsonObject) {
    App app = new App(jsonObject.getString(JsonKeys.APP_ID), jsonObject.getString(JsonKeys.APPS_DIRECTORY));
    app.setLocked(jsonObject.getBoolean(JsonKeys.APP_LOCKED, false));
    return app;/*from   ww  w  .j ava  2s  .co m*/
}