use of javax.json.JsonReader in project mysql_perf_analyzer by yahoo.
the class UserDefinedMetrics method createFromJson.
public static UserDefinedMetrics createFromJson(java.io.InputStream in) {
JsonReader jsonReader = null;
UserDefinedMetrics udm = null;
try {
jsonReader = javax.json.Json.createReader(in);
JsonObject jsonObject = jsonReader.readObject();
jsonReader.close();
udm = new UserDefinedMetrics(jsonObject.getString("groupName"));
udm.setAuto("y".equalsIgnoreCase(jsonObject.getString("auto", null)));
udm.setStoreInCommonTable("y".equalsIgnoreCase(jsonObject.getString("storeInCommonTable", null)));
udm.setSource(jsonObject.getString("source"));
udm.setUdmType(jsonObject.getString("type"));
udm.setNameCol(jsonObject.getString("nameColumn", null));
udm.setValueCol(jsonObject.getString("valueColumn", null));
udm.setKeyCol(jsonObject.getString("keyColumn", null));
udm.setSql(jsonObject.getString("sql", null));
JsonArray metrics = jsonObject.getJsonArray("metrics");
if (metrics != null) {
int mlen = metrics.size();
for (int i = 0; i < mlen; i++) {
JsonObject mobj = metrics.getJsonObject(i);
udm.addmetric(mobj.getString("name"), mobj.getString("sourceName"), "y".equalsIgnoreCase(mobj.getString("inc")), Metric.strToMetricDataType(mobj.getString("dataType")));
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, "Error to parse UDM", ex);
//TODO
}
return udm;
}
use of javax.json.JsonReader in project sling by apache.
the class TeleporterHttpClient method verifyCorrectBundleState.
void verifyCorrectBundleState(String bundleSymbolicName, int timeoutInSeconds) throws IOException {
final String url = baseUrl + "/system/console/bundles/" + bundleSymbolicName + ".json";
final long end = System.currentTimeMillis() + timeoutInSeconds * 1000;
final ExponentialBackoffDelay d = new ExponentialBackoffDelay(50, 250);
while (System.currentTimeMillis() < end) {
String jsonBody = waitForStatus(url, 200, timeoutInSeconds * 1000);
// deserialize json (https://issues.apache.org/jira/browse/SLING-6536)
try (JsonReader jsonReader = Json.createReader(new StringReader(jsonBody))) {
// extract state
JsonArray jsonArray = jsonReader.readObject().getJsonArray("data");
if (jsonArray == null) {
throw new JsonException("Could not find 'data' array");
}
JsonObject bundleObject = jsonArray.getJsonObject(0);
String state = bundleObject.getString("state");
if ("Active".equals(state)) {
return;
}
// otherwise evaluate the import section
JsonArray propsArray = bundleObject.getJsonArray("props");
if (propsArray == null) {
throw new JsonException("Could not find 'props' object");
}
// iterate through all of them until key="Imported Packages" is found
for (JsonValue propValue : propsArray) {
if (propValue.getValueType().equals(ValueType.OBJECT)) {
JsonObject propObject = (JsonObject) propValue;
if ("Imported Packages".equals(propObject.getString("key"))) {
JsonArray importedPackagesArray = propObject.getJsonArray("value");
String reason = null;
for (JsonValue importedPackageValue : importedPackagesArray) {
if (importedPackageValue.getValueType().equals(ValueType.STRING)) {
String importedPackage = ((JsonString) importedPackageValue).getString();
if (importedPackage.startsWith("ERROR:")) {
reason = importedPackage;
}
}
}
// only if ERROR is found there is no more need to wait for the bundle to become active, otherwise it might just be started in the background
if (reason != null) {
throw new IllegalStateException("The test bundle '" + bundleSymbolicName + "' is in state '" + state + "'. This is due to unresolved import-packages: " + reason);
}
}
}
}
} catch (JsonException | IndexOutOfBoundsException e) {
throw new IllegalArgumentException("Test bundle '" + bundleSymbolicName + "' not correctly installed. Could not parse JSON response though to expose further information: " + jsonBody, e);
}
d.waitNextDelay();
}
throw new IOException("Bundle '" + bundleSymbolicName + "' was not started after " + timeoutInSeconds + " seconds. The check at " + url + " was not successfull. Probably some dependent bundle was not started.");
}
use of javax.json.JsonReader in project opentheso by miledrousset.
the class SelectedTerme method majNoticeBdd.
private void majNoticeBdd() {
// ResourceBundle bundlePref = getBundlePref();
// st.getTaskResultSet().getFragmentCount();
nbNotices = 0;
urlNotice = user.getNodePreference().getUrlBdd();
if (user.getNodePreference().isBddUseId()) {
urlNotice = urlNotice.replace("##value##", idC);
} else {
urlNotice = urlNotice.replace("##value##", nom);
}
// récupération du total des notices
String urlCounterBdd = user.getNodePreference().getUrlCounterBdd();
urlCounterBdd = urlCounterBdd.replace("##conceptId##", idC);
// urlCounterBdd = "http://healthandco.test.o2sources.com/concept/40/total";
// exemple des données récupérées
// "{\"content\":[{\"nb_notices\":\"s7\"}],\"debug\":\"\",\"error\":0}\" ";
// {"content":[{"nb_notices":"7"}],"debug":"","error":0}
URL url;
try {
url = new URL(urlCounterBdd);
InputStream is = url.openStream();
JsonReader reader = Json.createReader(is);
JsonObject totalNotices = reader.readObject();
reader.close();
JsonArray values = totalNotices.getJsonArray("content");
String name;
for (int i = 0; i < values.size(); i++) {
JsonObject item = values.getJsonObject(i);
try {
name = item.getString("nb_notices");
if (name != null) {
if (!name.isEmpty())
nbNotices = Integer.parseInt(name);
}
} catch (JsonException e) {
System.out.println(e.toString());
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
} catch (MalformedURLException ex) {
Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
}
// try {
// urlNotice = URLEncoder.encode(urlNotice);
// } catch (UnsupportedEncodingException ex) {
// Logger.getLogger(SelectedTerme.class.getName()).log(Level.SEVERE, null, ex);
// }
}
use of javax.json.JsonReader in project opentheso by miledrousset.
the class ReadJson method getJsonObject.
/**
* permet de lire un fichier Json d'après une inputStream
* @param is
* @return
*/
public JsonObject getJsonObject(InputStream is) {
JsonReader reader = Json.createReader(is);
JsonObject jsonObject = reader.readObject();
reader.close();
return jsonObject;
}
use of javax.json.JsonReader in project opentheso by miledrousset.
the class ReadJson method getJsonObject.
/**
* Permet de lire un texte en Json
* @param jsonText
* @return
*/
public JsonObject getJsonObject(String jsonText) {
// String total = " {\"content\":[{\"nb_notices\":\"7\"}],\"debug\":\"\",\"error\":0}\" ";
JsonReader reader = Json.createReader(new StringReader(jsonText));
JsonObject jsonObject = reader.readObject();
reader.close();
return jsonObject;
}
Aggregations