Java Code Examples for io.vertx.core.json.JsonObject#getMap()

The following examples show how to use io.vertx.core.json.JsonObject#getMap() . 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: VxApiRequestBodyHandler.java    From VX-API-Gateway with MIT License 6 votes vote down vote up
/**
 * 获得body的参数
 * 
 * @return 返回一个不为null的MultiMap
 */
public MultiMap getBody() {
	if (contentType.isApplicationJson()) {
		try {
			JsonObject object = new JsonObject(bodyBuffer);
			if (object.getMap() != null) {
				object.getMap().forEach((k, v) -> {
					body.add(k, v.toString());
				});
			}
		} catch (Exception e) {
		}
	} else if (contentType.isUrlencoded()) {
		MultiMap decoderUriParams = HttpUtils.decoderUriParams(bodyBuffer.toString(), contentType.getCharset());
		if (decoderUriParams != null) {
			body.addAll(decoderUriParams);
		}
	}
	return body;
}
 
Example 2
Source File: TestSetChainParamsTest.java    From besu with Apache License 2.0 4 votes vote down vote up
@Test
public void testValidateGenesisImport() throws IOException {
  final String chainParamsJsonString =
      Resources.toString(
          TestSetChainParamsTest.class.getResource("multimpleBalanceInstructionChainParams.json"),
          Charsets.UTF_8);
  final JsonObject chainParamsJson = new JsonObject(chainParamsJsonString);

  final JsonRpcRequestContext request =
      new JsonRpcRequestContext(
          new JsonRpcRequest(
              "2.0", TestSetChainParams.METHOD_NAME, new Object[] {chainParamsJson.getMap()}));

  assertThat(test_setChainParams.response(request))
      .isEqualTo(new JsonRpcSuccessResponse(null, true));

  final BlockHeader blockHeader = context.getBlockHeader(0);

  assertThat(blockHeader.getLogsBloom().toString())
      .isEqualTo(
          "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
  assertThat(blockHeader.getCoinbase().toString())
      .isEqualTo("0x8888f1f195afa192cfee860698584c030f4c9db1");
  assertThat(blockHeader.getDifficulty()).isEqualTo(UInt256.fromHexString("0x20000"));
  assertThat(blockHeader.getExtraData().toHexString()).isEqualTo("0x42");
  assertThat(blockHeader.getGasLimit()).isEqualTo(3141592);
  assertThat(blockHeader.getGasUsed()).isEqualTo(0);
  assertThat(blockHeader.getMixHash().toString())
      .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
  assertThat(blockHeader.getNonce()).isEqualTo(0x0102030405060708L);
  assertThat(blockHeader.getNumber()).isEqualTo(0);
  assertThat(blockHeader.getParentHash().toString())
      .isEqualTo("0x0000000000000000000000000000000000000000000000000000000000000000");
  assertThat(blockHeader.getReceiptsRoot().toString())
      .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
  assertThat(blockHeader.getStateRoot().toString())
      .isEqualTo("0xf403922bfd555a9223f68fc755564004e20d78bb42aae647e867e3b23c48beba");
  assertThat(blockHeader.getTimestamp()).isEqualTo(0x54c98c81);
  assertThat(blockHeader.getTransactionsRoot().toString())
      .isEqualTo("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
  assertThat(blockHeader.getOmmersHash().toString())
      .isEqualTo("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347");
}
 
Example 3
Source File: Utils.java    From vertx-rabbitmq-client with Apache License 2.0 4 votes vote down vote up
public static Map<String, Object> asMap(JsonObject json) {
  if (json == null) return null;

  return json.getMap();
}
 
Example 4
Source File: GraphQLQuery.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
public GraphQLQuery(JsonObject value) {
  query = value.getString("query");
  operationName = value.getString("operationName");
  JsonObject vars = value.getJsonObject("variables");
  this.variables = vars != null ? vars.getMap() : null;
}
 
Example 5
Source File: RemoteReceiverModule.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
private void receiveData(RoutingContext rc) {
    if (!enabled.get()) {
        rc.response().setStatusCode(HttpResponseStatus.FORBIDDEN.code())
                .end("UI server remote listening is currently disabled. Use UIServer.getInstance().enableRemoteListener()");
        return;
    }

    if (statsStorage == null) {
        rc.response().setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code())
                .end("UI Server remote listener: no StatsStorage instance is set/available to store results");
        return;
    }

    JsonObject jo = rc.getBodyAsJson();
    Map<String,Object> map = jo.getMap();
    String type = (String) map.get("type");
    String dataClass = (String) map.get("class");
    String data = (String) map.get("data");

    if (type == null || dataClass == null || data == null) {
        log.warn("Received incorrectly formatted data from remote listener (has type = " + (type != null)
                        + ", has data class = " + (dataClass != null) + ", has data = " + (data != null) + ")");
        rc.response().setStatusCode(HttpResponseStatus.BAD_REQUEST.code())
                .end("Received incorrectly formatted data");
        return;
    }

    switch (type.toLowerCase()) {
        case "metadata":
            StorageMetaData meta = getMetaData(dataClass, data);
            if (meta != null) {
                statsStorage.putStorageMetaData(meta);
            }
            break;
        case "staticinfo":
            Persistable staticInfo = getPersistable(dataClass, data);
            if (staticInfo != null) {
                statsStorage.putStaticInfo(staticInfo);
            }
            break;
        case "update":
            Persistable update = getPersistable(dataClass, data);
            if (update != null) {
                statsStorage.putUpdate(update);
            }
            break;
        default:

    }

    rc.response().end();
}
 
Example 6
Source File: Fortune.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Fortune(JsonObject doc) {
  super(doc == null ? Collections.emptyMap() : doc.getMap());
}