use of javax.json.JsonReader in project scylla-jmx by scylladb.
the class APIClient method getMapStringLongValue.
public Map<String, Long> getMapStringLongValue(String string, MultivaluedMap<String, String> queryParams) {
Map<String, Long> res = new HashMap<String, Long>();
JsonReader reader = getReader(string, queryParams);
JsonArray arr = reader.readArray();
JsonObject obj = null;
for (int i = 0; i < arr.size(); i++) {
obj = arr.getJsonObject(i);
res.put(obj.getString("key"), obj.getJsonNumber("value").longValue());
}
return res;
}
use of javax.json.JsonReader in project scylla-jmx by scylladb.
the class APIClient method getJsonArray.
public JsonArray getJsonArray(String string, MultivaluedMap<String, String> queryParams) {
if (string.equals("")) {
return null;
}
JsonReader reader = getReader(string, queryParams);
JsonArray res = reader.readArray();
reader.close();
return res;
}
use of javax.json.JsonReader in project knime-core by knime.
the class BugAP7806_WorkflowSaveHooks method testOpenAPIGeneration.
/**
* Checks if the OpenAPI definition for the input parameters is generated correctly.
*
* @throws Exception if an error occurs
*/
@Test
public void testOpenAPIGeneration() throws Exception {
getManager().setDirty();
getManager().save(m_workflowDir, new ExecutionMonitor(), true);
Path openApiFragmentFile = m_workflowDir.toPath().resolve(WorkflowSaveHook.ARTIFACTS_FOLDER_NAME).resolve(OpenAPIDefinitionGenerator.INPUT_PARAMETERS_FILE);
String actualInputParameters;
try (JsonReader reader = Json.createReader(Files.newInputStream(openApiFragmentFile))) {
JsonObject o = reader.readObject();
try (StringWriter sw = new StringWriter();
JsonWriter writer = Json.createWriter(sw)) {
writer.write(o);
actualInputParameters = sw.toString();
}
}
String expectedInputParameters;
try (JsonReader reader = Json.createReader(Files.newInputStream(m_workflowDir.toPath().resolve("openapi-input-parameters-reference.json")))) {
JsonObject o = reader.readObject();
try (StringWriter sw = new StringWriter();
JsonWriter writer = Json.createWriter(sw)) {
writer.write(o);
expectedInputParameters = sw.toString();
}
}
assertThat("Unexpected input parameters definition written", actualInputParameters, is(expectedInputParameters));
}
use of javax.json.JsonReader in project Payara by payara.
the class JerseyRestResponse method getResponse.
/**
* <p> This method abstracts the physical response to return a consistent
* data structure.</p>
*/
@Override
public Map<String, Object> getResponse() {
// Prepare the result object
Map<String, Object> result = new HashMap<String, Object>(5);
// Add the Response Code
result.put("responseCode", getResponseCode());
// Add the Response Body
// FIXME: Do not put responseBody into the Map... too big, not needed
result.put("responseBody", getResponseBody());
String contentType = response.getHeaderString("Content-type");
if (contentType != null) {
String responseBody = getResponseBody();
contentType = contentType.toLowerCase(GuiUtil.guiLocale);
if (contentType.startsWith("application/xml")) {
InputStream input = null;
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
input = new ByteArrayInputStream(responseBody.trim().getBytes("UTF-8"));
XMLStreamReader parser = inputFactory.createXMLStreamReader(input);
while (parser.hasNext()) {
int event = parser.next();
switch(event) {
case XMLStreamConstants.START_ELEMENT:
{
if ("map".equals(parser.getLocalName())) {
result.put("data", processXmlMap(parser));
}
break;
}
default:
break;
}
}
} catch (Exception ex) {
Logger.getLogger(RestResponse.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
} finally {
try {
if (input != null) {
input.close();
}
} catch (IOException ex) {
Logger.getLogger(RestResponse.class.getName()).log(Level.SEVERE, null, ex);
}
}
// // If XML...
// Document document = MiscUtil.getDocument(getResponseBody());
// Element root = document.getDocumentElement();
// if ("action-report".equalsIgnoreCase(root.getNodeName())) {
// // Default XML document type...
// // Add the Command Description
// result.put("description", root.getAttribute("description"));
// result.put("exit-code", root.getAttribute("exit-code"));
//
// // Add the messages
// List<Map<String, Object>> messages = new ArrayList<Map<String, Object>>(2);
// result.put("messages", messages);
//
// // Iterate over each node looking for message-part
// NodeList nl = root.getChildNodes();
// int len = nl.getLength();
// Node child;
// for (int idx = 0; idx < len; idx++) {
// child = nl.item(idx);
// if ((child.getNodeType() == Node.ELEMENT_NODE) && (child.getNodeName().equals("message-part"))) {
// messages.add(processMessagePart(child));
// }
// }
// } else {
// // Generate a generic Java structure from the XML
// result.put("data", getJavaFromXML(root));
// }
} else if (contentType.startsWith("application/json")) {
// Decode JSON
JsonReader reader = Json.createReader(new StringReader(responseBody));
JsonObject object = reader.readObject();
result.put("data", JsonUtil.jsonObjectToMap(object));
} else {
// Unsupported Response Format!
System.out.println("Unsupported Response Format: '" + contentType + "'!");
}
}
// Return the populated result data structure
return result;
}
use of javax.json.JsonReader in project Payara by payara.
the class RequestTraceTest method testJSONParse.
@Test
public void testJSONParse() {
RequestTraceSpan re = new RequestTraceSpan(EventType.TRACE_START, "Start");
trace.addEvent(re);
for (int i = 0; i < 1000; i++) {
re = new RequestTraceSpan("Event" + i);
trace.addEvent(re);
}
trace.endTrace();
String jsonString = trace.toString();
JsonReader jsonReader = Json.createReader(new StringReader(jsonString));
jsonReader.readObject();
}
Aggregations