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:com.edgar.vertx.serviceproxy.provider.ProcessorServiceVertxProxyHandler.java

License:Apache License

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

        case "process": {
            service.process((io.vertx.core.json.JsonObject) json.getValue("document"), 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:com.emikra.vertx.orientdb.OrientDBServiceVertxProxyHandler.java

License:Apache License

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  a  2s  .  c  om*/
    accessed();
    switch (action) {

    case "createDatabase": {
        service.createDatabase(json.getJsonObject("options") == null ? null
                : new com.emikra.vertx.orientdb.database.data.CreateDatabaseParams(
                        json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "createDocument": {
        service.createDocument((io.vertx.core.json.JsonObject) json.getValue("document"), createHandler(msg));
        break;
    }
    case "createVertex": {
        service.createVertex((io.vertx.core.json.JsonObject) json.getValue("vertexDoc"), createHandler(msg));
        break;
    }
    case "createEdge": {
        service.createEdge((io.vertx.core.json.JsonObject) json.getValue("edgeDoc"), createHandler(msg));
        break;
    }
    case "createClass": {
        service.createClass(
                json.getJsonObject("params") == null ? null
                        : new com.emikra.vertx.orientdb.CreateClassParams(json.getJsonObject("params")),
                createHandler(msg));
        break;
    }
    case "getDocument": {
        service.getDocument((io.vertx.core.json.JsonObject) json.getValue("docQuery"), createHandler(msg));
        break;
    }
    case "getVertex": {
        service.getVertex((io.vertx.core.json.JsonObject) json.getValue("vertexQuery"), createHandler(msg));
        break;
    }
    case "getEdge": {
        service.getEdge((io.vertx.core.json.JsonObject) json.getValue("edgeQuery"), createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:com.englishtown.vertx.elasticsearch.ElasticSearchAdminServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//from   ww  w  .j  av  a 2  s.  c  om
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "putMapping": {
            service.putMapping(convertList(json.getJsonArray("indices").getList()),
                    (java.lang.String) json.getValue("type"),
                    (io.vertx.core.json.JsonObject) json.getValue("source"),
                    json.getJsonObject("options") == null ? null
                            : new com.englishtown.vertx.elasticsearch.MappingOptions(
                                    json.getJsonObject("options")),
                    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:com.englishtown.vertx.elasticsearch.ElasticSearchServiceVertxProxyHandler.java

License:Apache License

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 ww  w  .jav  a2  s.  c  o  m*/
    accessed();
    switch (action) {

    case "start": {
        service.start();
        break;
    }
    case "stop": {
        service.stop();
        break;
    }
    case "index": {
        service.index((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"),
                (io.vertx.core.json.JsonObject) json.getValue("source"),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.IndexOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "update": {
        service.update((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"),
                (java.lang.String) json.getValue("id"),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.UpdateOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "get": {
        service.get((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"),
                (java.lang.String) json.getValue("id"),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.GetOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "search": {
        service.search(convertList(json.getJsonArray("indices").getList()),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.SearchOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "searchScroll": {
        service.searchScroll((java.lang.String) json.getValue("scrollId"), json.getJsonObject("options") == null
                ? null
                : new com.englishtown.vertx.elasticsearch.SearchScrollOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    case "delete": {
        service.delete((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"),
                (java.lang.String) json.getValue("id"),
                json.getJsonObject("options") == null ? null
                        : new com.englishtown.vertx.elasticsearch.DeleteOptions(json.getJsonObject("options")),
                createHandler(msg));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:com.englishtown.vertx.guice.GuiceVerticleLoader.java

License:Open Source License

private Verticle createRealVerticle(Class<?> clazz) throws Exception {

    JsonObject config = context.config();
    Object field = config.getValue(CONFIG_BOOTSTRAP_BINDER_NAME);
    JsonArray bootstrapNames;//from  ww w  . java2 s  .  c om
    List<Module> bootstraps = new ArrayList<>();

    if (field instanceof JsonArray) {
        bootstrapNames = (JsonArray) field;
    } else {
        bootstrapNames = new JsonArray().add((field == null ? BOOTSTRAP_BINDER_NAME : field));
    }

    for (int i = 0; i < bootstrapNames.size(); i++) {
        String bootstrapName = bootstrapNames.getString(i);
        try {
            Class bootstrapClass = classLoader.loadClass(bootstrapName);
            Object obj = bootstrapClass.newInstance();

            if (obj instanceof Module) {
                bootstraps.add((Module) obj);
            } else {
                logger.error("Class " + bootstrapName + " does not implement Module.");
            }
        } catch (ClassNotFoundException e) {
            logger.error("Guice bootstrap binder class " + bootstrapName
                    + " was not found.  Are you missing injection bindings?");
        }
    }

    // Add vert.x binder
    bootstraps.add(new GuiceVertxBinder(vertx));

    // Each verticle factory will have it's own injector instance
    Injector injector = Guice.createInjector(bootstraps);
    return (Verticle) injector.getInstance(clazz);
}

From source file:com.englishtown.vertx.hk2.HK2VerticleLoader.java

License:Open Source License

private Verticle createRealVerticle(Class<?> clazz) throws Exception {

    JsonObject config = config();
    Object field = config.getValue(CONFIG_BOOTSTRAP_BINDER_NAME);
    JsonArray bootstrapNames;//from w  ww . j  a va 2s.  co m
    List<Binder> bootstraps = new ArrayList<>();

    if (field instanceof JsonArray) {
        bootstrapNames = (JsonArray) field;
    } else {
        bootstrapNames = new JsonArray().add((field == null ? BOOTSTRAP_BINDER_NAME : field));
    }

    for (int i = 0; i < bootstrapNames.size(); i++) {
        String bootstrapName = bootstrapNames.getString(i);
        try {
            Class bootstrapClass = classLoader.loadClass(bootstrapName);
            Object obj = bootstrapClass.newInstance();

            if (obj instanceof Binder) {
                bootstraps.add((Binder) obj);
            } else {
                logger.error("Class " + bootstrapName + " does not implement Binder.");
            }
        } catch (ClassNotFoundException e) {
            logger.error("HK2 bootstrap binder class " + bootstrapName
                    + " was not found.  Are you missing injection bindings?");
        }
    }

    // Each verticle factory will have it's own service locator instance
    // Passing a null name will not cache the locator in the factory
    locator = ServiceLocatorFactory.getInstance().create(null, parent);

    bootstraps.add(0, new HK2VertxBinder(vertx));
    ServiceLocatorUtilities.bind(locator, bootstraps.toArray(new Binder[bootstraps.size()]));

    return (Verticle) locator.createAndInitialize(clazz);
}

From source file:com.englishtown.vertx.jersey.impl.DefaultJerseyOptions.java

License:Open Source License

protected ResourceConfig getResourceConfig() {
    checkState();//from  ww w. j  a v a  2 s  .c  om
    JsonArray resources = config.getJsonArray(CONFIG_RESOURCES, null);

    if (resources == null || resources.size() == 0) {
        throw new RuntimeException(
                "At least one resource package name must be specified in the config " + CONFIG_RESOURCES);
    }

    String[] resourceArr = new String[resources.size()];
    for (int i = 0; i < resources.size(); i++) {
        resourceArr[i] = resources.getString(i);
    }

    ResourceConfig rc = new ResourceConfig();
    rc.packages(resourceArr);

    ClassLoader cl = Thread.currentThread().getContextClassLoader();

    JsonArray features = config.getJsonArray(CONFIG_FEATURES, null);
    if (features != null && features.size() > 0) {
        for (int i = 0; i < features.size(); i++) {
            try {
                Class<?> clazz = cl.loadClass(features.getString(i));
                rc.register(clazz);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    // Always register the InternalVertxJerseyBinder
    rc.register(new InternalVertxJerseyBinder(vertx));

    // Register configured binders
    JsonArray binders = config.getJsonArray(CONFIG_BINDERS, null);
    if (binders != null && binders.size() > 0) {
        for (int i = 0; i < binders.size(); i++) {
            try {
                Class<?> clazz = cl.loadClass(binders.getString(i));
                rc.register(clazz.newInstance());
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }

    final JsonObject resourceConfigAdditions = config.getJsonObject(CONFIG_RESOURCE_CONFIG);
    if (resourceConfigAdditions != null) {
        for (final String fieldName : resourceConfigAdditions.fieldNames()) {
            rc.property(fieldName, resourceConfigAdditions.getValue(fieldName));
        }
    }

    return rc;
}

From source file:com.englishtown.vertx.solr.SolrServiceVertxProxyHandler.java

License:Apache License

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

        case "start": {
            service.start();
            break;
        }
        case "stop": {
            service.stop();
            break;
        }
        case "query": {
            service.query((io.vertx.core.json.JsonObject) json.getValue("query"),
                    json.getJsonObject("options") == null ? null
                            : new com.englishtown.vertx.solr.QueryOptions(json.getJsonObject("options")),
                    createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.fail(-1, t.getMessage());
        throw t;
    }
}

From source file:com.funmix.entity.CompanyConverter.java

License:Apache License

public static void fromJson(JsonObject json, Company obj) {
    if (json.getValue("address") instanceof String) {
        obj.setAddress((String) json.getValue("address"));
    }//  w  w  w.ja  v a  2 s .c  o m
    if (json.getValue("companyname") instanceof String) {
        obj.setCompanyname((String) json.getValue("companyname"));
    }
    if (json.getValue("contact") instanceof String) {
        obj.setContact((String) json.getValue("contact"));
    }
    if (json.getValue("contact_phone") instanceof String) {
        obj.setContact_phone((String) json.getValue("contact_phone"));
    }
    if (json.getValue("created_time") instanceof String) {
        obj.setCreated_time((String) json.getValue("created_time"));
    }
    if (json.getValue("id") instanceof Number) {
        obj.setId(((Number) json.getValue("id")).intValue());
    }
    if (json.getValue("latitude") instanceof Number) {
        obj.setLatitude(((Number) json.getValue("latitude")).doubleValue());
    }
    if (json.getValue("longitude") instanceof Number) {
        obj.setLongitude(((Number) json.getValue("longitude")).doubleValue());
    }
    if (json.getValue("memo") instanceof String) {
        obj.setMemo((String) json.getValue("memo"));
    }
    if (json.getValue("phone") instanceof String) {
        obj.setPhone((String) json.getValue("phone"));
    }
    if (json.getValue("status") instanceof Number) {
        obj.setStatus(((Number) json.getValue("status")).intValue());
    }
}

From source file:com.funmix.entity.ContactConverter.java

License:Apache License

public static void fromJson(JsonObject json, Contact obj) {
    if (json.getValue("company") instanceof String) {
        obj.setCompany((String) json.getValue("company"));
    }/*from  w w  w  .j a va  2s . c om*/
    if (json.getValue("contact") instanceof String) {
        obj.setContact((String) json.getValue("contact"));
    }
    if (json.getValue("fhdz") instanceof String) {
        obj.setFhdz((String) json.getValue("fhdz"));
    }
    if (json.getValue("htzq") instanceof String) {
        obj.setHtzq((String) json.getValue("htzq"));
    }
    if (json.getValue("id") instanceof Number) {
        obj.setId(((Number) json.getValue("id")).intValue());
    }
    if (json.getValue("memo") instanceof String) {
        obj.setMemo((String) json.getValue("memo"));
    }
    if (json.getValue("phone") instanceof String) {
        obj.setPhone((String) json.getValue("phone"));
    }
    if (json.getValue("rate") instanceof Number) {
        obj.setRate(((Number) json.getValue("rate")).intValue());
    }
}