List of usage examples for io.vertx.core.json JsonObject put
public JsonObject put(String key, Object value)
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);//w w w.j ava2 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: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: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);/* w w w .j a v a 2 s .co m*/ System.out.println("Server verticle sent reply : " + replyMsg.encodePrettily()); }
From source file:FileAccess.java
public JsonObject getProjectStructure(String projectId) { JsonObject projectStructure = new JsonObject(); JsonArray rootFolder = new JsonArray(); JsonArray rootFile = new JsonArray(); List<String> rootDirectorys = vertx.fileSystem().readDirBlocking("project/" + projectId); System.out.println(new JsonArray(rootDirectorys).toString()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (String directory : rootDirectorys) { System.out.println(directory + "directory"); FileProps something = vertx.fileSystem().lpropsBlocking(directory); if (something.isDirectory()) { JsonObject directoryJSON = new JsonObject(); String splitDirectory[] = directory.split("\\\\"); directoryJSON.put("name", splitDirectory[splitDirectory.length - 1]); // tinggal tambahkan encode menggunakan base 64 agar tidak terdeteksi titik. String id = splitDirectory[splitDirectory.length - 2]; String tmpId = new Base32().encodeAsString(splitDirectory[splitDirectory.length - 1].getBytes()) .replace("=", "0"); directoryJSON.put("id", tmpId); directoryJSON.put("create_date", dateFormat.format(new Date(something.creationTime()))); directoryJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime()))); rootFolder.add(directoryJSON); List<String> subDirectorysFiles = vertx.fileSystem().readDirBlocking(directory); JsonArray subFiles = new JsonArray(); for (String subDirectoryFile : subDirectorysFiles) { JsonObject fileJSON = new JsonObject(); String splitFile[] = subDirectoryFile.split("\\\\"); fileJSON.put("name", splitFile[splitFile.length - 1]); fileJSON.put("id", new Base32().encodeAsString( (splitFile[splitFile.length - 2] + "/" + splitFile[splitFile.length - 1]).getBytes()) .replace("=", "0")); fileJSON.put("create_date", dateFormat.format(new Date(something.creationTime()))); fileJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime()))); subFiles.add(fileJSON);// w w w .j ava 2 s . com } directoryJSON.put("files", subFiles); } else { JsonObject fileJSON = new JsonObject(); String splitFile[] = directory.split("\\\\"); fileJSON.put("name", splitFile[splitFile.length - 1]); fileJSON.put("id", new Base32().encodeAsString(splitFile[splitFile.length - 1].getBytes()).replace("=", "0")); fileJSON.put("create_date", dateFormat.format(new Date(something.creationTime()))); fileJSON.put("modify_date", dateFormat.format(new Date(something.lastModifiedTime()))); rootFile.add(fileJSON); } } projectStructure.put("folders", rootFolder); projectStructure.put("files", rootFile); System.out.println(projectStructure.toString()); return projectStructure; }
From source file:FortuneCookieServiceVerticle.java
License:Apache License
@Override public void start() throws Exception { try (BufferedReader br = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream("/fortune-cookie.txt")))) { for (String line; (line = br.readLine()) != null;) { fortuneCookies.put(++bound, line); }/*ww w. j a v a 2s. co m*/ } catch (Exception e) { throw new RuntimeException("Error setting up FortuneCookieServiceVerticle"); } service = AMQPService.createEventBusProxy(vertx, "vertx.service-amqp"); ServiceOptions options = new ServiceOptions(); service.registerService(serviceAddress, noticeAddress, options, result -> { if (result.succeeded()) { print("Service registered succesfully with the vertx-amqp-bridge using address : '%s'", serviceAddress); } else { print("Unable to register service"); } }); vertx.eventBus().<JsonObject>consumer(serviceAddress, msg -> { JsonObject request = msg.body(); // print(request.encodePrettily()); String linkId = request.getString(AMQPService.INCOMING_MSG_LINK_REF); print("Received a request for a fortune-cookie from client [%s]", linkId); print("reply-to %s", msg.replyAddress()); service.accept(request.getString(AMQPService.INCOMING_MSG_REF), result -> { }); JsonObject response = new JsonObject(); response.put(AMQPService.OUTGOING_MSG_REF, linkId); response.put("body", fortuneCookies.get(random.nextInt(bound))); msg.reply(response); }); vertx.eventBus().<JsonObject>consumer(noticeAddress, msg -> { NotificationType type = NotificationHelper.getType(msg.body()); if (type == NotificationType.DELIVERY_STATE) { DeliveryTracker tracker = NotificationHelper.getDeliveryTracker(msg.body()); print("The the fortune-cookie is acknowledged by the client. Issuing another request credit after a 30s delay"); print("=============================================================\n"); vertx.setTimer(30 * 1000, timer -> { service.issueCredits(tracker.getMessageRef(), 1, result -> { }); }); } else if (type == NotificationType.INCOMING_LINK_OPENED) { String linkRef = NotificationHelper.getLinkRef(msg.body()); print("A client [%s] contacted the fortune-cookie service, issueing a single request-credit to start with", linkRef); print("============================================================="); service.issueCredits(linkRef, 1, result -> { }); } }); }
From source file:DbHelper.java
private void getFileFromFrolder(String projectId, List<JsonObject> listFolders, Handler<JsonArray> handler) { String queryFile = "SELECT files.`name` as name, files.crete_date as dateCreated, files.modify_date as dateModified , files.pk_id_file as id, files.FOLDERS_pk_id_folder as folderId FROM folders RIGHT JOIN files ON folders.pk_id_folder=files.pk_id_file and folders.pk_id_folder IN (SELECT pk_id_folder FROM folders WHERE `PROJECT_pk_id_project`=" + projectId + ")"; mySQLClient.getConnection(resConnection -> { if (resConnection.succeeded()) { SQLConnection connection;/*from w w w . jav a 2s .c o m*/ connection = resConnection.result(); connection.setAutoCommit(false, autoCommit -> { if (autoCommit.succeeded()) { connection.query(queryFile, handlerQuery -> { if (handlerQuery.succeeded()) { ResultSet resultSet = handlerQuery.result(); List<JsonObject> listFiles = resultSet.getRows(); // System.out.println(new JsonArray(list).toString()); for (JsonObject listFile : listFiles) { int folderId = listFile.getInteger("folderId"); // System.out.println("id folder " + folderId); for (JsonObject listFolder : listFolders) { if (listFolder.getInteger("id") == folderId) { try { listFolder.getJsonArray("files").add(listFile); } catch (Exception e) { List<JsonObject> listTmpFile = new ArrayList<>(); listTmpFile.add(listFile); listFolder.put("files", listTmpFile); } } } } // System.out.println(new JsonArray(listFolders).toString()); handler.handle(new JsonArray(listFolders)); } else { System.out.println("failed " + handlerQuery.cause()); } connection.close(); }); } else { System.out.println("auto commit failed"); } }); // Got a connection } else { // Failed to get connection - deal with it System.out.println("true failes"); } }); }
From source file:DbHelper.java
public void getProject(String projectId, Handler<JsonObject> handlerRequest) { String queryFolder = "SELECT pk_id_project as id, name , detail, board_type as arduinoType, ic_type as icType, accessbility FROM project WHERE project.pk_id_project ='" + projectId + "';"; System.out.println(queryFolder); mySQLClient.getConnection(resConnection -> { if (resConnection.succeeded()) { SQLConnection connection;/*from w w w . ja v a2s .c o m*/ connection = resConnection.result(); connection.setAutoCommit(false, autoCommit -> { if (autoCommit.succeeded()) { connection.query(queryFolder, handlerQuery -> { if (handlerQuery.succeeded()) { ResultSet resultSet = handlerQuery.result(); JsonObject resultJSON = resultSet.getRows().get(0); JsonObject project = new JsonObject(); project.put("id", resultJSON.getString("id")); project.put("name", resultJSON.getString("name")); project.put("detail", resultJSON.getString("detail")); JsonObject configProject = new JsonObject(); configProject.put("arduinoType", resultJSON.getString("arduinoType")); configProject.put("icType", resultJSON.getString("icType")); configProject.put("arduinoType", resultJSON.getString("arduinoType")); configProject.put("acessbility", resultJSON.getString("acessbility")); configProject.put("port", "com3"); project.put("config", configProject); handlerRequest.handle(project); // getProjectStructure(projectId, handler -> { // System.out.println("finisssss--------------------"); // JsonObject folders = new JsonObject(); // folders.put("folders", handler); // project.put("sourceCode", folders); //// project.put("files", new JsonArray().add(handler.getJsonObject(0).getJsonArray("files").getJsonObject(0))); //// System.out.println(project.toString()); // handlerRequest.handle(project); // }); } else { System.out.println("failed " + handlerQuery.cause()); } connection.close(); }); } else { System.out.println("auto commit failed"); } }); // Got a connection } else { // Failed to get connection - deal with it System.out.println("true failes"); } }); }
From source file:co.runrightfast.vertx.core.impl.VertxServiceImpl.java
License:Apache License
private void logVertxOptions() { LOG.logp(CONFIG, getClass().getName(), "logVertxOptions", () -> { final JsonObject json = new JsonObject() .put("BlockedThreadCheckInterval", vertxOptions.getBlockedThreadCheckInterval()) .put("ClusterHost", vertxOptions.getClusterHost()) .put("ClusterPingInterval", vertxOptions.getClusterPingInterval()) .put("ClusterPingReplyInterval", vertxOptions.getClusterPingReplyInterval()) .put("ClusterPort", vertxOptions.getClusterPort()) .put("EventLoopPoolSize", vertxOptions.getEventLoopPoolSize()) .put("HAGroup", vertxOptions.getHAGroup()) .put("InternalBlockingPoolSize", vertxOptions.getInternalBlockingPoolSize()) .put("MaxEventLoopExecuteTime", vertxOptions.getMaxEventLoopExecuteTime()) .put("MaxWorkerExecuteTime", vertxOptions.getMaxWorkerExecuteTime()) .put("QuorumSize", vertxOptions.getQuorumSize()) .put("WarningExceptionTime", vertxOptions.getWarningExceptionTime()) .put("WorkerPoolSize", vertxOptions.getWorkerPoolSize()); final ClusterManager clusterManager = vertxOptions.getClusterManager(); if (clusterManager != null) { json.put("clusterManagerClass", clusterManager.getClass().getName()); }//from ww w . j ava 2s .c om final MetricsOptions metricsOptions = vertxOptions.getMetricsOptions(); if (metricsOptions != null) { json.put("MetricsOptions", toJsonObject(metricsOptions)); } return json.encodePrettily(); }); }
From source file:co.runrightfast.vertx.core.impl.VertxServiceImpl.java
License:Apache License
private JsonObject toJsonObject(final MetricsOptions metricsOptions) { if (metricsOptions instanceof DropwizardMetricsOptions) { final DropwizardMetricsOptions dropwizardMetricsOptions = (DropwizardMetricsOptions) metricsOptions; final JsonObject json = new JsonObject().put("enabled", metricsOptions.isEnabled()).put("jmxEnabled", dropwizardMetricsOptions.isJmxEnabled()); toJsonObject(dropwizardMetricsOptions.getMonitoredEventBusHandlers()) .ifPresent(jsonArray -> json.put("MonitoredEventBusHandlers", jsonArray)); toJsonObject(dropwizardMetricsOptions.getMonitoredHttpClientUris()) .ifPresent(jsonArray -> json.put("MonitoredHttpClientUris", jsonArray)); toJsonObject(dropwizardMetricsOptions.getMonitoredHttpServerUris()) .ifPresent(jsonArray -> json.put("MonitoredHttpServerUris", jsonArray)); return json; } else {// w w w. j av a 2 s. co m return new JsonObject().put("enabled", metricsOptions.isEnabled()); } }