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:examples.VertxAmqpBridgeExamples.java

License:Apache License

@SuppressWarnings("unused")
public void example4(JsonObject amqpMsgPayload) {
    // Check the application properties section was present before use, it may not be
    JsonObject appProps = amqpMsgPayload.getJsonObject("application_properties");
    if (appProps != null) {
        Object propValue = appProps.getValue("propertyName");
    }/*from  w w w  .  j  a  v  a  2  s. c o  m*/
}

From source file:fr.pjthin.vertx.client.data.UserConverter.java

License:Apache License

public static void fromJson(JsonObject json, User obj) {
    if (json.getValue("cryptedPasswd") instanceof String) {
        obj.setCryptedPasswd((String) json.getValue("cryptedPasswd"));
    }/* w w w  . j a  v a2s  .co m*/
    if (json.getValue("gender") instanceof String) {
        obj.setGender(fr.pjthin.vertx.client.data.Gender.valueOf((String) json.getValue("gender")));
    }
    if (json.getValue("id") instanceof Number) {
        obj.setId(((Number) json.getValue("id")).intValue());
    }
    if (json.getValue("login") instanceof String) {
        obj.setLogin((String) json.getValue("login"));
    }
}

From source file:fr.pjthin.vertx.client.UserDaoVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//www. j  a  v 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 "save": {
            service.save(
                    json.getJsonObject("newUser") == null ? null
                            : new fr.pjthin.vertx.client.data.User(json.getJsonObject("newUser")),
                    createHandler(msg));
            break;
        }
        case "findAll": {
            service.findAll(res -> {
                if (res.failed()) {
                    msg.fail(-1, res.cause().getMessage());
                } else {
                    msg.reply(new JsonArray(
                            res.result().stream().map(User::toJson).collect(Collectors.toList())));
                }
            });
            break;
        }
        case "findUserByLogin": {
            service.findUserByLogin((java.lang.String) json.getValue("login"), res -> {
                if (res.failed()) {
                    msg.fail(-1, res.cause().getMessage());
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "deleteByLogin": {
            service.deleteByLogin((java.lang.String) json.getValue("login"), createHandler(msg));
            break;
        }
        case "close": {
            service.close();
            close();
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.fail(-1, t.getMessage());
        throw t;
    }
}

From source file:io.apiman.gateway.engine.vertx.polling.PolicyConfigLoader.java

License:Apache License

@SuppressWarnings("unchecked")
private <T, K> List<T> requireJsonArray(String keyName, JsonObject json, Class<K> klazz) {
    // Contains key.
    Arguments.require(json.containsKey(keyName), String.format("Must provide array of %s objects for key '%s'",
            StringUtils.capitalize(keyName), keyName));
    // Is of type array.
    Arguments.require(json.getValue(keyName) instanceof JsonArray,
            String.format("'%s' must be a Json array", keyName));
    // Transform into List<T>.
    return Json.decodeValue(json.getJsonArray(keyName).encode(), List.class, klazz);
}

From source file:io.apiman.gateway.platforms.vertx3.common.config.InheritingHttpServerOptionsConverter.java

License:Apache License

public static void fromJson(JsonObject json, InheritingHttpServerOptions obj) {
    if (json.getValue("acceptBacklog") instanceof Number) {
        obj.setAcceptBacklog(((Number) json.getValue("acceptBacklog")).intValue());
    }/*from www  . ja v  a2 s. c  om*/
    if (json.getValue("acceptUnmaskedFrames") instanceof Boolean) {
        obj.setAcceptUnmaskedFrames((Boolean) json.getValue("acceptUnmaskedFrames"));
    }
    if (json.getValue("alpnVersions") instanceof JsonArray) {
        java.util.ArrayList<io.vertx.core.http.HttpVersion> list = new java.util.ArrayList<>();
        json.getJsonArray("alpnVersions").forEach(item -> {
            if (item instanceof String)
                list.add(io.vertx.core.http.HttpVersion.valueOf((String) item));
        });
        obj.setAlpnVersions(list);
    }
    if (json.getValue("clientAuth") instanceof String) {
        obj.setClientAuth(io.vertx.core.http.ClientAuth.valueOf((String) json.getValue("clientAuth")));
    }
    if (json.getValue("clientAuthRequired") instanceof Boolean) {
        obj.setClientAuthRequired((Boolean) json.getValue("clientAuthRequired"));
    }
    if (json.getValue("compressionLevel") instanceof Number) {
        obj.setCompressionLevel(((Number) json.getValue("compressionLevel")).intValue());
    }
    if (json.getValue("compressionSupported") instanceof Boolean) {
        obj.setCompressionSupported((Boolean) json.getValue("compressionSupported"));
    }
    if (json.getValue("crlPaths") instanceof JsonArray) {
        json.getJsonArray("crlPaths").forEach(item -> {
            if (item instanceof String)
                obj.addCrlPath((String) item);
        });
    }
    if (json.getValue("crlValues") instanceof JsonArray) {
        json.getJsonArray("crlValues").forEach(item -> {
            if (item instanceof String)
                obj.addCrlValue(io.vertx.core.buffer.Buffer
                        .buffer(java.util.Base64.getDecoder().decode((String) item)));
        });
    }
    if (json.getValue("decompressionSupported") instanceof Boolean) {
        obj.setDecompressionSupported((Boolean) json.getValue("decompressionSupported"));
    }
    if (json.getValue("enabledCipherSuites") instanceof JsonArray) {
        json.getJsonArray("enabledCipherSuites").forEach(item -> {
            if (item instanceof String)
                obj.addEnabledCipherSuite((String) item);
        });
    }
    if (json.getValue("enabledSecureTransportProtocols") instanceof JsonArray) {
        json.getJsonArray("enabledSecureTransportProtocols").forEach(item -> {
            if (item instanceof String)
                obj.addEnabledSecureTransportProtocol((String) item);
        });
    }
    if (json.getValue("handle100ContinueAutomatically") instanceof Boolean) {
        obj.setHandle100ContinueAutomatically((Boolean) json.getValue("handle100ContinueAutomatically"));
    }
    if (json.getValue("host") instanceof String) {
        obj.setHost((String) json.getValue("host"));
    }
    if (json.getValue("http2ConnectionWindowSize") instanceof Number) {
        obj.setHttp2ConnectionWindowSize(((Number) json.getValue("http2ConnectionWindowSize")).intValue());
    }
    if (json.getValue("idleTimeout") instanceof Number) {
        obj.setIdleTimeout(((Number) json.getValue("idleTimeout")).intValue());
    }
    if (json.getValue("initialSettings") instanceof JsonObject) {
        obj.setInitialSettings(
                new io.vertx.core.http.Http2Settings((JsonObject) json.getValue("initialSettings")));
    }
    if (json.getValue("jdkSslEngineOptions") instanceof JsonObject) {
        obj.setJdkSslEngineOptions(
                new io.vertx.core.net.JdkSSLEngineOptions((JsonObject) json.getValue("jdkSslEngineOptions")));
    }
    if (json.getValue("keyStoreOptions") instanceof JsonObject) {
        obj.setKeyStoreOptions(new io.vertx.core.net.JksOptions((JsonObject) json.getValue("keyStoreOptions")));
    }
    if (json.getValue("logActivity") instanceof Boolean) {
        obj.setLogActivity((Boolean) json.getValue("logActivity"));
    }
    if (json.getValue("maxChunkSize") instanceof Number) {
        obj.setMaxChunkSize(((Number) json.getValue("maxChunkSize")).intValue());
    }
    if (json.getValue("maxHeaderSize") instanceof Number) {
        obj.setMaxHeaderSize(((Number) json.getValue("maxHeaderSize")).intValue());
    }
    if (json.getValue("maxInitialLineLength") instanceof Number) {
        obj.setMaxInitialLineLength(((Number) json.getValue("maxInitialLineLength")).intValue());
    }
    if (json.getValue("maxWebsocketFrameSize") instanceof Number) {
        obj.setMaxWebsocketFrameSize(((Number) json.getValue("maxWebsocketFrameSize")).intValue());
    }
    if (json.getValue("maxWebsocketMessageSize") instanceof Number) {
        obj.setMaxWebsocketMessageSize(((Number) json.getValue("maxWebsocketMessageSize")).intValue());
    }
    if (json.getValue("openSslEngineOptions") instanceof JsonObject) {
        obj.setOpenSslEngineOptions(
                new io.vertx.core.net.OpenSSLEngineOptions((JsonObject) json.getValue("openSslEngineOptions")));
    }
    if (json.getValue("pemKeyCertOptions") instanceof JsonObject) {
        obj.setPemKeyCertOptions(
                new io.vertx.core.net.PemKeyCertOptions((JsonObject) json.getValue("pemKeyCertOptions")));
    }
    if (json.getValue("pemTrustOptions") instanceof JsonObject) {
        obj.setPemTrustOptions(
                new io.vertx.core.net.PemTrustOptions((JsonObject) json.getValue("pemTrustOptions")));
    }
    if (json.getValue("pfxKeyCertOptions") instanceof JsonObject) {
        obj.setPfxKeyCertOptions(
                new io.vertx.core.net.PfxOptions((JsonObject) json.getValue("pfxKeyCertOptions")));
    }
    if (json.getValue("pfxTrustOptions") instanceof JsonObject) {
        obj.setPfxTrustOptions(new io.vertx.core.net.PfxOptions((JsonObject) json.getValue("pfxTrustOptions")));
    }
    if (json.getValue("port") instanceof Number) {
        obj.setPort(((Number) json.getValue("port")).intValue());
    }
    if (json.getValue("receiveBufferSize") instanceof Number) {
        obj.setReceiveBufferSize(((Number) json.getValue("receiveBufferSize")).intValue());
    }
    if (json.getValue("reuseAddress") instanceof Boolean) {
        obj.setReuseAddress((Boolean) json.getValue("reuseAddress"));
    }
    if (json.getValue("sendBufferSize") instanceof Number) {
        obj.setSendBufferSize(((Number) json.getValue("sendBufferSize")).intValue());
    }
    if (json.getValue("soLinger") instanceof Number) {
        obj.setSoLinger(((Number) json.getValue("soLinger")).intValue());
    }
    if (json.getValue("ssl") instanceof Boolean) {
        obj.setSsl((Boolean) json.getValue("ssl"));
    }
    if (json.getValue("tcpKeepAlive") instanceof Boolean) {
        obj.setTcpKeepAlive((Boolean) json.getValue("tcpKeepAlive"));
    }
    if (json.getValue("tcpNoDelay") instanceof Boolean) {
        obj.setTcpNoDelay((Boolean) json.getValue("tcpNoDelay"));
    }
    if (json.getValue("trafficClass") instanceof Number) {
        obj.setTrafficClass(((Number) json.getValue("trafficClass")).intValue());
    }
    if (json.getValue("trustStoreOptions") instanceof JsonObject) {
        obj.setTrustStoreOptions(
                new io.vertx.core.net.JksOptions((JsonObject) json.getValue("trustStoreOptions")));
    }
    if (json.getValue("useAlpn") instanceof Boolean) {
        obj.setUseAlpn((Boolean) json.getValue("useAlpn"));
    }
    if (json.getValue("usePooledBuffers") instanceof Boolean) {
        obj.setUsePooledBuffers((Boolean) json.getValue("usePooledBuffers"));
    }
    if (json.getValue("websocketSubProtocols") instanceof String) {
        obj.setWebsocketSubProtocols((String) json.getValue("websocketSubProtocols"));
    }
}

From source file:io.apiman.gateway.platforms.vertx3.io.VertxApiRequestConverter.java

License:Apache License

public static void fromJson(JsonObject json, VertxApiRequest obj) {
    if (json.getValue("apiKey") instanceof String) {
        obj.setApiKey((String) json.getValue("apiKey"));
    }/*from w w  w  . j a  v  a  2 s .c  om*/
    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"));
    }
}

From source file:io.apiman.gateway.platforms.vertx3.io.VertxApiResponseConverter.java

License:Apache License

public static void fromJson(JsonObject json, VertxApiResponse obj) {
    if (json.getValue("attributes") instanceof JsonObject) {
        java.util.Map<String, java.lang.Object> map = new java.util.LinkedHashMap<>();
        json.getJsonObject("attributes").forEach(entry -> {
            if (entry.getValue() instanceof Object)
                map.put(entry.getKey(), entry.getValue());
        });//from w w w .  j av a2 s. co  m
        obj.setAttributes(map);
    }
    if (json.getValue("code") instanceof Number) {
        obj.setCode(((Number) json.getValue("code")).intValue());
    }
    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("message") instanceof String) {
        obj.setMessage((String) json.getValue("message"));
    }
}

From source file:io.apiman.gateway.platforms.vertx3.io.VertxPolicyFailureConverter.java

License:Apache License

public static void fromJson(JsonObject json, VertxPolicyFailure obj) {
    if (json.getValue("failureCode") instanceof Number) {
        obj.setFailureCode(((Number) json.getValue("failureCode")).intValue());
    }// w  ww  . ja  va  2 s  .com
    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("message") instanceof String) {
        obj.setMessage((String) json.getValue("message"));
    }
    if (json.getValue("raw") instanceof String) {
        obj.setRaw((String) json.getValue("raw"));
    }
    if (json.getValue("responseCode") instanceof Number) {
        obj.setResponseCode(((Number) json.getValue("responseCode")).intValue());
    }
    if (json.getValue("type") instanceof String) {
        obj.setType(io.apiman.gateway.engine.beans.PolicyFailureType.valueOf((String) json.getValue("type")));
    }
}

From source file:io.apiman.gateway.platforms.vertx3.io.VertxServiceRequestConverter.java

License:Apache License

public static void fromJson(JsonObject json, VertxServiceRequest obj) {
    if (json.getValue("apiKey") instanceof String) {
        obj.setApiKey((String) json.getValue("apiKey"));
    }//from w w w  .  j a va  2  s.c om
    if (json.getValue("destination") instanceof String) {
        obj.setDestination((String) json.getValue("destination"));
    }
    if (json.getValue("headers") instanceof JsonObject) {
        java.util.Map<String, java.lang.String> map = new java.util.LinkedHashMap<>();
        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) {
        java.util.Map<String, java.lang.String> map = new java.util.LinkedHashMap<>();
        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.setServiceId((String) json.getValue("serviceId"));
    }
    if (json.getValue("serviceOrgId") instanceof String) {
        obj.setServiceOrgId((String) json.getValue("serviceOrgId"));
    }
    if (json.getValue("serviceVersion") instanceof String) {
        obj.setServiceVersion((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"));
    }
}

From source file:io.apiman.gateway.platforms.vertx3.io.VertxServiceResponseConverter.java

License:Apache License

public static void fromJson(JsonObject json, VertxServiceResponse obj) {
    if (json.getValue("attributes") instanceof JsonObject) {
        java.util.Map<String, java.lang.Object> map = new java.util.LinkedHashMap<>();
        json.getJsonObject("attributes").forEach(entry -> {
            if (entry.getValue() instanceof Object)
                map.put(entry.getKey(), entry.getValue());
        });/*from   w  ww.  j a  v  a2  s  .  c  o m*/
        obj.setAttributes(map);
    }
    if (json.getValue("code") instanceof Number) {
        obj.setCode(((Number) json.getValue("code")).intValue());
    }
    if (json.getValue("headers") instanceof JsonObject) {
        java.util.Map<String, java.lang.String> map = new java.util.LinkedHashMap<>();
        json.getJsonObject("headers").forEach(entry -> {
            if (entry.getValue() instanceof String)
                map.put(entry.getKey(), (String) entry.getValue());
        });
        obj.setHeaders(map);
    }
    if (json.getValue("message") instanceof String) {
        obj.setMessage((String) json.getValue("message"));
    }
}