List of usage examples for io.vertx.core.json JsonArray JsonArray
public JsonArray(Buffer buf)
From source file:org.pac4j.vertx.VertxWebContext.java
License:Apache License
public VertxWebContext(final RoutingContext routingContext) { final HttpServerRequest request = routingContext.request(); this.routingContext = routingContext; this.method = request.method().toString(); this.fullUrl = request.absoluteURI(); URI uri;/*from w ww . j ava 2 s . com*/ try { uri = new URI(fullUrl); } catch (URISyntaxException e) { e.printStackTrace(); throw new InvalidParameterException( "Request to invalid URL " + fullUrl + " while constructing VertxWebContext"); } this.scheme = uri.getScheme(); this.serverName = uri.getHost(); this.serverPort = (uri.getPort() != -1) ? uri.getPort() : scheme.equals("http") ? 80 : 443; this.remoteAddress = request.remoteAddress().toString(); headers = new JsonObject(); for (String name : request.headers().names()) { headers.put(name, request.headers().get(name)); } parameters = new JsonObject(); for (String name : request.params().names()) { parameters.put(name, new JsonArray(Arrays.asList(request.params().getAll(name).toArray()))); } mapParameters = new HashMap<>(); for (String name : parameters.fieldNames()) { JsonArray params = parameters.getJsonArray(name); String[] values = new String[params.size()]; int i = 0; for (Object o : params) { values[i++] = (String) o; } mapParameters.put(name, values); } }
From source file:org.perfcake.reporting.destination.c3chart.C3ChartData.java
License:Apache License
/** * Reads the chart data from the appropriate data file. The data file is located in ${target}/data/${baseName}.js. * * @param baseName/*from w ww .j a va2 s.co m*/ * The base of the chart data files name. * @param target * The target path where the chart report is stored. The individual data files are located in ${target}/data/${baseName}.js. * @throws PerfCakeException * When there was an error reading the data. Mainly because of some I/O error. */ public C3ChartData(final String baseName, final Path target) throws PerfCakeException { this(target, new LinkedList<>()); try { List<String> lines = Utils .readLines(Paths.get(target.toString(), "data", baseName + ".js").toUri().toURL()); for (final String line : lines) { if (line.startsWith(baseName)) { String jsonArray = line.substring((baseName + ".push(").length()); jsonArray = jsonArray.substring(0, jsonArray.length() - 2); data.add(new JsonArray(jsonArray)); } } } catch (IOException e) { throw new PerfCakeException("Cannot read chart data: ", e); } }
From source file:org.perfcake.reporting.destination.c3chart.C3ChartData.java
License:Apache License
/** * Creates a new chart where with only two columns from the original chart. These columns have indexes 0 and the second is specified in the parameter. * This is used to create a subchart with the values of the X axis and one data line. * * @param keepColumnIndex/*from w ww. j a v a 2 s. co m*/ * The index of the column to be kept. * @return A new chart where with only two columns - the X axis values and the data line specified in the parameter. */ public C3ChartData filter(int keepColumnIndex) { final List<JsonArray> newData = new LinkedList<>(); data.forEach(array -> { List raw = array.getList(); newData.add(new JsonArray(Arrays.asList(raw.get(0), raw.get(keepColumnIndex)))); }); return new C3ChartData(target, newData); }
From source file:org.perfcake.reporting.destination.c3chart.C3ChartData.java
License:Apache License
/** * Mixes two charts together sorted according to the first index column. Missing data for any index values in either chart are replaced with null. * Records with only null values are skipped. The existing chart data are not changed, a new instance is created. * * @param otherData/*from w w w .j av a2s .com*/ * The other chart data to be mixed with this chart data. * @return A new chart data combining both input charts. */ @SuppressWarnings("unchecked") C3ChartData combineWith(final C3ChartData otherData) { final List<JsonArray> newData = new LinkedList<>(); int idx1 = getDataStart(); int idx2 = otherData.getDataStart(); if (idx1 == -1) { if (idx2 == -1) { return new C3ChartData(target, newData); } else { return new C3ChartData(target, new LinkedList<>(otherData.data)); } } else if (idx2 == -2) { return new C3ChartData(target, new LinkedList<>(data)); } int size1 = data.get(0).size(); List nullList1 = getNullList(size1 - 1); int size2 = otherData.data.get(0).size(); List nullList2 = getNullList(size2 - 1); while (idx1 < data.size() || idx2 < otherData.data.size()) { JsonArray a1 = idx1 < data.size() ? data.get(idx1) : null; JsonArray a2 = idx2 < otherData.data.size() ? otherData.data.get(idx2) : null; long p1 = a1 != null ? a1.getLong(0) : Long.MAX_VALUE; long p2 = a2 != null ? a2.getLong(0) : Long.MAX_VALUE; List raw = new LinkedList<>(); if (p1 == p2) { if (!isAllNull(a1) || !isAllNull(a2)) { raw.add(p1); raw.addAll(a1.getList().subList(1, size1)); raw.addAll(a2.getList().subList(1, size2)); } idx1++; idx2++; } else if (p1 < p2) { if (!isAllNull(a1)) { raw.add(p1); raw.addAll(a1.getList().subList(1, size1)); raw.addAll(nullList2); } idx1++; } else { if (!isAllNull(a2)) { raw.add(p2); raw.addAll(nullList1); raw.addAll(a2.getList().subList(1, size2)); } idx2++; } if (raw.size() > 0) { newData.add(new JsonArray(raw)); } } return new C3ChartData(target, newData); }
From source file:org.politrons.auth.impl.MongoAuthImpl.java
License:Open Source License
@Override public void insertUser(String username, String password, List<String> roles, List<String> permissions, Handler<AsyncResult<String>> resultHandler) { JsonObject principal = new JsonObject(); principal.put(getUsernameField(), username); if (roles != null) { principal.put(MongoAuth.DEFAULT_ROLE_FIELD, new JsonArray(roles)); }// w w w. j av a 2 s . c om if (permissions != null) { principal.put(MongoAuth.DEFAULT_PERMISSION_FIELD, new JsonArray(permissions)); } MongoUser user = new MongoUser(principal, this); if (getHashStrategy().getSaltStyle() == HashSaltStyle.COLUMN) { principal.put(getSaltField(), DefaultHashStrategy.generateSalt()); } String cryptPassword = getHashStrategy().computeHash(password, user); principal.put(getPasswordField(), cryptPassword); mongoClient.save(getCollectionName(), user.principal(), resultHandler); }
From source file:org.sfs.rx.BufferToJsonArray.java
License:Apache License
@Override public JsonArray call(Buffer buffer) { return new JsonArray(buffer.toString(UTF_8.toString())); }
From source file:vertx_react.verticles.EventsVerticle.java
@Override public void start(Future<Void> startFuture) throws Exception { EventBus eb = this.getVertx().eventBus(); eb.consumer("incoming", (Message<JsonObject> handler) -> { JsonObject m = handler.body();/*from ww w .j a v a 2 s. c om*/ JsonArray ja = new JsonArray(getRandomArray()); JsonObject j = new JsonObject().put("table", m.getInteger("table")).put("openSeats", ja); handler.reply(j); log.info(Json.encodePrettily(m.encodePrettily())); }); super.start(startFuture); }