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

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

Introduction

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

Prototype

public Object getValue(String key) 

Source Link

Document

Get the value with the specified key, as an Object with types respecting the limitations of JSON.

Usage

From source file:io.flowly.engine.verticles.services.Email.java

License:Open Source License

private void registerEmailHandler() {
    vertx.eventBus().consumer(EngineAddresses.SEND_EMAIL, request -> {
        JsonObject mail = (JsonObject) request.body();
        MailMessage email = new MailMessage();

        try {/*from ww  w . j  a  va  2  s .  c o  m*/
            // TODO: Should "from" variable be configured per app or per call?
            email.setFrom("test@flowly.io");

            // TODO: Test multiple send to issue.
            // If emailTo is a string, create an array.
            Object emailTo = mail.getValue(JsonKeys.EMAIL_TO);

            if (emailTo instanceof String) {
                email.setTo((String) emailTo);
            } else {
                email.setTo(mail.getJsonArray(JsonKeys.EMAIL_TO).getList());
            }

            email.setSubject(mail.getString(JsonKeys.EMAIL_SUBJECT));
            email.setHtml(mail.getString(JsonKeys.EMAIL_BODY));

            mailClient.sendMail(email, result -> {
                if (result.succeeded()) {
                    if (logger.isInfoEnabled()) {
                        logger.info("Email: " + email.getSubject() + ", sent to: " + email.getTo());
                    }

                    JsonObject message = new JsonObject();
                    message.put(JsonKeys.RESULT, true);
                    request.reply(message);
                } else {
                    Failure failure = new Failure(6000, "Failed to send email.", result.cause());
                    logger.error(failure.getError(), failure.getCause());
                    request.fail(failure.getCode(), failure.getMessage());
                }
            });
        } catch (Exception ex) {
            Failure failure = new Failure(6001, "Unable to parse email message.", ex);
            logger.error(failure.getError(), failure.getCause());
            request.fail(failure.getCode(), failure.getMessage());
        }
    });
}

From source file:io.github.pflima92.plyshare.common.configuration.ConfigurationProviderVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//from   w w  w  .j a  v a2  s. co m
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {
        case "getConfiguration": {
            service.getConfiguration((java.lang.String) json.getValue("name"), createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:io.github.pflima92.plyshare.common.discovery.HeartbeatConverter.java

License:Apache License

public static void fromJson(JsonObject json, Heartbeat obj) {
    if (json.getValue("healthy") instanceof Boolean) {
        obj.setHealthy((Boolean) json.getValue("healthy"));
    }//from w w  w. jav a2s.  c o m
    if (json.getValue("record") instanceof JsonObject) {
        obj.setRecord(new io.vertx.servicediscovery.Record((JsonObject) json.getValue("record")));
    }
}

From source file:io.github.pflima92.plyshare.common.discovery.RecordMetadataConverter.java

License:Apache License

public static void fromJson(JsonObject json, RecordMetadata obj) {
    if (json.getValue("healthCheck") instanceof Boolean) {
        obj.setHealthCheck((Boolean) json.getValue("healthCheck"));
    }/* w  w w.  j  a va2  s  .  c o  m*/
    if (json.getValue("healthPathCheck") instanceof String) {
        obj.setHealthPathCheck((String) json.getValue("healthPathCheck"));
    }
    if (json.getValue("name") instanceof String) {
        obj.setName((String) json.getValue("name"));
    }
}

From source file:io.github.pflima92.plyshare.common.MicroserviceOptionsConverter.java

License:Apache License

public static void fromJson(JsonObject json, MicroserviceOptions obj) {
    if (json.getValue("address") instanceof String) {
        obj.setAddress((String) json.getValue("address"));
    }/*w  ww  . ja v  a 2  s.c om*/
    if (json.getValue("circuitBreakerOptions") instanceof JsonObject) {
        obj.setCircuitBreakerOptions(new io.vertx.circuitbreaker.CircuitBreakerOptions(
                (JsonObject) json.getValue("circuitBreakerOptions")));
    }
    if (json.getValue("config") instanceof JsonObject) {
        obj.setConfig(((JsonObject) json.getValue("config")).copy());
    }
    if (json.getValue("healthCheck") instanceof Boolean) {
        obj.setHealthCheck((Boolean) json.getValue("healthCheck"));
    }
    if (json.getValue("healthPathCheck") instanceof String) {
        obj.setHealthPathCheck((String) json.getValue("healthPathCheck"));
    }
    if (json.getValue("httpServerOptions") instanceof JsonObject) {
        obj.setHttpServerOptions(
                new io.vertx.core.http.HttpServerOptions((JsonObject) json.getValue("httpServerOptions")));
    }
    if (json.getValue("name") instanceof String) {
        obj.setName((String) json.getValue("name"));
    }
    if (json.getValue("port") instanceof Number) {
        obj.setPort(((Number) json.getValue("port")).intValue());
    }
    if (json.getValue("serviceDiscoveryOptions") instanceof JsonObject) {
        obj.setServiceDiscoveryOptions(new io.vertx.servicediscovery.ServiceDiscoveryOptions(
                (JsonObject) json.getValue("serviceDiscoveryOptions")));
    }
}

From source file:io.github.qrman.guice.WimbledonModule.java

License:Open Source License

private Properties extractToProperties(JsonObject config) {
    Properties properties = new Properties();
    config.getMap().keySet().stream().forEach((String key) -> {
        properties.setProperty(key, (String) config.getValue(key));
    });/*w ww .  j av  a2 s.  com*/
    return properties;
}

From source file:io.gravitee.am.identityprovider.github.authentication.GithubAuthenticationProvider.java

License:Apache License

private User createUser(JsonObject jsonObject) {
    User user = new DefaultUser(jsonObject.getString(GithubUser.LOGIN));
    // set additional information
    Map<String, Object> additionalInformation = new HashMap<>();
    additionalInformation.put("sub", jsonObject.getValue(GithubUser.LOGIN));
    additionalInformation.put(GithubUser.AVATAR_URL, jsonObject.getValue(GithubUser.AVATAR_URL));
    additionalInformation.put(GithubUser.GRAVATAR_ID, jsonObject.getValue(GithubUser.GRAVATAR_ID));
    additionalInformation.put(GithubUser.URL, jsonObject.getValue(GithubUser.URL));
    additionalInformation.put(GithubUser.HTML_URL, jsonObject.getValue(GithubUser.HTML_URL));
    additionalInformation.put(GithubUser.FOLLOWERS_URL, jsonObject.getValue(GithubUser.FOLLOWERS_URL));
    additionalInformation.put(GithubUser.FOLLOWING_URL, jsonObject.getValue(GithubUser.FOLLOWING_URL));
    additionalInformation.put(GithubUser.GISTS_URL, jsonObject.getValue(GithubUser.GISTS_URL));
    additionalInformation.put(GithubUser.STARRED_URL, jsonObject.getValue(GithubUser.STARRED_URL));
    additionalInformation.put(GithubUser.SUBSCRIPTIONS_URL, jsonObject.getValue(GithubUser.SUBSCRIPTIONS_URL));
    additionalInformation.put(GithubUser.ORGANIZATIONS_URL, jsonObject.getValue(GithubUser.ORGANIZATIONS_URL));
    additionalInformation.put(GithubUser.REPOS_URL, jsonObject.getValue(GithubUser.REPOS_URL));
    additionalInformation.put(GithubUser.EVENTS_URL, jsonObject.getValue(GithubUser.EVENTS_URL));
    additionalInformation.put(GithubUser.RECEIVED_EVENTS_URL,
            jsonObject.getValue(GithubUser.RECEIVED_EVENTS_URL));
    additionalInformation.put(GithubUser.SITE_ADMIN, jsonObject.getBoolean(GithubUser.SITE_ADMIN));
    additionalInformation.put(GithubUser.NAME, jsonObject.getValue(GithubUser.NAME));
    additionalInformation.put(GithubUser.COMPANY, jsonObject.getValue(GithubUser.COMPANY));
    additionalInformation.put(GithubUser.LOCATION, jsonObject.getValue(GithubUser.LOCATION));
    additionalInformation.put(GithubUser.EMAIL, jsonObject.getValue(GithubUser.EMAIL));
    additionalInformation.put(GithubUser.PUBLIC_REPOS, jsonObject.getValue(GithubUser.PUBLIC_REPOS));
    additionalInformation.put(GithubUser.PUBLIC_GISTS, jsonObject.getValue(GithubUser.PUBLIC_GISTS));
    additionalInformation.put(GithubUser.FOLLOWERS, jsonObject.getValue(GithubUser.FOLLOWERS));
    additionalInformation.put(GithubUser.FOLLOWING, jsonObject.getValue(GithubUser.FOLLOWING));
    additionalInformation.put(GithubUser.LOCATION, jsonObject.getValue(GithubUser.LOCATION));
    additionalInformation.put(GithubUser.EMAIL, jsonObject.getValue(GithubUser.EMAIL));
    ((DefaultUser) user).setAdditonalInformation(additionalInformation);
    return user;/*from  w w w. j a  v  a 2s .  co  m*/
}

From source file:io.gravitee.am.identityprovider.oauth2.authentication.OAuth2GenericAuthenticationProvider.java

License:Apache License

private User createUser(JsonObject jsonNode) {
    User user = new DefaultUser(jsonNode.getString(CLAIMS_SUB));
    // set additional information
    Map<String, Object> additionalInformation = new HashMap<>();
    additionalInformation.put(CLAIMS_SUB, jsonNode.getValue(CLAIMS_SUB));
    if (this.mapper.getMappers() != null) {
        this.mapper.getMappers().forEach((k, v) -> {
            if (jsonNode.getValue(v) != null) {
                additionalInformation.put(k, jsonNode.getValue(v));
            }// www.  java 2 s. c o m
        });
    }
    ((DefaultUser) user).setAdditonalInformation(additionalInformation);
    return user;
}

From source file:io.hijynx.ensemble.identity.PrivilegeConverter.java

License:Apache License

public static void fromJson(JsonObject json, Privilege obj) {
    if (json.getValue("description") instanceof String) {
        obj.setDescription((String) json.getValue("description"));
    }//from  ww w.ja  v a2  s. c om
    if (json.getValue("privilegeCreate") instanceof Boolean) {
        obj.setPrivilegeCreate((Boolean) json.getValue("privilegeCreate"));
    }
    if (json.getValue("privilegeDelete") instanceof Boolean) {
        obj.setPrivilegeDelete((Boolean) json.getValue("privilegeDelete"));
    }
    if (json.getValue("privilegeId") instanceof String) {
        obj.setPrivilegeId((String) json.getValue("privilegeId"));
    }
    if (json.getValue("privilegeName") instanceof String) {
        obj.setPrivilegeName((String) json.getValue("privilegeName"));
    }
    if (json.getValue("privilegeRead") instanceof Boolean) {
        obj.setPrivilegeRead((Boolean) json.getValue("privilegeRead"));
    }
    if (json.getValue("privilegeUpdate") instanceof Boolean) {
        obj.setPrivilegeUpdate((Boolean) json.getValue("privilegeUpdate"));
    }
    if (json.getValue("target") instanceof String) {
        obj.setTarget((String) json.getValue("target"));
    }
}

From source file:io.hijynx.ensemble.identity.PrivilegeServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/* www .j a v a2 s  .com*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {
        case "addPrivilege": {
            service.addPrivilege(
                    json.getJsonObject("privilege") == null ? null
                            : new io.hijynx.ensemble.identity.Privilege(json.getJsonObject("privilege")),
                    createHandler(msg));
            break;
        }
        case "retrievePrivilege": {
            service.retrievePrivilege((java.lang.String) json.getValue("id"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "retrievePrivilegeByName": {
            service.retrievePrivilegeByName((java.lang.String) json.getValue("privilegeName"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "retrieveAllPrivileges": {
            service.retrieveAllPrivileges(res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(new JsonArray(
                            res.result().stream().map(Privilege::toJson).collect(Collectors.toList())));
                }
            });
            break;
        }
        case "updatePrivilege": {
            service.updatePrivilege(
                    json.getJsonObject("privilege") == null ? null
                            : new io.hijynx.ensemble.identity.Privilege(json.getJsonObject("privilege")),
                    res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "deletePrivilege": {
            service.deletePrivilege((java.lang.String) json.getValue("id"), createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}