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:com.groupon.vertx.redis.RedisSocket.java

License:Apache License

public void close() {
    RedisCommand command = pendingCommands.poll();
    while (command != null) {
        command.setResponse(//from  ww w  .j  a v a2  s  .  co m
                new JsonObject("{\"status\":\"error\",\"message\":\"Socket closed unexpectedly\"}"));
        command = pendingCommands.poll();
    }

    socket.close();
}

From source file:com.groupon.vertx.utils.config.DefaultConfigParser.java

License:Apache License

@Override
public JsonObject parse(final String configuration) {
    return new JsonObject(configuration);
}

From source file:com.hpe.sw.cms.verticle.Boot.java

License:Apache License

public static void main(String... args) throws IOException {
    String file = args[0];/*  ww  w.j  av a 2 s. c o m*/
    //    String file="dockerWeb/startup.json";
    String confStr = FileUtils.readFileToString(new File(file));
    JsonObject jsonConf = new JsonObject(confStr);
    DeploymentOptions deploymentOptions = new DeploymentOptions(jsonConf);
    VertxOptions options = new VertxOptions();
    options.setMaxEventLoopExecuteTime(Long.MAX_VALUE);
    Vertx vertx = Vertx.vertx(options);
    vertx.deployVerticle(new Boot(), deploymentOptions, r -> {
        if (r.succeeded()) {
            LOG.info("Successfully deployed");
        } else {
            throw new RuntimeException(r.cause());
        }
    });
}

From source file:com.nasa.ElasticSearchAdapter.java

private JsonObject doPost(String url, String data) throws IOException {

    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    //add reuqest header
    con.setRequestMethod("POST");

    con.setDoOutput(true);//from  w  ww .j  av  a2  s .com
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(data);
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();
    //System.out.println("\nSending 'POST' request to URL : " + url);
    //System.out.println("Post parameters : " + data);
    //System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    //print result
    //System.out.println(response.toString());
    return new JsonObject(response.toString());
}

From source file:com.waves_rsp.ikb4stream.communication.web.VertxServer.java

License:Open Source License

/**
 * Reads a request from a routing context, and attach the response to it. It requests the database
 * with DatabaseReader./*from w  w  w .  j  a v a2 s. c o  m*/
 *
 * @param rc {@link RoutingContext}, which contains the request, and the response
 * @throws NullPointerException if rc is null
 */
private void getAnomalies(RoutingContext rc) {
    Request request;
    try {
        LOGGER.info("Received web request: {}", rc.getBodyAsJson());
        request = parseRequest(rc.getBodyAsJson());
        if (request == null) {
            rc.response().setStatusCode(400).putHeader("Content-type", "application/json;charset:utf-8")
                    .end("{\"error\": \"Invalid address\"}");
            return;
        }
    } catch (DecodeException | NullPointerException e) {
        LOGGER.info("Received an invalid format request : {} ", e.getMessage());
        LOGGER.debug("DecodeException: {}", e);
        rc.fail(400);
        return;
    }
    LOGGER.info("Request : {}", request);
    LOGGER.info("rc= {}", rc);
    rc.response().putHeader("content-type", "application/json");

    getEvent(request, (t, result) -> {
        if (t != null) {
            LOGGER.error("DatabaseReader error: " + t.getMessage());
            return;
        }
        LOGGER.info("Found events: {}", result);
        JsonObject response = new JsonObject("{\"events\":" + result + "}");
        rc.response().end(response.encode());
    });
}

From source file:com.zyxist.dirtyplayground.core.journal.MongoJournalWriter.java

License:Apache License

@Override
public void persist(JournalEvent event) {
    log.debug("Persisting event...");
    db.mongo().save("journal", new JsonObject(Json.encode(event)), (res) -> {
    });// w w  w .j a v a 2s .co  m
}

From source file:de.neofonie.deployer.ConfigLoader.java

License:Open Source License

/**
 * Load the global application configuration. The global application state
 * is merged with the external configuration. The external configuration
 * takes precedence.// w w  w.  java2  s  . co m
 *
 * @return The configuration for the deployer
 */
public static JsonObject loadConfiguration() {
    JsonObject result = null;

    // read file by convention
    LOG.info("Looking for the deployer configuration");
    URL appConf = loadURL();

    if (appConf != null) {
        LOG.info("Deployer configuration found");
        try {
            URI uri = appConf.toURI();
            initFileSystemIfNeeded(uri);

            byte[] readAllBytes = Files.readAllBytes(Paths.get(appConf.toURI()));
            result = new JsonObject(new String(readAllBytes, "UTF-8"));
            LOG.info("Deployer configuration loaded");

        } catch (IOException | URISyntaxException | DecodeException e) {
            LOG.log(Level.SEVERE, "Global application configuration invalid", e);
        }
    } else {
        LOG.info("Global application configuration not found.");
    }
    return result;
}

From source file:de.neofonie.deployer.DeployerMock.java

License:Open Source License

/**
 * Read a JSON configuration from the classpath.
 *
 * @param name The filename to read from.
 * @return JsonObject with the configuration.
 *//*from w ww . ja v a2s  .  c o  m*/
public static JsonObject readConfiguration(final String name) {
    JsonObject result = null;
    try {
        InputStream u = DeployerVerticleTest.class.getResourceAsStream(name);
        assertNotNull(u);
        result = new JsonObject(IOUtils.toString(u));
    } catch (IOException e) {
        fail(e.getMessage());
    }
    return result;
}

From source file:de.openflorian.alarm.AlarmFaxEventMessageCodec.java

License:Open Source License

@Override
public AlarmFaxEvent decodeFromWire(int position, Buffer buffer) {
    // My custom message starting from this *position* of buffer
    int _pos = position;

    // Length of JSON
    int length = buffer.getInt(_pos);

    String jsonStr = buffer.getString(_pos += 4, _pos += length);
    JsonObject contentJson = new JsonObject(jsonStr);

    String fileName = contentJson.getString(JSON_PROPERTY_FILENAME);

    return new AlarmFaxEvent(new File(fileName));
}

From source file:docoverride.json.Examples.java

License:Open Source License

public void example0_1() {
    String jsonString = "{\"foo\":\"bar\"}";
    JsonObject object = new JsonObject(jsonString);
}