List of usage examples for io.vertx.core.json JsonObject JsonObject
public JsonObject()
From source file:eu.rethink.mn.component.HypertyAllocationManager.java
License:Apache License
@Override public void handle(PipeContext ctx) { final PipeMessage msg = ctx.getMessage(); if (msg.getType().equals("create")) { //process JSON msg requesting a number of available addresses final JsonObject msgBodyValue = msg.getBody().getJsonObject("value"); int number = msgBodyValue.getInteger("number", 5); final List<String> allocated = allocate(ctx, number); final PipeMessage reply = new PipeMessage(); reply.setId(msg.getId());/*from w w w. j a v a 2 s.co m*/ reply.setFrom(name); reply.setTo(msg.getFrom()); reply.setReplyCode(ReplyCode.OK); final JsonObject value = new JsonObject(); value.put("allocated", new JsonArray(allocated)); reply.getBody().put("value", value); ctx.reply(reply); } else { //TODO: deallocate !? } }
From source file:eu.rethink.mn.component.ObjectAllocationManager.java
License:Apache License
@Override public void handle(PipeContext ctx) { final PipeMessage msg = ctx.getMessage(); final JsonObject body = msg.getBody(); if (msg.getType().equals("create")) { //process JSON msg requesting a number of available addresses final String scheme = body.getString("scheme"); //on value final JsonObject msgBodyValue = body.getJsonObject("value"); final int number = msgBodyValue.getInteger("number", 5); final List<String> allocated = allocate(ctx, scheme, number); final PipeMessage reply = new PipeMessage(); reply.setId(msg.getId());// ww w . j a va2 s. c om reply.setFrom(name); reply.setTo(msg.getFrom()); reply.setReplyCode(ReplyCode.OK); final JsonObject value = new JsonObject(); value.put("allocated", new JsonArray(allocated)); reply.getBody().put("value", value); ctx.reply(reply); } else if (msg.getType().equals("delete")) { //process JSON msg releasing an address final String resource = body.getString("resource"); deallocate(ctx, resource); ctx.replyOK(name); } }
From source file:eu.rethink.mn.pipeline.message.PipeMessage.java
License:Apache License
public PipeMessage() { this(new JsonObject()); }
From source file:eu.rethink.mn.pipeline.message.PipeMessage.java
License:Apache License
public JsonObject getBody() { if (!msg.containsKey("body")) { msg.put("body", new JsonObject()); }/*from w ww .j a va 2 s . c o m*/ return msg.getJsonObject("body"); }
From source file:eventbusbridge.Main.java
License:Apache License
public static void main(String[] args) { final Vertx vertx = Vertx.vertx(); final EventBus eb = vertx.eventBus(); TcpEventBusBridge bridge = TcpEventBusBridge.create(vertx, new BridgeOptions().addOutboundPermitted(new PermittedOptions().setAddressRegex("test.*")) .addInboundPermitted(new PermittedOptions().setAddressRegex("test.*"))); final int port = Integer.parseInt(args[0]); final File semaphoreFile; if (args.length > 1) { semaphoreFile = new File(args[1]); } else {// w w w. ja v a 2 s . c o m semaphoreFile = null; } bridge.listen(port, res -> { System.out.println("Vert.x bridge started on " + port); if (semaphoreFile != null) { try { semaphoreFile.createNewFile(); } catch (IOException e) { System.err.println(e); } } vertx.setPeriodic(100, timer -> { //System.out.println("Sending the time..."); eb.publish("test.time", new JsonObject().put("now", System.currentTimeMillis())); eb.send("test.time-send", new JsonObject().put("now", System.currentTimeMillis())); }); vertx.eventBus().consumer("test.echo", m -> { //System.out.println("echo: " + m.body()); JsonObject reply = new JsonObject(); JsonObject headers = new JsonObject(); m.headers().forEach(e -> headers.put(e.getKey(), e.getValue())); reply.put("original-body", m.body()).put("original-headers", headers); //System.out.println("REPLY: " + m.headers() + " | " + reply); m.reply(reply); // send a copy to another address as well to test // non-replyable messages if (m.isSend()) { eb.send("test.echo.responses", reply); } else { eb.publish("test.echo.responses", reply); } }); vertx.eventBus().consumer("test.ping-pong", Main::pingPong); }); }
From source file:eventbusbridge.Main.java
License:Apache License
static void pingPong(final Message<JsonObject> m) { final int counter = m.body().getInteger("counter"); System.out.println("ping-pong: count is " + counter); final JsonObject reply = new JsonObject(); reply.put("counter", counter + 1); m.reply(reply, pingPongReply);/*from w ww . j ava2 s .c o m*/ }
From source file:examples.AuthCommonExamples.java
License:Open Source License
public void example1(AuthProvider authProvider) { JsonObject authInfo = new JsonObject().put("username", "tim").put("password", "mypassword"); authProvider.authenticate(authInfo, res -> { if (res.succeeded()) { User user = res.result();/*from w ww . j av a2 s.com*/ System.out.println("User " + user.principal() + " is now authenticated"); } else { res.cause().printStackTrace(); } }); }
From source file:examples.AuthHtdigestExamples.java
License:Open Source License
public void example2(HtdigestAuth authProvider) { JsonObject authInfo = new JsonObject().put("username", "Mufasa").put("realm", "testrealm@host.com") .put("nonce", "dcd98b7102dd2f0e8b11d0f600bfb0c093").put("method", "GET") .put("uri", "/dir/index.html").put("response", "6629fae49393a05397450978507c4ef1"); authProvider.authenticate(authInfo, res -> { if (res.succeeded()) { User user = res.result();/*from w w w . j a va2 s . c om*/ } else { // Failed! } }); }
From source file:examples.AuthHtpasswdExamples.java
License:Open Source License
public void example2(HtpasswdAuth authProvider) { JsonObject authInfo = new JsonObject().put("username", "someUser").put("password", "somePassword"); authProvider.authenticate(authInfo, res -> { if (res.succeeded()) { User user = res.result();// www . j a v a 2 s .co m } else { // Failed! } }); }
From source file:examples.AuthJDBCExamples.java
License:Open Source License
public void example6(AuthProvider authProvider) { JsonObject authInfo = new JsonObject().put("username", "tim").put("password", "sausages"); authProvider.authenticate(authInfo, res -> { if (res.succeeded()) { User user = res.result();//from w w w . j a va 2 s. c om } else { // Failed! } }); }