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

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

Introduction

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

Prototype

public JsonObject(Buffer buf) 

Source Link

Document

Create an instance from a buffer.

Usage

From source file:fr.wseduc.rack.services.RackServiceMongoImpl.java

License:Open Source License

public void deleteRack(String id, Handler<Either<String, JsonObject>> handler) {
    mongo.delete(collection, new JsonObject("{ \"_id\": \"" + id + "\" }"), validActionResultHandler(handler));
}

From source file:fr.wseduc.smsproxy.providers.ovh.OVHSmsProvider.java

License:Apache License

@Override
public void sendSms(final Message<JsonObject> message) {
    final JsonObject parameters = message.body().getJsonObject("parameters");
    logger.debug("[OVH][sendSms] Called with parameters : " + parameters);

    final Handler<HttpClientResponse> resultHandler = new Handler<HttpClientResponse>() {
        public void handle(HttpClientResponse response) {
            if (response == null) {
                sendError(message, "ovh.apicall.error", null);
            } else {
                response.bodyHandler(new Handler<Buffer>() {
                    public void handle(Buffer body) {
                        final JsonObject response = new JsonObject(body.toString());
                        final JsonArray invalidReceivers = response.getJsonArray("invalidReceivers",
                                new JsonArray());
                        final JsonArray validReceivers = response.getJsonArray("validReceivers",
                                new JsonArray());

                        if (validReceivers.size() == 0) {
                            sendError(message, "invalid.receivers.all", null, new JsonObject(body.toString()));
                        } else if (invalidReceivers.size() > 0) {
                            sendError(message, "invalid.receivers.partial", null,
                                    new JsonObject(body.toString()));
                        } else {
                            message.reply(response);
                        }//from w  ww .j  a  v  a2 s.c  o m
                    }
                });
            }
        }
    };

    Handler<String> serviceCallback = new Handler<String>() {
        public void handle(String service) {
            if (service == null) {
                sendError(message, "ovh.apicall.error", null);
            } else {
                ovhRestClient.post("/sms/" + service + "/jobs/", parameters, resultHandler);
            }
        }
    };

    retrieveSmsService(message, serviceCallback);
}

From source file:fr.wseduc.smsproxy.providers.ovh.OVHSmsProvider.java

License:Apache License

@Override
public void getInfo(final Message<JsonObject> message) {
    final JsonObject parameters = message.body().getJsonObject("parameters");
    logger.debug("[OVH][getInfo] Called with parameters : " + parameters);

    retrieveSmsService(message, new Handler<String>() {
        public void handle(String service) {
            if (service == null) {
                sendError(message, "ovh.apicall.error", null);
            } else {
                ovhRestClient.get("/sms/" + service, parameters, new Handler<HttpClientResponse>() {
                    public void handle(HttpClientResponse response) {
                        if (response == null) {
                            sendError(message, "ovh.apicall.error", null);
                            return;
                        }/*from  w w  w.j  a  v a2 s. c  om*/
                        response.bodyHandler(new Handler<Buffer>() {
                            public void handle(Buffer body) {
                                final JsonObject response = new JsonObject(body.toString());
                                message.reply(response);
                            }
                        });
                    }
                });
            }
        }
    });
}

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

License:Apache License

private void processData() {
    if (rawData.length() == 0) {
        log.warn("Remote file at {0} was empty.", uri);
        return;/*from   ww  w  .j a v a2  s .c om*/
    }
    try {
        JsonObject json = new JsonObject(rawData.toString("UTF-8").trim());
        log.trace("Processing JSON: {0}", json);
        if (clientResultHandler != null)
            clients = requireJsonArray("clients", json, Client.class);
        if (apiResultHandler != null)
            apis = requireJsonArray("apis", json, Api.class);
    } catch (DecodeException e) {
        exceptionHandler.handle(e);
    }
}

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

License:Apache License

protected Map<String, String> toFlatStringMap(JsonObject jsonObject) {
    if (jsonObject == null)
        return Collections.emptyMap();

    Map<String, String> outMap = new LinkedHashMap<>();
    // TODO figure out why this workaround is necessary.
    jsonMapToProperties("", new JsonObject(jsonObject.encode()).getMap(), outMap);
    substituteValues(outMap);//  w w w  .j a v  a2 s  .c  om
    return outMap;
}

From source file:io.apiman.gateway.platforms.vertx3.junit.resttest.Vertx3GatewayTestServer.java

License:Apache License

@Override
public void configure(JsonNode config) {
    ClassLoader classLoader = getClass().getClassLoader();
    String fPath = config.get("config").asText();
    File file = new File(classLoader.getResource(fPath).getFile());

    try {//from  w ww .  j av  a 2 s  .co m
        conf = new String(Files.readAllBytes(file.toPath()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    vertxConf = new JsonObject(conf);
    resetter = getResetter(config.get("resetter").asText());
}

From source file:io.apiman.gateway.test.junit.vertx3.ApiToFileRegistry.java

License:Apache License

private void publish(Api api) {
    JsonObject apiJson = new JsonObject(Json.encode(api));
    apis.add(apiJson);
    apiMap.put(api, apiJson);
}

From source file:io.apiman.gateway.test.junit.vertx3.ApiToFileRegistry.java

License:Apache License

private void register(Client client) {
    JsonObject clientJson = new JsonObject(Json.encode(client));
    clients.add(clientJson);
    clientMap.put(client, clientJson);
}

From source file:io.apiman.gateway.test.junit.vertx3.Vertx3GatewayFileRegistryServer.java

License:Apache License

private JsonObject loadJsonObjectFromResources(JsonNode nodeConfig, String name) {
    ClassLoader classLoader = getClass().getClassLoader();
    String fPath = nodeConfig.get(name).asText();
    File file = new File(classLoader.getResource(fPath).getFile());
    try {/*  w  w w  .  j a v  a2 s  . c om*/
        conf = new String(Files.readAllBytes(file.toPath()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new JsonObject(conf);
}