Java Code Examples for com.eclipsesource.json.Json#parse()

The following examples show how to use com.eclipsesource.json.Json#parse() . 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: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 6 votes vote down vote up
private JsonValue executeCommandAndGetJsonValue(String command1, String command2, String command3)
	throws WalletCallException, IOException, InterruptedException
{
	String strResponse = this.executeCommandAndGetSingleStringResponse(command1, command2, command3);

	JsonValue response = null;
	try
	{
	  	response = Json.parse(strResponse);
	} catch (ParseException pe)
	{
	  	throw new WalletCallException(strResponse + "\n" + pe.getMessage() + "\n", pe);
	}

	return response;
}
 
Example 2
Source File: R2ServerClient.java    From r2cloud with Apache License 2.0 6 votes vote down vote up
private static Long readObservationId(String con) {
	JsonValue result;
	try {
		result = Json.parse(con);
	} catch (ParseException e) {
		LOG.info("malformed json");
		return null;
	}
	if (!result.isObject()) {
		LOG.info("malformed json");
		return null;
	}
	JsonObject resultObj = result.asObject();
	String status = resultObj.getString("status", null);
	if (status == null || !status.equalsIgnoreCase("SUCCESS")) {
		LOG.info("response error: {}", resultObj);
		return null;
	}
	long id = resultObj.getLong("id", -1);
	if (id == -1) {
		return null;
	}
	return id;
}
 
Example 3
Source File: ProActiveVersionUtility.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
protected static String handleResponse(HttpResponse response) throws IOException {
    int statusCode = response.getStatusLine().getStatusCode();

    if (statusCode >= 200 && statusCode < 300) {
        HttpEntity entity = response.getEntity();

        if (entity != null) {
            JsonValue jsonValue = Json.parse(EntityUtils.toString(entity));

            if (jsonValue.isObject()) {
                JsonObject jsonObject = jsonValue.asObject();
                return jsonObject.get("rest").asString();
            }
        }
    }

    return null;
}
 
Example 4
Source File: Main.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
private static JsonValue urlGetJson(String getUrl) {
    try {
        String proxyAddress = Configuration.updateProxyAddress.get();
        URL url = new URL(getUrl);

        URLConnection uc;
        if (proxyAddress != null && !proxyAddress.isEmpty()) {
            int port = 8080;
            if (proxyAddress.contains(":")) {
                String[] parts = proxyAddress.split(":");
                port = Integer.parseInt(parts[1]);
                proxyAddress = parts[0];
            }

            uc = url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyAddress, port)));
        } else {
            uc = url.openConnection();
        }
        uc.setRequestProperty("User-Agent", ApplicationInfo.shortApplicationVerName);
        uc.connect();
        JsonValue value = Json.parse(new InputStreamReader(uc.getInputStream()));
        return value;
    } catch (IOException | NumberFormatException ex) {
        return null;
    }
}
 
Example 5
Source File: WebServer.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
private static ModelAndView processPost(IHTTPSession session, HttpContoller controller) {
	ModelAndView model;
	JsonValue request;
	try {
		request = Json.parse(WebServer.getRequestBody(session));
		if (!request.isObject()) {
			model = new BadRequest("expected object");
		} else {
			model = controller.doPost(request.asObject());
		}
	} catch (ParseException e) {
		model = new BadRequest("expected json object");
	}
	return model;
}
 
Example 6
Source File: TestUtil.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public static void assertJson(String classPathResource, JsonObject actual) {
	assertNotNull(actual);
	try (Reader is = new InputStreamReader(TestUtil.class.getClassLoader().getResourceAsStream(classPathResource), StandardCharsets.UTF_8)) {
		JsonValue value = Json.parse(is);
		assertTrue(value.isObject());
		assertJson(value.asObject(), actual);
	} catch (Exception e) {
		fail("unable to assert json: " + classPathResource + " " + e.getMessage());
	}
}
 
Example 7
Source File: RestClient.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public JsonObject updateSchedule(String id, boolean enabled) {
	HttpResponse<String> response = updateScheduleWithResponse(id, enabled);
	if (response.statusCode() != 200) {
		LOG.info("response: {}", response.body());
		throw new RuntimeException("invalid status code: " + response.statusCode());
	}
	return (JsonObject) Json.parse(response.body());
}
 
Example 8
Source File: RestClient.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public String scheduleStart(String satelliteId) {
	HttpResponse<String> response = scheduleStartResponse(satelliteId);
	if (response.statusCode() != 200) {
		LOG.info("response: {}", response.body());
		throw new RuntimeException("invalid status code: " + response.statusCode());
	}
	JsonObject json = (JsonObject) Json.parse(response.body());
	return json.getString("id", null);
}
 
Example 9
Source File: RestClient.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public JsonObject requestObservationSpectogram(String satelliteId, String observationId) {
	HttpResponse<String> response = requestObservationSpectogramResponse(satelliteId, observationId);
	if (response.statusCode() != 200) {
		LOG.info("response: {}", response.body());
		throw new RuntimeException("invalid status code: " + response.statusCode());
	}
	return (JsonObject) Json.parse(response.body());
}
 
Example 10
Source File: RestClient.java    From r2cloud with Apache License 2.0 5 votes vote down vote up
public JsonObject getObservation(String satelliteId, String observationId) {
	HttpResponse<String> response = getObservationResponse(satelliteId, observationId);
	if (response.statusCode() == 404) {
		return null;
	}
	if (response.statusCode() != 200) {
		LOG.info("response: {}", response.body());
		throw new RuntimeException("invalid status code: " + response.statusCode());
	}
	return (JsonObject) Json.parse(response.body());
}
 
Example 11
Source File: JsonRunner_Test.java    From minimal-json with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  runner = JsonRunnerFactory.findByName(name);
  json = readResource("input/test.json");
  jsonBytes = json.getBytes(JsonRunner.UTF8);
  minimalJsonModel = Json.parse(json);
}
 
Example 12
Source File: BaseTest.java    From r2cloud with Apache License 2.0 4 votes vote down vote up
public static void assertErrorInField(String field, HttpResponse<String> response) {
	JsonObject result = (JsonObject) Json.parse(response.body());
	JsonObject errors = (JsonObject) result.get("errors");
	assertNotNull(errors);
	assertNotNull(errors.get(field));
}
 
Example 13
Source File: MinimalJsonRunner.java    From minimal-json with MIT License 4 votes vote down vote up
@Override
public Object readFromString(String string) throws IOException {
  return Json.parse(string);
}
 
Example 14
Source File: MinimalJsonRunner.java    From minimal-json with MIT License 4 votes vote down vote up
@Override
public Object readFromReader(Reader reader) throws IOException {
  return Json.parse(reader);
}