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() 

Source Link

Document

Create a new, empty instance

Usage

From source file:Console.java

private void handleCreateFolder(RoutingContext routingContext) {
    String projectId = routingContext.request().getParam("projectId");
    //        String directoryName = routingContext.request().getParam("directory");
    String folderName = routingContext.request().getParam("folderName");

    System.out.println("Create file " + projectId + " " + folderName);
    FileAccess.getInstance().createFolder(projectId, folderName, hand -> {
        HttpServerResponse response = routingContext.response();
        response.putHeader("content-type", "application/json")
                .end(new JsonObject().put("result", hand).toString());

    });/*w  ww .  j  av  a2  s. c o m*/
}

From source file:Console.java

private void handleCreateFile(RoutingContext routingContext) {
    String projectId = routingContext.request().getParam("projectId");
    String directory = routingContext.request().getParam("directory");
    String fileName = routingContext.request().getParam("fileName");

    System.out.println("Create file " + projectId + " " + directory + " " + fileName);
    FileAccess.getInstance().createFile(projectId, directory, fileName, hand -> {

        HttpServerResponse response = routingContext.response();
        response.putHeader("content-type", "application/json")
                .end(new JsonObject().put("result", hand).toString());

    });/*from w w  w .j a  v  a 2 s . c o m*/
}

From source file:Console.java

private void handleCreateProject(RoutingContext routingContext) {

    routingContext.response().putHeader("content-type", "application/json");

    routingContext.request().bodyHandler(hndlr -> {

        System.out.println(hndlr.toString());

        JsonObject project = hndlr.toJsonObject();

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();

        String projectId = username + "_" + UUID.randomUUID().toString().replace("-", "");
        DbHelper.getInstance().createProject(this.username, projectId, project.getString("name"),
                project.getString("detail"), project.getString("visibility"), dateFormat.format(date),
                dateFormat.format(date), project.getString("board"), project.getString("ic"), handler -> {
                    FileAccess.getInstance().createFolder(projectId, "", resultWrite -> {
                        if (resultWrite) {
                            FileAccess.getInstance().writeFile(projectId, "main.ino", "example",
                                    resultWriteText -> {
                                        routingContext.response()
                                                .end(new JsonObject().put("result", resultWriteText)
                                                        .put("projectId", projectId).toString());
                                    });//from   www .j  a v a 2  s.  c  om
                        } else {
                            routingContext.response()
                                    .end(new JsonObject().put("result", resultWrite).toString());
                        }
                    });
                });

    });

}

From source file:Console.java

private void handleSaveFile(RoutingContext routingContext) {

    //        routingContext.request().handler(hndlr->{
    //            String projectId = routingContext.request().getParam("projectId");
    //            System.out.println("project name " + projectId);
    //            String fileId = routingContext.request().getParam("fileId");
    //            fileId = new String(new Base32().decode(fileId.replace("0", "=")));
    //            System.out.println("file name " + fileId);
    ////from   w  w w  .ja  v  a 2 s  .c o  m
    //            System.out.println("source " + new String(hndlr.getBytes()));
    //
    //            HttpServerResponse response = routingContext.response();
    //
    //            FileAccess.getInstance().
    //                    saveFile(hndlr.toString(), projectId, fileId, handlerr -> {
    //                        routingContext.response().
    //                                end(new JsonObject().
    //                                        put("result", handlerr).toString());
    //                    });
    //
    //        });
    routingContext.response().putHeader("content-type", "application/json");
    routingContext.request().bodyHandler(hndlr -> {
        String projectId = routingContext.request().getParam("projectId");
        System.out.println("project name " + projectId);
        String fileId = routingContext.request().getParam("fileId");
        fileId = new String(new Base32().decode(fileId.replace("0", "=")));
        System.out.println("file name " + fileId);

        System.out.println("source " + new String(hndlr.getBytes()));

        HttpServerResponse response = routingContext.response();

        FileAccess.getInstance().saveFile(hndlr.toString(), projectId, fileId, handlerr -> {
            routingContext.response().end(new JsonObject().put("result", handlerr).toString());
        });

    });

}

From source file:HelloServiceVerticle.java

License:Apache License

@Override
public void handle(Message<JsonObject> requestMsg) {
    System.out.println("Hello-Service-Verticle received request : " + requestMsg.body().encodePrettily());

    JsonObject replyMsg = new JsonObject();
    replyMsg.put("body", "HELLO " + requestMsg.body().getString("body").toUpperCase());
    requestMsg.reply(replyMsg);//from  w  ww.j  a v  a2  s .  c o m

    System.out.println("Hello-Service-Verticle sent reply : " + replyMsg.encodePrettily());
}

From source file:ClientVerticle.java

License:Apache License

@Override
public void start() {
    JsonObject requestMsg = new JsonObject();
    requestMsg.put("body", "rajith muditha attapattu");
    vertx.eventBus().send("hello-service-amqp", requestMsg, this);
    System.out.println("Client verticle sent request : " + requestMsg.encodePrettily());
}

From source file:PublishToQueueVerticle.java

License:Apache License

@Override
public void start() throws Exception {
    final AMQPService service = AMQPService.createEventBusProxy(vertx, "vertx.service-amqp");
    registerForNotifications(service);/*from   ww  w.  j a  va 2  s . c om*/

    // 1. Setup an outgoing-link to 'amqp://localhost:6672/my-queue' and map
    // it to vert.x address 'my-pub-queue'
    OutgoingLinkOptions options = new OutgoingLinkOptions();
    options.setReliability(ReliabilityMode.AT_LEAST_ONCE);

    System.out.println(
            "Attempting to establish an outgoing link from the bridge to 'amqp://localhost:5672/my-queue'");
    service.establishOutgoingLink("amqp://localhost:6672/my-queue", "my-pub-queue", "my-pub-notifications",
            options, result -> {
                if (result.succeeded()) {
                    outgoingLinkRef = result.result();
                    System.out.println("Outgoing link ref : " + outgoingLinkRef);
                    // 2. Send a message to vert.x address 'my-pub-queue'
                    // Use a unique id for outgoing msg ref. When a delivery
                    // notification is set, you could use this ref to
                    // correlate the tracker to the original message.
                    System.out.println("Sending a message to vertx address my-pub-queue");
                    vertx.eventBus().publish("my-pub-queue", new JsonObject().put("body", "rajith")
                            .put(AMQPService.OUTGOING_MSG_REF, "msg-ref".concat(String.valueOf(i++))));
                } else {
                    System.out.println(
                            "Error occured while setting up outgoing link from application to AMQP peer: "
                                    + result.cause());
                    result.cause().printStackTrace();
                }
            });
}

From source file:PubVerticle.java

License:Apache License

@Override
public void start() {
    JsonObject msg1 = new JsonObject();
    msg1.put("vertx.routing-key", "foo.bar");
    msg1.put("body", "hello world from foo bar");
    vertx.eventBus().publish("vertx.service-amqp.bridge", msg1);
    System.out.println("Publiser verticle sent msg : " + msg1.encodePrettily());

    JsonObject msg2 = new JsonObject();
    msg2.put("vertx.routing-key", "foo.baz");
    msg2.put("body", "hello world from foo baz");
    vertx.eventBus().publish("vertx.service-amqp.bridge", msg2);
    System.out.println("Publiser verticle sent msg : " + msg2.encodePrettily());
}

From source file:FortuneCookieClientVerticle.java

License:Apache License

private void sendRequest() {
    print("Sent a request for a fortune cookie");
    vertx.eventBus().<JsonObject>send(publishAddr, new JsonObject(), resp -> {
        JsonObject msg = resp.result().body();
        print("Received my fortune cookie : '%s'", msg.getString("body"));
        service.accept(msg.getString(AMQPService.INCOMING_MSG_REF), result -> {
        });// w w w .j  a v a2 s.c  o  m
        print("Accepted the cookie");
        print("====================================");
    });
}

From source file:ServerVerticle.java

License:Apache License

@Override
public void handle(Message<JsonObject> requestMsg) {
    System.out.println("Server verticle received request : " + requestMsg.body().encodePrettily());

    JsonObject replyMsg = new JsonObject();
    replyMsg.put("body", "HELLO " + requestMsg.body().getString("body").toUpperCase());
    requestMsg.reply(replyMsg);//from  w w w.j  a v  a2s. c o  m

    System.out.println("Server verticle sent reply : " + replyMsg.encodePrettily());
}