List of usage examples for io.vertx.core.json JsonObject getString
public String getString(String key)
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 w ww. ja v a 2s .c om } else { routingContext.response() .end(new JsonObject().put("result", resultWrite).toString()); } }); }); }); }
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 ww . j av a2s .c om*/ print("Accepted the cookie"); print("===================================="); }); }
From source file:ConsumeFromQueueVerticle.java
License:Apache License
@Override public void start() throws Exception { final AMQPService service = AMQPService.createEventBusProxy(vertx, "vertx.service-amqp"); // 1. Create a vert.x consumer for address 'my-sub-queue' System.out.println("Creating a vertx consumer for my-sub-queue"); vertx.eventBus().consumer("my-sub-queue", message -> { // 4. The message should be received by the consumer created for // 'my-sub-queue'. JsonObject msg = (JsonObject) message.body(); System.out.println("Received a message: " + msg); // 5. Accept the message. System.out.println("Accepting message: " + msg.getString(AMQPService.INCOMING_MSG_REF)); service.accept(msg.getString(AMQPService.INCOMING_MSG_REF), result -> { if (result.failed()) { System.out.println("Error accepting the message : " + result.cause()); result.cause().printStackTrace(); }//from w w w.j a va2s . c o m // 6. Cancel the incoming and outgoing link mappings. service.cancelIncomingLink(incomingLinkRef, r -> { }); // Note we are not waiting for the results of step #6. }); }); // 2. Setup an incoming-link to 'amqp://localhost:6672/my-queue' and map // it to 'my-sub-queue' using the Service API. IncomingLinkOptions options = new IncomingLinkOptions(); options.setReliability(ReliabilityMode.AT_LEAST_ONCE); options.setPrefetch(10); System.out.println( "Attempting to establish an incoming link from 'amqp://localhost:6672/my-queue' to the bridge"); service.establishIncomingLink("amqp://localhost:6672/my-queue", "my-sub-queue", "my-sub-notifications", options, result -> { if (result.succeeded()) { incomingLinkRef = result.result(); System.out.println("Incoming link ref : " + incomingLinkRef); // Incoming link was successfully established. Now setup // outgoing link and send message. } else { System.out.println( "Error occured while setting up incoming link from AMQP peer to application: " + result.cause()); result.cause().printStackTrace(); System.exit(-1); } }); }
From source file:RestAPI.java
private void handleAddProduct(RoutingContext routingContext) { JsonObject project = new JsonObject(routingContext.getBodyAsString()); project.getString("name"); project.getString("board"); project.getString("ic"); project.getString("detail"); project.getString("visibility"); // System.out.println("from post "+routingContext.getBodyAsString()); // String productID = routingContext.request().getParam("productID"); HttpServerResponse response = routingContext.response(); // if (productID == null) { // sendError(400, response); // } else { // JsonObject product = routingContext.getBodyAsJson(); // if (product == null) { // sendError(400, response); // } else { // products.put(productID, product); response.end();//from ww w .jav a 2 s . c o m // } // } }
From source file:RestAPI.java
private void addProduct(JsonObject product) { products.put(product.getString("id"), product); }
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); }//from ww w. ja 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
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;// w w w.j ava 2 s.com 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:com.baldmountain.depot.models.BaseModel.java
License:Open Source License
BaseModel(String collection, JsonObject json) { this.collection = collection; id = json.getString("_id"); String s = json.getString("createdOn"); if (s != null) { try {//from www .ja v a2 s .c o m createdOn = dateFormat.parse(s); } catch (ParseException e) { // bad date, update to now createdOn = new Date(); } catch (NumberFormatException e) { // bug in the date parser createdOn = new Date(); } } else { createdOn = new Date(); } s = json.getString("updatedOn"); if (s != null && !s.isEmpty()) { try { updatedOn = dateFormat.parse(s); } catch (ParseException e) { // just ignore } catch (NumberFormatException e) { // just ignore } } }
From source file:com.baldmountain.depot.models.LineItem.java
License:Open Source License
public LineItem(JsonObject json) { super("line_items", json); cartId = json.getString("cart"); productId = json.getString("product"); count = json.getInteger("count", 1); }
From source file:com.baldmountain.depot.models.Product.java
License:Open Source License
public Product(JsonObject json) { super("products", json); title = json.getString("title"); description = json.getString("description"); imageUrl = json.getString("imageUrl"); if (json.containsKey("price")) { price = new BigDecimal(json.getDouble("price")).setScale(2, RoundingMode.CEILING); } else {/*from w w w .j a va2 s. c o m*/ price = BigDecimal.ZERO.setScale(2, RoundingMode.CEILING); } }