List of usage examples for io.vertx.core.json JsonObject JsonObject
public JsonObject(Buffer buf)
From source file:com.englishtown.vertx.cassandra.binarystore.integration.IntegrationTestHelper.java
License:Open Source License
public static JsonObject loadConfig() { try (InputStream stream = IntegrationTestHelper.class.getResourceAsStream("/config.json")) { StringBuilder sb = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); String line = reader.readLine(); while (line != null) { sb.append(line).append('\n'); line = reader.readLine();//from w ww . j a v a2s .c o m } return new JsonObject(sb.toString()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.funmix.entity.Driver.java
public Driver(String jsonStr) { DriverConverter.fromJson(new JsonObject(jsonStr), this); }
From source file:com.funmix.entity.Line.java
public Line(String jsonStr) { LineConverter.fromJson(new JsonObject(jsonStr), this); }
From source file:com.funmix.entity.Order.java
public Order(String jsonStr) { OrderConverter.fromJson(new JsonObject(jsonStr), this); }
From source file:com.funmix.entity.Truck.java
public Truck(String jsonStr) { TruckConverter.fromJson(new JsonObject(jsonStr), this); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void create(String data, RBatch redissonBatch, AsyncResultHandler<String> resultHandler) { vertx.<JsonObject>executeBlocking(f -> { JsonObject d = new JsonObject(data); if (schema == null && !f.isComplete()) { f.complete(d);/*from w w w . j a v a 2s .c om*/ return; } try { ProcessingReport validate = VALIDATOR.validate(schema, Json.mapper.readTree(data)); if (validate.isSuccess() && !d.containsKey("id") && !f.isComplete()) { f.complete(d); } else if (!f.isComplete()) { f.fail(new RepositoryException("Invalid Data")); } } catch (ProcessingException | IOException ex) { if (!f.isComplete()) { f.fail(ex); } } }, result -> { if (result.succeeded()) { createWithoutValidate(result.result(), redissonBatch, resultHandler); } else { resultHandler.handle(Future.failedFuture(result.cause())); } }); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
License:Apache License
private void update(String id, String data, RBatch redissonBatch, Handler<AsyncResult<Boolean>> resultHandler) { vertx.<JsonObject>executeBlocking(f -> { JsonObject d = new JsonObject(data); if (schema == null && !f.isComplete()) { f.complete(d);/*from w w w .j a v a 2 s . c o m*/ return; } try { ProcessingReport validate = VALIDATOR.validate(schema, Json.mapper.readTree(data)); if (id != null && validate.isSuccess() && d.containsKey("id") && id.equals(d.getString("id")) && !f.isComplete()) { f.complete(d); } else if (!f.isComplete()) { f.fail(new RepositoryException("Invalid Data")); } } catch (ProcessingException | IOException ex) { if (!f.isComplete()) { f.fail(ex); } } }, result -> { if (result.succeeded()) { updateWithoutValidate(id, result.result(), redissonBatch, resultHandler); } else { resultHandler.handle(Future.failedFuture(result.cause())); } }); }
From source file:com.github.jackygurui.vertxredissonrepository.repository.index.DefaultValueResolver.java
License:Apache License
@Override public String lookup(String indexedValue, RedissonIndex index) { return new JsonObject(indexedValue).getString("id"); }
From source file:com.glencoesoftware.omero.ms.thumbnail.ThumbnailVerticle.java
License:Open Source License
/** * Render thumbnail event handler. Responds with a <code>image/jpeg</code> * body on success or a failure./* w w w . jav a 2 s. c om*/ * @param message JSON encoded event data. Required keys are * <code>omeroSessionKey</code> (String), <code>longestSide</code> * (Integer), and <code>imageId</code> (Long). */ private void renderThumbnail(Message<String> message) { JsonObject data = new JsonObject(message.body()); String omeroSessionKey = data.getString("omeroSessionKey"); int longestSide = data.getInteger("longestSide"); long imageId = data.getLong("imageId"); Optional<Long> renderingDefId = Optional.ofNullable(data.getLong("renderingDefId")); log.debug("Render thumbnail request Image:{} longest side {} RenderingDef:{}", imageId, longestSide, renderingDefId.orElse(null)); try (OmeroRequest request = new OmeroRequest(host, port, omeroSessionKey)) { byte[] thumbnail = request .execute(new ThumbnailRequestHandler(longestSide, imageId, renderingDefId)::renderThumbnail); if (thumbnail == null) { message.fail(404, "Cannot find Image:" + imageId); } else { message.reply(thumbnail); } } catch (PermissionDeniedException | CannotCreateSessionException e) { String v = "Permission denied"; log.debug(v); message.fail(403, v); } catch (Exception e) { String v = "Exception while retrieving thumbnail"; log.error(v, e); message.fail(500, v); } }
From source file:com.glencoesoftware.omero.ms.thumbnail.ThumbnailVerticle.java
License:Open Source License
/** * Get thumbnails event handler. Responds with a JSON dictionary of Base64 * encoded <code>image/jpeg</code> thumbnails keyed by {@link Image} * identifier. Each dictionary value is prefixed with * <code>data:image/jpeg;base64,</code> so that it can be used with * <a href="http://caniuse.com/#feat=datauri">data URIs</a>. * @param message JSON encoded event data. Required keys are * <code>omeroSessionKey</code> (String), <code>longestSide</code> * (Integer), and <code>imageIds</code> (List<Long>). *//* w w w . j a v a2 s .c o m*/ private void getThumbnails(Message<String> message) { JsonObject data = new JsonObject(message.body()); String omeroSessionKey = data.getString("omeroSessionKey"); int longestSide = data.getInteger("longestSide"); JsonArray imageIdsJson = data.getJsonArray("imageIds"); List<Long> imageIds = new ArrayList<Long>(); for (int i = 0; i < imageIdsJson.size(); i++) { imageIds.add(imageIdsJson.getLong(i)); } log.debug("Render thumbnail request ImageIds:{} longest side {}", imageIds, longestSide); try (OmeroRequest request = new OmeroRequest(host, port, omeroSessionKey)) { Map<Long, byte[]> thumbnails = request .execute(new ThumbnailsRequestHandler(longestSide, imageIds)::renderThumbnails); if (thumbnails == null) { message.fail(404, "Cannot find one or more Images"); } else { Map<Long, String> thumbnailsJson = new HashMap<Long, String>(); for (Entry<Long, byte[]> v : thumbnails.entrySet()) { thumbnailsJson.put(v.getKey(), "data:image/jpeg;base64," + Base64.encode(v.getValue())); } message.reply(Json.encode(thumbnailsJson)); } } catch (PermissionDeniedException | CannotCreateSessionException e) { String v = "Permission denied"; log.debug(v); message.fail(403, v); } catch (Exception e) { String v = "Exception while retrieving thumbnail"; log.error(v, e); message.fail(500, v); } }