Java Code Examples for io.vertx.core.json.JsonObject#encodePrettily()
The following examples show how to use
io.vertx.core.json.JsonObject#encodePrettily() .
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: AuthModuleTest.java From okapi with Apache License 2.0 | 6 votes |
@Test public void testBadLogin(TestContext context) { Async async = context.async(); HashMap<String, String> headers = new HashMap<>(); headers.put(XOkapiHeaders.URL, URL); headers.put(XOkapiHeaders.TENANT, "my-lib"); OkapiClient cli = new OkapiClient(URL, vertx, headers); JsonObject j = new JsonObject(); j.put("tenant", "my-lib"); j.put("username", "foo"); j.put("password", "badpassword"); String body = j.encodePrettily(); cli.post("/authn/login", body, res -> { cli.close(); context.assertTrue(res.failed()); context.assertEquals(ErrorType.USER, res.getType()); async.complete(); }); }
Example 2
Source File: AuthModuleTest.java From okapi with Apache License 2.0 | 6 votes |
@Test public void testPostTenant1(TestContext context) { Async async = context.async(); HashMap<String, String> headers = new HashMap<>(); headers.put(XOkapiHeaders.URL, URL); headers.put(XOkapiHeaders.TENANT, "my-lib"); headers.put("Content-Type", "application/json"); OkapiClient cli = new OkapiClient(URL, vertx, headers); JsonObject j = new JsonObject(); j.put("tenant", "my-lib"); j.put("username", "foo"); j.put("password", "foo-password"); String body = j.encodePrettily(); cli.post("/authn/login", body, res -> { context.assertTrue(res.succeeded()); cli.setOkapiToken(cli.getRespHeaders().get(XOkapiHeaders.TOKEN)); cli.post("/_/tenant", "{}", res2 -> { context.assertTrue(res2.succeeded()); async.complete(); }); }); }
Example 3
Source File: TestSetChainParams.java From besu with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { try { final JsonObject chainParamsAsJson = new JsonObject((Map<String, Object>) requestContext.getRequest().getParams()[0]); final String chainParamsAsString = chainParamsAsJson.encodePrettily(); LOG.trace("ChainParams {}", chainParamsAsString); final String genesisFileAsString = modifyGenesisFile(chainParamsAsString); LOG.trace("Genesis {}", genesisFileAsString); final boolean result = context.resetContext( genesisFileAsString, chainParamsAsJson.getString("sealEngine", "NoProof"), Optional.empty()); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result); } catch (final Exception e) { LOG.error("Unhandled error", e); return new JsonRpcErrorResponse( requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS); } }
Example 4
Source File: MonitoringClient.java From enmasse with Apache License 2.0 | 5 votes |
public void validateQuery(String query, String expectedValue, Map<String, String> labels) throws Exception { JsonObject queryResult = client.doQuery(query); basicQueryResultValidation(query, queryResult); boolean validateResult = metricQueryResultValidation(queryResult, query, labels, resource -> expectedValue.equals(resource.getValue())); if (!validateResult) { throw new Exception("Unexpected query result " + queryResult.encodePrettily()); } }
Example 5
Source File: AuthModuleTest.java From okapi with Apache License 2.0 | 5 votes |
@Test public void testPostTenant2(TestContext context) { Async async = context.async(); HashMap<String, String> headers = new HashMap<>(); headers.put(XOkapiHeaders.URL, URL); headers.put(XOkapiHeaders.TENANT, "my-lib"); headers.put("Content-Type", "application/json"); headers.put(XOkapiHeaders.PERMISSIONS_REQUIRED, "a,b"); OkapiClient cli = new OkapiClient(URL, vertx, headers); JsonObject j = new JsonObject(); j.put("tenant", "my-lib"); j.put("username", "foo"); j.put("password", "foo-password"); String body = j.encodePrettily(); cli.post("/authn/login", body, res -> { context.assertTrue(res.succeeded()); cli.setOkapiToken(cli.getRespHeaders().get(XOkapiHeaders.TOKEN)); cli.post("/_/tenant", "{}", res2 -> { context.assertTrue(res2.failed()); async.complete(); }); }); }
Example 6
Source File: HttpRequestValidationException.java From sfs with Apache License 2.0 | 5 votes |
public HttpRequestValidationException(int statusCode, JsonObject entity) { super(entity.encodePrettily()); this.statusCode = statusCode; this.entity = entity; checkEntity(this.entity); this.entity.put("code", statusCode); }
Example 7
Source File: MonitoringClient.java From enmasse with Apache License 2.0 | 5 votes |
public void validateRangeQuery(String query, Instant start, String addressSpace, Predicate<List<String>> rangeValidator) throws Exception { JsonObject queryResult = client.doRangeQuery(query, String.valueOf(start.getEpochSecond()), String.valueOf(Instant.now().getEpochSecond())); basicQueryResultValidation(query, queryResult); boolean validateResult = metricQueryResultValidation(queryResult, addressSpace, Collections.emptyMap(), resource -> rangeValidator.test(resource.getRangeValues())); if (!validateResult) { throw new Exception("Unexpected query result " + queryResult.encodePrettily()); } }
Example 8
Source File: PersistAccount.java From sfs with Apache License 2.0 | 5 votes |
@Override public Observable<Optional<PersistentAccount>> call(final TransientAccount transientAccount) { final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch(); final JsonObject source = transientAccount.toJsonObject(); String encoded; if (LOGGER.isDebugEnabled()) { encoded = source.encodePrettily(); LOGGER.debug(format("Index Request {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), transientAccount.getId(), encoded)); } else { encoded = source.encode(); } IndexRequestBuilder request = elasticSearch.get() .prepareIndex( elasticSearch.accountIndex(), elasticSearch.defaultType(), transientAccount.getId()) .setCreate(true) .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10)) .setSource(encoded); return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout()) .map(indexResponse -> { if (indexResponse.isPresent()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s} = %s", indexResponse.get().getType(), indexResponse.get().getIndex(), transientAccount.getId(), Jsonify.toString(indexResponse.get()))); } return of(fromIndexResponse(indexResponse.get(), source)); } else { LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), transientAccount.getId(), "null")); return absent(); } }); }
Example 9
Source File: UpdateAccount.java From sfs with Apache License 2.0 | 5 votes |
@Override public Observable<Optional<PersistentAccount>> call(final PersistentAccount persistentAccount) { final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch(); final JsonObject source = persistentAccount.toJsonObject(); String encoded; if (LOGGER.isDebugEnabled()) { encoded = source.encodePrettily(); LOGGER.debug(format("Index Request {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion(), encoded)); } else { encoded = source.encode(); } IndexRequestBuilder request = elasticSearch.get() .prepareIndex( elasticSearch.accountIndex(), elasticSearch.defaultType(), persistentAccount.getId()) .setVersion(persistentAccount.getPersistentVersion()) .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10)) .setSource(encoded); return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout()) .map(indexResponse -> { if (indexResponse.isPresent()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion(), Jsonify.toString(indexResponse.get()))); } return of(fromIndexResponse(indexResponse.get(), source)); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.accountIndex(), persistentAccount.getId(), persistentAccount.getPersistentVersion(), "null")); } return absent(); } }); }
Example 10
Source File: HttpRequestValidationException.java From sfs with Apache License 2.0 | 5 votes |
public HttpRequestValidationException(Throwable cause, int statusCode, JsonObject entity) { super(entity.encodePrettily(), cause); this.statusCode = statusCode; this.entity = entity; checkEntity(this.entity); this.entity.put("code", statusCode); }
Example 11
Source File: UpdateServiceDef.java From sfs with Apache License 2.0 | 4 votes |
@Override public Observable<Optional<PersistentServiceDef>> call(final PersistentServiceDef persistentServiceDef) { final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch(); final String id = persistentServiceDef.getId(); final JsonObject source = persistentServiceDef.toJsonObject(); String encoded; if (LOGGER.isDebugEnabled()) { encoded = source.encodePrettily(); LOGGER.debug(format("Request {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, encoded)); } else { encoded = source.encode(); } IndexRequestBuilder request = elasticSearch.get() .prepareIndex( elasticSearch.serviceDefTypeIndex(), elasticSearch.defaultType(), id) .setSource(encoded) .setTTL(ttl) .setVersion(persistentServiceDef.getVersion()) .setCreate(false) .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10)); return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout()) .map(new Func1<Optional<IndexResponse>, Optional<PersistentServiceDef>>() { @Override public Optional<PersistentServiceDef> call(Optional<IndexResponse> oIndexResponse) { if (oIndexResponse.isPresent()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, Jsonify.toString(oIndexResponse.get()))); } return fromNullable(fromIndexResponse(oIndexResponse.get(), source)); } else { LOGGER.debug(format("Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.serviceDefTypeIndex(), id, "null")); return absent(); } } }); }
Example 12
Source File: ListContainerKeys.java From sfs with Apache License 2.0 | 4 votes |
@Override public Observable<PersistentContainerKey> call(PersistentContainer persistentContainer) { final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch(); final JsonObject source = persistentContainer.toJsonObject(); String encoded; if (LOGGER.isDebugEnabled()) { encoded = source.encodePrettily(); LOGGER.debug(format("Search Request {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), encoded)); } else { encoded = source.encode(); } SearchRequestBuilder request = elasticSearch.get() .prepareSearch(elasticSearch.containerKeyIndex()) .setTypes(elasticSearch.defaultType()) .setVersion(true) .setQuery(termQuery("container_id", persistentContainer.getId())) .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10)) .setSource(encoded); return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout()) .flatMap(oSearchResponse -> { if (oSearchResponse.isPresent()) { SearchResponse searchResponse = oSearchResponse.get(); if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Search Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), Jsonify.toString(searchResponse))); } return from(searchResponse.getHits()); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), persistentContainer.getId(), persistentContainer.getPersistentVersion(), "null")); } return empty(); } }) .map(searchHitFields -> fromSearchHit(persistentContainer, searchHitFields)); }
Example 13
Source File: JsObject.java From vertx-codetrans with Apache License 2.0 | 4 votes |
@CodeTranslate public void encodePrettily() throws Exception { JsonObject obj = new JsonObject().put("foo", "foo_value"); JsonTest.o = obj.encodePrettily(); }
Example 14
Source File: PersistContainer.java From sfs with Apache License 2.0 | 4 votes |
@Override public Observable<Optional<PersistentContainer>> call(final TransientContainer transientContainer) { final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch(); final JsonObject source = transientContainer.toJsonObject(); String encoded; if (LOGGER.isDebugEnabled()) { encoded = source.encodePrettily(); LOGGER.debug(format("Index Request {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), transientContainer.getId(), encoded)); } else { encoded = source.encode(); } IndexRequestBuilder request = elasticSearch.get() .prepareIndex( elasticSearch.containerIndex(), elasticSearch.defaultType(), transientContainer.getId()) .setCreate(true) .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10)) .setSource(encoded); return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout()) .map(indexResponse -> { if (indexResponse.isPresent()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), transientContainer.getId(), Jsonify.toString(indexResponse.get()))); } return of(fromIndexResponse(transientContainer.getParent(), indexResponse.get(), source)); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s} = %s", elasticSearch.defaultType(), elasticSearch.containerIndex(), transientContainer.getId(), "null")); } return absent(); } }); }
Example 15
Source File: UpdateObject.java From sfs with Apache License 2.0 | 4 votes |
@Override public Observable<Optional<PersistentObject>> call(final PersistentObject persistentObject) { final JsonObject source = persistentObject.toJsonObject(); final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch(); PersistentContainer persistentContainer = persistentObject.getParent(); String objectIndex = elasticSearch.objectIndex(persistentContainer.getName()); String encoded; if (LOGGER.isDebugEnabled()) { encoded = source.encodePrettily(); LOGGER.debug(format("Index Request {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), objectIndex, persistentObject.getId(), persistentObject.getPersistentVersion(), encoded)); } else { encoded = source.encode(); } IndexRequestBuilder request = elasticSearch.get() .prepareIndex( objectIndex, elasticSearch.defaultType(), persistentObject.getId()) .setVersion(persistentObject.getPersistentVersion()) .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10)) .setSource(encoded); return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout()) .map(indexResponse -> { if (indexResponse.isPresent()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), objectIndex, persistentObject.getId(), persistentObject.getPersistentVersion(), Jsonify.toString(indexResponse.get()))); } return of(fromIndexResponse(persistentObject.getParent(), indexResponse.get(), source)); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), objectIndex, persistentObject.getId(), persistentObject.getPersistentVersion(), "null")); } return absent(); } }); }
Example 16
Source File: UpdateContainerKey.java From sfs with Apache License 2.0 | 4 votes |
@Override public Observable<Holder2<PersistentContainerKey, Optional<PersistentContainerKey>>> call(final PersistentContainerKey persistentContainerKey) { final JsonObject source = persistentContainerKey.toJsonObject(); final Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch(); String encoded; if (LOGGER.isDebugEnabled()) { encoded = source.encodePrettily(); LOGGER.debug(format("Index Request {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainerKey.getId(), persistentContainerKey.getPersistentVersion(), encoded)); } else { encoded = source.encode(); } IndexRequestBuilder request = elasticSearch.get() .prepareIndex( elasticSearch.containerKeyIndex(), elasticSearch.defaultType(), persistentContainerKey.getId()) .setVersion(persistentContainerKey.getPersistentVersion()) .setTimeout(timeValueMillis(elasticSearch.getDefaultIndexTimeout() - 10)) .setSource(encoded); return elasticSearch.execute(vertxContext, request, elasticSearch.getDefaultIndexTimeout()) .map(indexResponse -> { Holder2<PersistentContainerKey, Optional<PersistentContainerKey>> output = new Holder2<>(); output.value0 = persistentContainerKey; if (indexResponse.isPresent()) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainerKey.getId(), persistentContainerKey.getPersistentVersion(), Jsonify.toString(indexResponse.get()))); } output.value1 = of(fromIndexResponse(persistentContainerKey.getPersistentContainer(), indexResponse.get(), source)); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Index Response {%s,%s,%s,%d} = %s", elasticSearch.defaultType(), elasticSearch.containerKeyIndex(), persistentContainerKey.getId(), persistentContainerKey.getPersistentVersion(), "null")); } output.value1 = absent(); } return output; }); }
Example 17
Source File: TenantLoadingTest.java From raml-module-builder with Apache License 2.0 | 4 votes |
public String myFilter(String content) { JsonObject obj = new JsonObject(content); String id = obj.getString("id"); obj.put("id", "X" + id); return obj.encodePrettily(); }
Example 18
Source File: OkapiClientTest.java From okapi with Apache License 2.0 | 4 votes |
@Test public void test1(TestContext context) { Async async = context.async(); final String tenant = "test-lib"; HashMap<String, String> headers = new HashMap<>(); headers.put(XOkapiHeaders.URL, URL); headers.put(XOkapiHeaders.TENANT, tenant); headers.put(XOkapiHeaders.REQUEST_ID, "919"); OkapiClient cli = new OkapiClient(URL, vertx, headers); assertEquals(URL, cli.getOkapiUrl()); cli.disableInfoLog(); cli.enableInfoLog(); JsonObject o = new JsonObject(); o.put("tenant", tenant); o.put("foo", "bar"); String s = o.encodePrettily(); byte[] encodedBytes = Base64.getEncoder().encode(s.getBytes()); String e = new String(encodedBytes); String tokenStr = "method." + e + ".trail"; OkapiToken t = new OkapiToken(tokenStr); assertEquals("test-lib", t.getTenant()); cli.setOkapiToken(tokenStr); assertEquals(tokenStr, cli.getOkapiToken()); cli.newReqId("920"); cli.get("/test1", (ExtendedAsyncResult<String> res) -> { assertTrue(res.succeeded()); assertEquals("hello test-lib", res.result()); assertEquals(res.result(), cli.getResponsebody()); MultiMap respH = cli.getRespHeaders(); assertNotNull(respH); assertEquals("text/plain", respH.get("Content-Type")); test2(cli, async); }); }
Example 19
Source File: BesuCommandTest.java From besu with Apache License 2.0 | 4 votes |
private String encodeJsonGenesis(final JsonObject jsonGenesis) { return jsonGenesis.encodePrettily(); }
Example 20
Source File: TestSetChainParams.java From besu with Apache License 2.0 | 4 votes |
private static String modifyGenesisFile(final String initialGenesis) { final JsonObject chainParamsJson = new JsonObject(initialGenesis); final JsonObject config = new JsonObject(); chainParamsJson.put("config", config); final JsonObject params = chainParamsJson.getJsonObject("params"); final JsonObject genesis = chainParamsJson.getJsonObject("genesis"); // Whether sealEngine is NoProof, Ethash, or NoReward the genesis file is the same final JsonObject ethash = new JsonObject(); config.put("ethash", ethash); maybeMoveToNumber(params, "homesteadForkBlock", config, "homesteadBlock"); maybeMoveToNumber(params, "EIP150ForkBlock", config, "eip150Block"); maybeMoveToNumber(params, "EIP158ForkBlock", config, "eip158Block"); maybeMoveToNumber(params, "byzantiumForkBlock", config, "byzantiumBlock"); maybeMoveToNumber(params, "constantinopleForkBlock", config, "constantinopleBlock"); maybeMoveToNumber(params, "constantinopleFixForkBlock", config, "constantinopleFixBlock"); maybeMoveToNumber(params, "istanbulForkBlock", config, "istanbulBlock"); maybeMoveToNumber(params, "muirGlacierForkBlock", config, "muirGlacierBlock"); maybeMoveToNumber(params, "berlinForkBlock", config, "berlinBlock"); maybeMoveToNumber(params, "chainID", config, "chainId", 1); maybeMove(genesis, "author", chainParamsJson, "coinbase"); maybeMove(genesis, "difficulty", chainParamsJson, "difficulty"); maybeMove(genesis, "extraData", chainParamsJson, "extraData"); maybeMove(genesis, "gasLimit", chainParamsJson, "gasLimit"); maybeMove(genesis, "mixHash", chainParamsJson, "mixHash"); maybeMove(genesis, "nonce", chainParamsJson, "nonce"); maybeMove(genesis, "timestamp", chainParamsJson, "timestamp"); maybeMove(chainParamsJson, "accounts", chainParamsJson, "alloc"); // strip out precompiles with zero balance final JsonObject alloc = chainParamsJson.getJsonObject("alloc"); final Iterator<String> fieldNamesIter = alloc.fieldNames().iterator(); while (fieldNamesIter.hasNext()) { final String address = fieldNamesIter.next(); final JsonObject account = alloc.getJsonObject(address); if (account.containsKey("precompiled") && !account.containsKey("balance")) { fieldNamesIter.remove(); } } return chainParamsJson.encodePrettily(); }