List of usage examples for io.vertx.core.json JsonArray JsonArray
public JsonArray()
From source file:io.github.jdocker.Machine.java
License:Apache License
public JsonObject toJSON() { JsonObject ob = new JsonObject().put("name", getName()).put("uri", getUri()); JsonArray propsArray = new JsonArray(); for (Map.Entry<String, String> en : properties.entrySet()) { propsArray.add(new JsonObject().put(en.getKey(), en.getValue())); }//from w ww . j ava 2 s .com ob.put("properties", propsArray); return ob; }
From source file:io.github.jdocker.MachineConfig.java
License:Apache License
public JsonObject toJSON() { JsonObject o = new JsonObject().put("type", MachineConfig.class.getName()).put("name", getName()) .put("driver", getDriver()).put("uri", installURL); if (unmanagedMachine != null) { o.put("unmanagedMachine", unmanagedMachine.toJSON()); }//from ww w .j av a2 s. c om if (swarmConfig != null) { o.put("swarmConfig", swarmConfig.toJson()); } // labelsl JsonArray array = new JsonArray(); for (Map.Entry<String, String> en : labels.entrySet()) { if (en.getKey().equals(en.getValue())) { array.add(en.getValue()); } else { array.add(en.getKey() + '=' + en.getValue()); } } o.put("labels", array); array = new JsonArray(); for (String env : machineEnvironment) { array.add(env); } o.put("machineEnvironment", array); array = new JsonArray(); for (String env : insecureRegistries) { array.add(env); } o.put("insecureRegistries", array); array = new JsonArray(); for (String env : engineOptions) { array.add(env); } o.put("engineOptions", array); return o; }
From source file:io.github.jdocker.SwarmConfig.java
License:Apache License
public JsonObject toJson() { JsonObject o = new JsonObject(); o.put("dockerHost", dockerHost); o.put("swarmImage", swarmImage); o.put("swarmMaster", swarmMaster); o.put("swarmDiscoveryToken", swarmDiscoveryToken); o.put("swarmStrategy", swarmStrategy); o.put("swarmHostUri", swarmHostURI); o.put("swarmAdvertizeUri", swarmAdvertizeURI); JsonArray array = new JsonArray(); for (String env : swarmEnvironment) { array.add(env);/* w w w . j a v a 2 s. c o m*/ } o.put("swarmEnvironment", array); return o; }
From source file:io.knotx.adapter.common.http.HttpAdapterConfiguration.java
License:Apache License
public HttpAdapterConfiguration(JsonObject config) { address = config.getString("address"); services = config.getJsonArray("services").stream().map(item -> (JsonObject) item).map(item -> { ServiceMetadata metadata = new ServiceMetadata(); metadata.path = item.getString("path"); metadata.domain = item.getString("domain"); metadata.port = item.getInteger("port"); metadata.allowedRequestHeaderPatterns = item.getJsonArray("allowedRequestHeaders", new JsonArray()) .stream().map(object -> (String) object).map(new StringToPatternFunction()) .collect(Collectors.toList()); return metadata; }).collect(Collectors.toList()); clientOptions = config.getJsonObject("clientOptions", new JsonObject()); }
From source file:io.knotx.knot.action.ActionKnotConfiguration.java
License:Apache License
public ActionKnotConfiguration(JsonObject config) { this.address = config.getString("address"); this.formIdentifierName = config.getString("formIdentifierName"); this.adapterMetadataList = config.getJsonArray("adapters").stream().map(item -> (JsonObject) item) .map(item -> {//w w w.j a v a 2 s. c o m AdapterMetadata metadata = new AdapterMetadata(); metadata.name = item.getString("name"); metadata.address = item.getString("address"); metadata.params = item.getJsonObject("params", new JsonObject()).getMap(); metadata.allowedRequestHeaders = item.getJsonArray("allowedRequestHeaders", new JsonArray()) .stream().map(object -> (String) object).map(new StringToPatternFunction()) .collect(Collectors.toList()); metadata.allowedResponseHeaders = item.getJsonArray("allowedResponseHeaders", new JsonArray()) .stream().map(object -> (String) object).map(new StringToPatternFunction()) .collect(Collectors.toList()); return metadata; }).collect(Collectors.toList()); }
From source file:io.knotx.repository.impl.RepositoryConnectorProxyImpl.java
License:Apache License
public RepositoryConnectorProxyImpl(Vertx vertx, JsonObject configuration) { clientOptions = configuration.getJsonObject("clientOptions", new JsonObject()); clientDestination = configuration.getJsonObject("clientDestination"); allowedRequestHeaders = configuration.getJsonArray("allowedRequestHeaders", new JsonArray()).stream() .map(object -> (String) object).map(new StringToPatternFunction()).collect(Collectors.toList()); httpClient = createHttpClient(vertx); }
From source file:io.knotx.util.MultiMapConverter.java
License:Apache License
/** * Converts MultiMap to JsonObject<br> It expects the MultiMap key, contains List of String * objects, so the result of conversion will look like below * <br>/*from w ww .j ava 2 s . c om*/ * <pre> * { * "mapKey1": ["val1", "val2"], * "mapKey2": ["val1"] * } * </pre> * * @param multiMap - {@link MultiMap} to convert * @return - {@link JsonObject} with {@link JsonArray} under each object key */ public static JsonObject toJsonObject(MultiMap multiMap) { JsonObject json = new JsonObject(); ((io.vertx.core.MultiMap) multiMap.getDelegate()).forEach(entry -> { JsonArray values; if (json.containsKey(entry.getKey())) { values = json.getJsonArray(entry.getKey()); } else { values = new JsonArray(); json.put(entry.getKey(), values); } values.add(entry.getValue()); }); return json; }
From source file:io.nitor.api.backend.NitorBackend.java
License:Apache License
private void setupServices(JsonObject configRoot, HttpServerOptions httpServerOptions, Router router, ServiceRouterBuilder routeBuilder, HttpClient httpClient, CookieSessionHandler sessionHandler, JsonObject adAuth, boolean isOrigReqHttps) { JsonArray services = configRoot.getJsonArray("services", new JsonArray()); services.forEach(s -> {//from w ww. jav a2s. com JsonObject service = (JsonObject) s; String type = service.getString("type", "<missing>"); String logMsg = "Setting up service '" + type + "' on route '" + service.getString("route") + "'"; switch (type) { case "proxy": setupProxy(service, routeBuilder, httpServerOptions, isOrigReqHttps); break; case "static": setupStaticFiles(service, routeBuilder); break; case "s3": setupS3(service, routeBuilder); break; case "lambda": setupLambda(service, routeBuilder); break; case "graph": setupGraph(service, routeBuilder, adAuth, sessionHandler, httpClient); break; case "virtualHost": String virtualHost = service.getString("host"); logMsg += " for virtual host '" + virtualHost + "'"; setupServices(service, httpServerOptions, null, routeBuilder.virtualHostHandler(virtualHost), httpClient, sessionHandler, adAuth, isOrigReqHttps); break; case "cache": setupCache(service, routeBuilder); break; default: { RuntimeException ex = new RuntimeException("No support for service '" + type + "'"); logger.fatal("service config failure", ex); throw ex; } } logger.info(logMsg); }); if (router != null) { routeBuilder.registerHandlers(router); } }
From source file:io.nitor.api.backend.s3.S3Handler.java
License:Apache License
public S3Handler(Vertx vertx, JsonObject conf, int routeLength) { this.routeLength = routeLength; indexFile = conf.getString("indexFile", "index.html"); String staticPathConfig = conf.getString("staticPaths"); staticPaths = staticPathConfig != null ? Pattern.compile(staticPathConfig) : null; String region = resolveRegion(conf).toString(); this.s3Host = ("us-east-1".equals(region) ? "s3" : "s3-" + region) + ".amazonaws.com"; String bucket = conf.getString("bucket"); String basePath = '/' + bucket + '/' + conf.getString("path", ""); basePathComponents = PathComponent.splitPath(basePath); AwsCredentialsProvider secretsProvider = resolveCredentialsProvider(conf); signer = new AWSRequestSigner(region, s3Host, secretsProvider); JsonArray operations = conf.getJsonArray("operations", new JsonArray().add("GET")); operations.forEach(op -> allowedMethods.add(HttpMethod.valueOf(op.toString()))); http = vertx.createHttpClient(new HttpClientOptions() .setConnectTimeout((int) SECONDS.toMillis(conf.getInteger("connectTimeout", 5))) .setIdleTimeout((int) SECONDS.toSeconds(conf.getInteger("idleTimeout", 60))) .setMaxPoolSize(conf.getInteger("maxPoolSize", 100)).setPipelining(false).setMaxWaitQueueSize(100) .setUsePooledBuffers(true).setProtocolVersion(HTTP_1_1).setMaxRedirects(5) .setTryUseCompression(false)); }
From source file:io.openshift.booster.CrudApplication.java
License:Apache License
private void retrieveAll(RoutingContext ctx) { HttpServerResponse response = ctx.response().putHeader("Content-Type", "application/json"); JsonArray res = new JsonArray(); store.readAll().subscribe(res::add, err -> error(ctx, 400, err), () -> response.end(res.encodePrettily())); }