public void refreshMembers(JsonObject members) { List<String> newServerAddresses = new ArrayList<>(); members.getJsonArray("instances").forEach(m -> { JsonObject instance = (JsonObject) m; if ("UP".equals(instance.getString("status", "UP"))) { String endpoint = instance.getJsonArray("endpoints").getString(0); String scheme = instance.getBoolean("isHttps", false) ? "https" : "http"; newServerAddresses.add(scheme + SCHEMA_SEPRATOR + endpoint.substring(endpoint.indexOf(SCHEMA_SEPRATOR) + SCHEMA_SEPRATOR.length())); } }); synchronized (lock) { this.configServerAddresses.clear(); this.configServerAddresses.addAll(newServerAddresses); Collections.shuffle(this.configServerAddresses); } LOGGER.info("New config center members: {}", this.configServerAddresses); } }
/** * Gets this credentials' secret(s) as {@code Map} instances. * * @return The (potentially empty) list of secrets. */ @JsonProperty(CredentialsConstants.FIELD_SECRETS) public List<Map<String, Object>> getSecretsAsMaps() { final List<Map<String, Object>> result = new LinkedList<>(); secrets.forEach(secret -> result.add(((JsonObject) secret).getMap())); return result; }
/** * Gets this credentials' secret(s) as {@code Map} instances. * * @return The (potentially empty) list of secrets. */ @JsonProperty(CredentialsConstants.FIELD_SECRETS) public List<Map<String, Object>> getSecretsAsMaps() { final List<Map<String, Object>> result = new LinkedList<>(); secrets.forEach(secret -> result.add(((JsonObject) secret).getMap())); return result; }
@Override public JsonArraySend addAll(JsonArray array) { assertSend(); array.forEach(this::add); return this; }
private List<Match> loadMonitored(String arrayField, JsonObject json) { List<Match> list = new ArrayList<>(); JsonArray monitored = json.getJsonArray(arrayField, new JsonArray()); monitored.forEach(object -> { if (object instanceof JsonObject) list.add(new Match((JsonObject) object)); }); return list; }
private List<Match> loadLabelMatches(JsonObject json) { List<Match> list = new ArrayList<>(); JsonArray monitored = json.getJsonArray("labelMatches", new JsonArray()); monitored.forEach(object -> { if (object instanceof JsonObject) list.add(new Match((JsonObject) object)); }); return list; }
private void addCSRFHandler(Router router) { JsonArray jsonArray = config.getJsonArray("csrf.whitelist", new JsonArray()); Set<String> whiteList=new HashSet<>(); jsonArray.forEach(o-> whiteList.add(o.toString())); router.route().handler(new DominoCSRFHandler(secret,config)); }
public void refreshMembers(JsonObject members) { List<String> newServerAddresses = new ArrayList<>(); members.getJsonArray("instances").forEach(m -> { JsonObject instance = (JsonObject) m; if ("UP".equals(instance.getString("status", "UP"))) { String endpoint = instance.getJsonArray("endpoints").getString(0); String scheme = instance.getBoolean("isHttps", false) ? "https" : "http"; newServerAddresses.add(scheme + SCHEMA_SEPRATOR + endpoint.substring(endpoint.indexOf(SCHEMA_SEPRATOR) + SCHEMA_SEPRATOR.length())); } }); synchronized (lock) { this.configServerAddresses.clear(); this.configServerAddresses.addAll(newServerAddresses); Collections.shuffle(this.configServerAddresses); } LOGGER.info("New config center members: {}", this.configServerAddresses); } }
private Authorities getAuthorities(final JsonObject user) { final AuthoritiesImpl result = new AuthoritiesImpl(); user.getJsonArray(FIELD_AUTHORITIES).forEach(obj -> { final String authority = (String) obj; final Authorities roleAuthorities = roles.get(authority); if (roleAuthorities != null) { result.addAll(roleAuthorities); } }); return result; }
public static void fromJson(JsonObject json, MethodRoutingEntries obj) { if (json.getValue("items") instanceof JsonArray) { java.util.ArrayList<io.knotx.server.configuration.RoutingEntry> list = new java.util.ArrayList<>(); json.getJsonArray("items").forEach( item -> { if (item instanceof JsonObject) list.add(new io.knotx.server.configuration.RoutingEntry((JsonObject)item)); }); obj.setItems(list); } }
/** * Add default values for optional fields that are not filled in the payload. * <p> * Payload should be checked for validity first, there is no error handling inside this method anymore. * </p> * * @param checkedPayload The checked payload to add optional fields to. * @throws ClassCastException If the {@link TenantConstants#FIELD_ADAPTERS_TYPE} element is not a {@link JsonArray} * or the JsonArray contains elements that are not of type {@link JsonObject}. */ protected final void addNotPresentFieldsWithDefaultValuesForTenant(final JsonObject checkedPayload) { if (!checkedPayload.containsKey(TenantConstants.FIELD_ENABLED)) { log.trace("adding 'enabled' key to payload"); checkedPayload.put(TenantConstants.FIELD_ENABLED, Boolean.TRUE); } final JsonArray adapters = checkedPayload.getJsonArray(TenantConstants.FIELD_ADAPTERS); if (adapters != null) { adapters.forEach(elem -> addNotPresentFieldsWithDefaultValuesForAdapter((JsonObject) elem)); } }
private BridgeOptions configureBridgeOptions(JsonObject config) { BridgeOptions bridgeOptions = new BridgeOptions(); JsonObject addresses=config.getJsonObject(ADDRESSES); JsonArray outbounds=addresses.getJsonArray(OUTBOUND); JsonArray inbounds=addresses.getJsonArray(INBOUND); outbounds.forEach(o-> addOutboundPermitted(bridgeOptions, (JsonObject) o)); inbounds.forEach(i-> addInboundPermitted(bridgeOptions, (JsonObject) i)); return bridgeOptions; }
/** * Hashes clear text passwords contained in hashed-password credentials * provided by a client. * * @param credentials The credentials to hash the clear text passwords for. * @return A future containing the (updated) credentials. */ protected final Future<CredentialsObject> hashPlainPasswords(final CredentialsObject credentials) { final Future<CredentialsObject> result = Future.future(); if (CredentialsConstants.SECRETS_TYPE_HASHED_PASSWORD.equals(credentials.getType())) { getVertx().executeBlocking(blockingCodeHandler -> { log.debug("hashing password on vert.x worker thread [{}]", Thread.currentThread().getName()); credentials.getSecrets().forEach(secret -> hashPwdAndUpdateSecret((JsonObject) secret)); blockingCodeHandler.complete(credentials); }, result); } else { result.complete(credentials); } return result; }
@Override public void start() throws Exception { JsonObject config = config(); this.http = vertx.createHttpClient(new HttpClientOptions(config)); if(config.containsKey("dbnames")){ config.getJsonArray("dbnames").forEach(dbname -> registerConsumer((String) dbname)); LOG.info("InfluxDB timeseries verticle started"); } else { LOG.warn("No InfluxDB name configured"); } }
/** * Constructor from JSON * * @param json the JSON */ public TxnResponse(JsonObject json) { if (json.getValue("Results") instanceof JsonArray) { json.getJsonArray("Results").forEach(entry -> { JsonObject obj = (JsonObject) entry; if (obj.containsKey("KV")) { results.add(new KeyValue(obj.getJsonObject("KV"))); } }); } if (json.getValue("Errors") instanceof JsonArray) { json.getJsonArray("Errors").forEach(entry -> errors.add(new TxnError((JsonObject) entry))); } }
private static List handleList(JsonArray array) { array.forEach(v -> { if (v instanceof Map) { throw new UnsupportedOperationException("unsupported map, but support json"); } else if (v instanceof List) { throw new UnsupportedOperationException("unsupported list, but support jsonArray"); } CheckUtil.checkAndCopy(v, false); if (v instanceof JsonObject) { CollectionUtils.wrapToImmutable((JsonObject) v); } else if (v instanceof JsonArray) { CollectionUtils.wrapToImmutable((JsonArray) v); } }); List list = array.getList(); CollectionUtils.wrapToImmutable(array); return list; }
public static List<Object> fromJsonArray(JsonConverter converter, JsonArray arr) { List<Object> m = new ArrayList<>(); arr.forEach( value -> { if (value instanceof JsonObject) { m.add(fromJsonObject(converter, (JsonObject) value)); } else if (value instanceof JsonArray) { m.add(fromJsonArray(converter, (JsonArray) value)); } else { m.add(value); } }); return m; } }
private SockJSHandler configureSockJsHandler(VertxContext vertxContext, BridgeOptions bridgeOptions, JsonObject config) { SockJSHandler sockJSHandler = SockJSHandler.create(vertxContext.vertx()); sockJSHandler.bridge(bridgeOptions, event -> event.complete(true)); JsonArray jsonArray=config.getJsonArray(ALLOWED_ORIGINS); sockJSHandler.socketHandler(event -> jsonArray.forEach(o -> event.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, (String)o))); return sockJSHandler; }
public static void fromJson(JsonObject json, HttpFormsAdapterOptions obj) { if (json.getValue("address") instanceof String) { obj.setAddress((String)json.getValue("address")); } if (json.getValue("clientOptions") instanceof JsonObject) { obj.setClientOptions(new io.vertx.ext.web.client.WebClientOptions((JsonObject)json.getValue("clientOptions"))); } if (json.getValue("customHttpHeader") instanceof JsonObject) { obj.setCustomHttpHeader(new io.knotx.configuration.CustomHttpHeader((JsonObject)json.getValue("customHttpHeader"))); } if (json.getValue("services") instanceof JsonArray) { java.util.ArrayList<com.acme.forms.adapter.http.common.configuration.HttpFormsSettings> list = new java.util.ArrayList<>(); json.getJsonArray("services").forEach( item -> { if (item instanceof JsonObject) list.add(new com.acme.forms.adapter.http.common.configuration.HttpFormsSettings((JsonObject)item)); }); obj.setServices(list); } }
public static void fromJson(JsonObject json, KnotContext obj) { if (json.getValue("clientRequest") instanceof JsonObject) { obj.setClientRequest(new io.knotx.dataobjects.ClientRequest((JsonObject)json.getValue("clientRequest"))); } if (json.getValue("clientResponse") instanceof JsonObject) { obj.setClientResponse(new io.knotx.dataobjects.ClientResponse((JsonObject)json.getValue("clientResponse"))); } if (json.getValue("fragments") instanceof JsonArray) { java.util.ArrayList<io.knotx.dataobjects.Fragment> list = new java.util.ArrayList<>(); json.getJsonArray("fragments").forEach( item -> { if (item instanceof JsonObject) list.add(new io.knotx.dataobjects.Fragment((JsonObject)item)); }); obj.setFragments(list); } if (json.getValue("transition") instanceof String) { obj.setTransition((String)json.getValue("transition")); } }