Java Code Examples for io.vertx.core.json.JsonObject#mergeIn()
The following examples show how to use
io.vertx.core.json.JsonObject#mergeIn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuth2AuthHandlerImpl.java From vertx-web with Apache License 2.0 | 6 votes |
private String authURI(String redirectURL, String state) { final JsonObject config = new JsonObject() .put("state", state != null ? state : redirectURL); if (host != null) { config.put("redirect_uri", host + callback.getPath()); } if (scopes.size() > 0) { config.put("scopes", scopes); } if (prompt != null) { config.put("prompt", prompt); } if (extraParams != null) { config.mergeIn(extraParams); } return ((OAuth2Auth) authProvider).authorizeURL(config); }
Example 2
Source File: DeleteByQueryResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 6 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (tookMillis != null) json.put(JSON_FIELD_TOOK_MILLIS, tookMillis); if (timedOut != null) json.put(JSON_FIELD_TIMED_OUT, timedOut); if (deleted != null) json.put(JSON_FIELD_DELETED, deleted); if (batches != null) json.put(JSON_FIELD_BATCHES, batches); if (versionConflicts != null) json.put(JSON_FIELD_VERSION_CONFLICTS, versionConflicts); if (retries != null) json.put(JSON_FIELD_RETRIES, retries.toJson()); if (throttledMillis != null) json.put(JSON_FIELD_THROTTLED_MILLIS, throttledMillis); if (requestsPerSecond != null) json.put(JSON_FIELD_REQUESTS_PER_SECOND, requestsPerSecond); if (throttledUntilMillis != null) json.put(JSON_FIELD_THROTTLED_UNTIL_MILLIS, throttledUntilMillis); if (total != null) json.put(JSON_FIELD_TOTAL, total); if (failures != null) json.put(JSON_FIELD_FAILURES, failures); return json.mergeIn(super.toJson()); }
Example 3
Source File: SearchResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 6 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (took != null) json.put(JSON_FIELD_TOOK, took); if (timedOut != null) json.put(JSON_FIELD_TIMEOUT, timedOut); if (hits != null) json.put(JSON_FIELD_HITS, hits.toJson()); if (scrollId != null) json.put(JSON_FIELD_SCROLL_ID, scrollId); if (suggestions != null) { final JsonObject jsonSuggestions = new JsonObject(); suggestions.entrySet().forEach(e -> jsonSuggestions.put(e.getKey(), e.getValue().toJson())); json.put(JSON_FIELD_SUGGESTION, jsonSuggestions); } if (aggregations != null) { final JsonObject jsonAggregations = new JsonObject(); aggregations.entrySet().forEach(e -> jsonAggregations.put(e.getKey(), e.getValue())); json.put(JSON_FIELD_AGGREGATIONS, jsonAggregations); } return json.mergeIn(super.toJson()); }
Example 4
Source File: RedisDataSourceImpl.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
/** * Creates a Redis client for the service. * * @return the Redis client, configured to access the service */ @Override protected Redis retrieve() { JsonObject result = record().getMetadata().copy(); result.mergeIn(record().getLocation()); if (config != null) { result.mergeIn(config); } return Redis.createClient(vertx, new RedisOptions(result)); }
Example 5
Source File: SpringConfigServerStore.java From vertx-config with Apache License 2.0 | 5 votes |
private void parseFromStandard(JsonObject body, Handler<AsyncResult<Buffer>> handler) { JsonArray sources = body.getJsonArray("propertySources"); if (sources == null) { handler.handle(Future.failedFuture("Invalid configuration server response, property sources missing")); } else { JsonObject configuration = new JsonObject(); for (int i = sources.size() - 1; i >= 0; i--) { JsonObject source = sources.getJsonObject(i); JsonObject content = source.getJsonObject("source"); configuration = configuration.mergeIn(content, true); } handler.handle(Future.succeededFuture(Buffer.buffer(configuration.encode()))); } }
Example 6
Source File: IndexResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 5 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (index != null) json.put(JSON_FIELD_INDEX, index); if (type != null) json.put(JSON_FIELD_TYPE, type); if (id != null) json.put(JSON_FIELD_ID, id); if (version != null) json.put(JSON_FIELD_VERSION, version); if (created != null) json.put(JSON_FIELD_CREATED, created); return json.mergeIn(super.toJson()); }
Example 7
Source File: DeleteResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 5 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (index != null) json.put(JSON_FIELD_INDEX, index); if (type != null) json.put(JSON_FIELD_TYPE, type); if (id != null) json.put(JSON_FIELD_ID, id); if (version != null) json.put(JSON_FIELD_VERSION, version); if (deleted != null) json.put(JSON_FIELD_DELETED, deleted); return json.mergeIn(super.toJson()); }
Example 8
Source File: UpdateResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 5 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (index != null) json.put(JSON_FIELD_INDEX, index); if (type != null) json.put(JSON_FIELD_TYPE, type); if (id != null) json.put(JSON_FIELD_ID, id); if (version != null) json.put(JSON_FIELD_VERSION, version); if (created != null) json.put(JSON_FIELD_CREATED, created); if (result != null) json.put(JSON_FIELD_RESULT, result.toJson()); return json.mergeIn(super.toJson()); }
Example 9
Source File: BulkResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 5 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (responses != null) { final JsonArray jsonResponses = new JsonArray(); responses.forEach(e -> jsonResponses.add(e.toJson())); json.put(JSON_FIELD_RESPONSES, jsonResponses); } if (tookInMillis != null) json.put(JSON_FIELD_TOOK_IN_MILLIS, tookInMillis); return json.mergeIn(super.toJson()); }
Example 10
Source File: FieldSortOption.java From vertx-elasticsearch-service with Apache License 2.0 | 5 votes |
public JsonObject toJson() { final JsonObject baseJsonObject = super.toJson(); final JsonObject jsonObject = new JsonObject() .put(JSON_FIELD_FIELD, field); jsonObject.mergeIn(baseJsonObject); return jsonObject; }
Example 11
Source File: Oauth2Credentials.java From vertx-auth with Apache License 2.0 | 5 votes |
public JsonObject toJson() { JsonObject json = new JsonObject(); if (getCode() != null) { json.put("code", getCode()); } if (getRedirectUri() != null) { json.put("redirect_uri", getRedirectUri()); } if (extra != null) { json.mergeIn(extra); } return json; }
Example 12
Source File: MongoDataSourceImpl.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@Override public MongoClient retrieve() { JsonObject result = record().getMetadata().copy(); result.mergeIn(record().getLocation()); if (config != null) { result.mergeIn(config); } if (result.getBoolean("shared", false)) { return MongoClient.createShared(vertx, result); } else { return MongoClient.create(vertx, result); } }
Example 13
Source File: JDBCDataSourceImpl.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@Override public JDBCClient retrieve() { JsonObject result = record().getMetadata().copy(); result.mergeIn(record().getLocation()); if (config != null) { result.mergeIn(config); } if (result.getBoolean("shared", false)) { return JDBCClient.createShared(vertx, result); } else { return JDBCClient.create(vertx, result); } }
Example 14
Source File: MessageHelper.java From hono with Eclipse Public License 2.0 | 4 votes |
private static Message addProperties( final Message message, final ResourceIdentifier target, final TenantObject tenant, final JsonObject deviceDefaultProperties, final boolean useDefaults, final boolean useJmsVendorProps) { final long maxTtl = Optional.ofNullable(tenant) .map(t -> Optional.ofNullable(t.getResourceLimits()) .map(limits -> limits.getMaxTtl()) .orElse(TenantConstants.UNLIMITED_TTL)) .orElse(TenantConstants.UNLIMITED_TTL); if (useDefaults) { final JsonObject defaults = Optional.ofNullable(tenant) .map(t -> t.getDefaults().copy()) .orElseGet(() -> new JsonObject()); if (deviceDefaultProperties != null) { defaults.mergeIn(deviceDefaultProperties); } if (!defaults.isEmpty()) { addDefaults(message, target, defaults, maxTtl); } } if (Strings.isNullOrEmpty(message.getContentType())) { // set default content type if none has been specified when creating the // message nor a default content type is available message.setContentType(CONTENT_TYPE_OCTET_STREAM); } if (useJmsVendorProps) { addJmsVendorProperties(message); } // make sure that device provided TTL is capped at max TTL (if set) // AMQP spec defines TTL as milliseconds final long maxTtlMillis = maxTtl * 1000L; if (target.hasEventEndpoint() && maxTtl != TenantConstants.UNLIMITED_TTL) { if (message.getTtl() == 0) { LOG.debug("setting event's TTL to tenant's max TTL [{}ms]", maxTtlMillis); setTimeToLive(message, Duration.ofSeconds(maxTtl)); } else if (message.getTtl() > maxTtlMillis) { LOG.debug("limiting device provided TTL [{}ms] to max TTL [{}ms]", message.getTtl(), maxTtlMillis); setTimeToLive(message, Duration.ofSeconds(maxTtl)); } else { LOG.trace("keeping event's TTL [0 < {}ms <= max TTL ({}ms)]", message.getTtl(), maxTtlMillis); } } return message; }
Example 15
Source File: OAuth2API.java From vertx-auth with Apache License 2.0 | 4 votes |
/** * Sign out an end-user. * * see: */ public void logout(String accessToken, String refreshToken, Handler<AsyncResult<Void>> callback) { final JsonObject headers = new JsonObject(); headers.put("Authorization", "Bearer " + accessToken); JsonObject tmp = config.getHeaders(); if (tmp != null) { headers.mergeIn(tmp); } final JsonObject form = new JsonObject(); form.put("client_id", config.getClientID()); if (config.getClientSecretParameterName() != null && config.getClientSecret() != null) { form.put(config.getClientSecretParameterName(), config.getClientSecret()); } if (refreshToken != null) { form.put("refresh_token", refreshToken); } headers.put("Content-Type", "application/x-www-form-urlencoded"); final Buffer payload = Buffer.buffer(stringify(form)); // specify preferred accepted accessToken type headers.put("Accept", "application/json,application/x-www-form-urlencoded;q=0.9"); fetch( HttpMethod.POST, config.getLogoutPath(), headers, payload, res -> { if (res.succeeded()) { callback.handle(Future.succeededFuture()); } else { callback.handle(Future.failedFuture(res.cause())); } }); }
Example 16
Source File: OAuth2API.java From vertx-auth with Apache License 2.0 | 4 votes |
/** * Revoke an obtained access or refresh token. * * see: https://tools.ietf.org/html/rfc7009 */ public void tokenRevocation(String tokenType, String token, Handler<AsyncResult<Void>> handler) { if (token == null) { handler.handle(Future.failedFuture("Cannot revoke null token")); return; } final JsonObject headers = new JsonObject(); final boolean confidentialClient = config.getClientID() != null && config.getClientSecret() != null; if (confidentialClient) { String basic = config.getClientID() + ":" + config.getClientSecret(); headers.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(basic.getBytes())); } final JsonObject tmp = config.getHeaders(); if (tmp != null) { headers.mergeIn(tmp); } final JsonObject form = new JsonObject(); form .put("token", token) .put("token_type_hint", tokenType); headers.put("Content-Type", "application/x-www-form-urlencoded"); final Buffer payload = Buffer.buffer(stringify(form)); // specify preferred accepted accessToken type headers.put("Accept", "application/json,application/x-www-form-urlencoded;q=0.9"); fetch( HttpMethod.POST, config.getRevocationPath(), headers, payload, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); return; } final OAuth2Response reply = res.result(); if (reply.body() == null) { handler.handle(Future.failedFuture("No Body")); return; } handler.handle(Future.succeededFuture()); }); }
Example 17
Source File: AbstractSearchResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 3 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (rawResponse != null) json.put(JSON_FIELD_RAW_RESPONSE, rawResponse); return json.mergeIn(super.toJson()); }
Example 18
Source File: GetResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 3 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (result != null) json.put(JSON_FIELD_RESULT, result.toJson()); return json.mergeIn(super.toJson()); }
Example 19
Source File: MultiGetResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 3 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (!responses.isEmpty()) json.put(JSON_FIELD_RESPONSES, new JsonArray(responses.stream().map(MultiGetResponseItem::toJson).collect(Collectors.toList()))); return json.mergeIn(super.toJson()); }
Example 20
Source File: MultiSearchResponse.java From vertx-elasticsearch-service with Apache License 2.0 | 3 votes |
public JsonObject toJson() { final JsonObject json = new JsonObject(); if (!responses.isEmpty()) json.put(JSON_FIELD_RESPONSES, new JsonArray(responses.stream().map(MultiSearchResponseItem::toJson).collect(Collectors.toList()))); return json.mergeIn(super.toJson()); }