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.apiman.gateway.platforms.vertx3.services.IngestorToPolicyServiceVertxProxyHandler.java

License:Apache License

@Override
public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }//  w w  w .  j a  v  a 2 s  .  c o m
    accessed();
    switch (action) {

    case "head": {
        service.head(json.getJsonObject("apiRequest") == null ? null
                : new io.apiman.gateway.platforms.vertx3.io.VertxApiRequest(json.getJsonObject("apiRequest")),
                createHandler(msg));
        break;
    }
    case "write": {
        service.write((java.lang.String) json.getValue("chunk"));
        break;
    }
    case "end": {
        service.end(createHandler(msg));
        close();
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:io.apiman.gateway.platforms.vertx3.services.InitializeIngestorServiceVertxProxyHandler.java

License:Apache License

@Override
public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }//w  w  w .ja va  2  s .  c  o m
    accessed();
    switch (action) {
    case "createIngestor": {
        service.createIngestor((java.lang.String) json.getValue("uuid"), res -> {
            if (res.failed()) {
                msg.fail(-1, res.cause().getMessage());
            } else {
                String proxyAddress = UUID.randomUUID().toString();
                ProxyHelper.registerService(IngestorToPolicyService.class, vertx, res.result(), proxyAddress,
                        false, timeoutSeconds);
                msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
            }
        });
        break;
    }

    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:io.apiman.gateway.platforms.vertx3.services.PolicyToIngestorServiceVertxProxyHandler.java

License:Apache License

@Override
public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }/*from   w w w  .  j  a v  a2s  .co m*/
    accessed();
    switch (action) {

    case "head": {
        service.head(json.getJsonObject("apiResponse") == null ? null
                : new io.apiman.gateway.platforms.vertx3.io.VertxApiResponse(json.getJsonObject("apiResponse")),
                createHandler(msg));
        break;
    }
    case "write": {
        service.write((java.lang.String) json.getValue("chunk"));
        break;
    }
    case "end": {
        service.end(createHandler(msg));
        close();
        break;
    }
    case "policyFailure": {
        service.policyFailure(json.getJsonObject("policyFailure") == null ? null
                : new io.apiman.gateway.platforms.vertx3.io.VertxPolicyFailure(
                        json.getJsonObject("policyFailure")));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:io.engagingspaces.graphql.events.SchemaReferenceData.java

License:Open Source License

/**
 * Creates a new {@link SchemaReferenceData} from
 * its json representation./*from   www.  j  a  v  a  2  s  .c o  m*/
 *
 * @param json the json object
 */
public SchemaReferenceData(JsonObject json) {
    this.id = json.getString("id");
    this.record = new Record(json.getJsonObject("record"));
    this.status = "bind".equals(json.getValue("type")) ? Status.BOUND : Status.RELEASED;
}

From source file:io.engagingspaces.graphql.marshaller.schema.impl.SchemaContextImpl.java

License:Open Source License

/**
 * {@inheritDoc}//  w w  w  .j  av  a 2  s . co  m
 */
@Override
@SuppressWarnings("unchecked")
public <T, U extends SchemaDecorator> List<T> unmarshallList(JsonObject json, String listKey, U parent) {
    if (json == null || !json.containsKey(listKey) || json.getValue(listKey) == null) {
        return Collections.emptyList();
    }
    Object list = json.getValue(listKey);
    if (list instanceof JsonObject) {
        return ((JsonObject) list).stream().map(entry -> (T) unmarshall((JsonObject) entry.getValue(), parent))
                .collect(Collectors.toList());
    } else if (list instanceof JsonArray) {
        return ((JsonArray) list).stream().map(value -> (T) unmarshall((JsonObject) value, parent))
                .collect(Collectors.toList());
    } else {
        throw new IllegalStateException(
                "Failed to unmarshall type to list. Type: " + list.getClass().getName());
    }
}

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

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from   ww w  . j  a  v a 2  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 "query": {
            service.query((java.lang.String) json.getValue("graphqlQuery"), 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 "queryWithVariables": {
            service.queryWithVariables((java.lang.String) json.getValue("graphqlQuery"),
                    (io.vertx.core.json.JsonObject) json.getValue("variables"), 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 "resolveType": {
            service.resolveType((java.lang.String) json.getValue("typeResolverId"),
                    (io.vertx.core.json.JsonObject) json.getValue("typeHolder"), createHandler(msg));
            break;
        }
        case "fetchData": {
            service.fetchData((java.lang.String) json.getValue("dataFetcherId"),
                    (io.vertx.core.json.JsonObject) json.getValue("dataFetchingEnvironment"),
                    createHandler(msg));
            break;
        }
        case "close": {
            service.close();
            close();
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:io.fabric8.devops.apps.bughunter.model.AppInfoConverter.java

License:Apache License

public static void fromJson(JsonObject json, AppInfo obj) {
    if (json.getValue("branch") instanceof String) {
        obj.setBranch((String) json.getValue("branch"));
    }/*from   w  w w  . j a  v a2s . c  o m*/
    if (json.getValue("group") instanceof String) {
        obj.setGroup((String) json.getValue("group"));
    }
    if (json.getValue("issueTrackerUrl") instanceof String) {
        obj.setIssueTrackerUrl((String) json.getValue("issueTrackerUrl"));
    }
    if (json.getValue("project") instanceof String) {
        obj.setProject((String) json.getValue("project"));
    }
    if (json.getValue("projectUrl") instanceof String) {
        obj.setProjectUrl((String) json.getValue("projectUrl"));
    }
    if (json.getValue("revision") instanceof String) {
        obj.setRevision((String) json.getValue("revision"));
    }
    if (json.getValue("version") instanceof String) {
        obj.setVersion((String) json.getValue("version"));
    }
}

From source file:io.fabric8.devops.apps.bughunter.model.BugInfoConverter.java

License:Apache License

public static void fromJson(JsonObject json, BugInfo obj) {
    if (json.getValue("app") instanceof JsonObject) {
        obj.setApp(new io.fabric8.devops.apps.bughunter.model.AppInfo((JsonObject) json.getValue("app")));
    }//from  ww  w  .j a  v a 2  s. co m
    if (json.getValue("count") instanceof Number) {
        obj.setCount(((Number) json.getValue("count")).intValue());
    }
    if (json.getValue("id") instanceof String) {
        obj.setId((String) json.getValue("id"));
    }
    if (json.getValue("logMessage") instanceof String) {
        obj.setLogMessage((String) json.getValue("logMessage"));
    }
    if (json.getValue("pod") instanceof JsonObject) {
        obj.setPod(new io.fabric8.devops.apps.bughunter.model.PodInfo((JsonObject) json.getValue("pod")));
    }
    if (json.getValue("score") instanceof Number) {
        obj.setScore(((Number) json.getValue("score")).floatValue());
    }
    if (json.getValue("timestamp") instanceof String) {
        obj.setTimestamp((String) json.getValue("timestamp"));
    }
}

From source file:io.fabric8.devops.apps.bughunter.model.PodInfoConverter.java

License:Apache License

public static void fromJson(JsonObject json, PodInfo obj) {
    if (json.getValue("containerName") instanceof String) {
        obj.setContainerName((String) json.getValue("containerName"));
    }/* w w  w .ja va  2s  .c  o  m*/
    if (json.getValue("host") instanceof String) {
        obj.setHost((String) json.getValue("host"));
    }
    if (json.getValue("namespace") instanceof String) {
        obj.setNamespace((String) json.getValue("namespace"));
    }
    if (json.getValue("podId") instanceof String) {
        obj.setPodId((String) json.getValue("podId"));
    }
    if (json.getValue("podName") instanceof String) {
        obj.setPodName((String) json.getValue("podName"));
    }
}

From source file:io.fabric8.devops.apps.elasticsearch.helper.service.ElasticSearchOptionsConverter.java

License:Apache License

public static void fromJson(JsonObject json, ElasticSearchOptions obj) {
    if (json.getValue("configMap") instanceof String) {
        obj.setConfigMap((String) json.getValue("configMap"));
    }//from   w ww  .  j a v a 2  s .  c  o  m
    if (json.getValue("configMapScanPeriod") instanceof Number) {
        obj.setConfigMapScanPeriod(((Number) json.getValue("configMapScanPeriod")).longValue());
    }
    if (json.getValue("host") instanceof String) {
        obj.setHost((String) json.getValue("host"));
    }
    if (json.getValue("indexes") instanceof JsonArray) {
        java.util.ArrayList<java.lang.String> list = new java.util.ArrayList<>();
        json.getJsonArray("indexes").forEach(item -> {
            if (item instanceof String)
                list.add((String) item);
        });
        obj.setIndexes(list);
    }
    if (json.getValue("indexs") instanceof JsonArray) {
        json.getJsonArray("indexs").forEach(item -> {
            if (item instanceof String)
                obj.addIndex((String) item);
        });
    }
    if (json.getValue("kubernetesNamespace") instanceof String) {
        obj.setKubernetesNamespace((String) json.getValue("kubernetesNamespace"));
    }
    if (json.getValue("port") instanceof Number) {
        obj.setPort(((Number) json.getValue("port")).intValue());
    }
    if (json.getValue("ssl") instanceof Boolean) {
        obj.setSsl((Boolean) json.getValue("ssl"));
    }
}