List of usage examples for io.vertx.core.eventbus Message headers
MultiMap headers();
From source file:com.englishtown.vertx.elasticsearch.ElasticSearchServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { JsonObject json = msg.body();// w w w .j a v a 2 s.co m String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "start": { service.start(); break; } case "stop": { service.stop(); break; } case "index": { service.index((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"), (io.vertx.core.json.JsonObject) json.getValue("source"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.IndexOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "update": { service.update((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"), (java.lang.String) json.getValue("id"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.UpdateOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "get": { service.get((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"), (java.lang.String) json.getValue("id"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.GetOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "search": { service.search(convertList(json.getJsonArray("indices").getList()), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.SearchOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "searchScroll": { service.searchScroll((java.lang.String) json.getValue("scrollId"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.SearchScrollOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "delete": { service.delete((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"), (java.lang.String) json.getValue("id"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.DeleteOptions(json.getJsonObject("options")), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } }
From source file:com.englishtown.vertx.mail.MailServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {//from w ww . j ava 2 s. c o m JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "start": { service.start(); break; } case "stop": { service.stop(); break; } case "send": { service.send( json.getJsonObject("options") == null ? null : new com.englishtown.vertx.mail.SendOptions(json.getJsonObject("options")), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.englishtown.vertx.solr.SolrServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/* ww w . j av a2s .c om*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "start": { service.start(); break; } case "stop": { service.stop(); break; } case "query": { service.query((io.vertx.core.json.JsonObject) json.getValue("query"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.solr.QueryOptions(json.getJsonObject("options")), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.fail(-1, t.getMessage()); throw t; } }
From source file:com.example.myservice.services.ProductServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { JsonObject json = msg.body();// w w w .ja v a 2 s . c o m String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "start": { service.start(); break; } case "stop": { service.stop(); break; } case "list": { service.list(createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } }
From source file:com.github.ithildir.airbot.service.GeoServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*from w ww . j av a2 s.c om*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "getLocationByCoordinates": { service.getLocationByCoordinates( json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()), json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } case "getLocationByQuery": { service.getLocationByQuery((java.lang.String) json.getValue("query"), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.github.ithildir.airbot.service.MeasurementServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {//from w ww.j a va2 s . c o m JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "getMeasurement": { service.getMeasurement( json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()), json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } case "getName": { service.getName(createHandler(msg)); break; } case "init": { service.init(createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.github.ithildir.airbot.service.UserServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*from w ww. j av a2 s . c o m*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "getUserLocation": { service.getUserLocation((java.lang.String) json.getValue("userId"), res -> { if (res.failed()) { if (res.cause() instanceof ServiceException) { msg.reply(res.cause()); } else { msg.reply(new ServiceException(-1, res.cause().getMessage())); } } else { msg.reply(res.result() == null ? null : res.result().toJson()); } }); break; } case "updateUserLocation": { service.updateUserLocation((java.lang.String) json.getValue("userId"), json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()), json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()), (java.lang.String) json.getValue("country"), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.github.meshuga.vertx.neo4j.rbac.auth.AuthServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { JsonObject json = msg.body();// w w w. j av a 2 s . c o m String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "hasPermission": { service.hasPermission((java.lang.String) json.getValue("userName"), (java.lang.String) json.getValue("permission"), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } }
From source file:com.github.vertx.node.example.HelloWorldServiceInterfaceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/*w ww . ja v a 2 s . c o m*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "hello": { service.hello((java.lang.String) json.getValue("message"), createHandler(msg)); break; } case "close": { service.close(); close(); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.fail(-1, t.getMessage()); throw t; } }
From source file:com.glt.cronjob.JobServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { JsonObject json = msg.body();//from www. j a v a 2s .c o m String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "close": { service.close(); break; } case "schedule": { service.schedule((io.vertx.core.json.JsonObject) json.getValue("jobDescriptor"), createHandler(msg)); break; } case "unschedule": { service.unschedule((io.vertx.core.json.JsonObject) json.getValue("jobDescriptor"), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } }