use of org.codehaus.jackson.JsonNode in project sling by apache.
the class OsgiConsoleClient method getBundleData.
/**
* Returns a data structure like:
*
* {
* "status" : "Bundle information: 173 bundles in total - all 173 bundles active.",
* "s" : [173,171,2,0,0],
* "data": [{
* "id":0,
* "name":"System Bundle",
* "fragment":false,
* "stateRaw":32,
* "state":"Active",
* "version":"3.0.7",
* "symbolicName":"org.apache.felix.framework",
* "category":""
* }]
* }
*/
private JsonNode getBundleData(String symbolicName) throws ClientException {
final String path = getBundlePath(symbolicName, ".json");
final String content = this.doGet(path, SC_OK).getContent();
final JsonNode root = JsonUtils.getJsonNodeFromString(content);
if (root.get(JSON_KEY_DATA) == null) {
throw new ClientException(path + " does not provide '" + JSON_KEY_DATA + "' element, JSON content=" + content);
}
Iterator<JsonNode> data = root.get(JSON_KEY_DATA).getElements();
if (!data.hasNext()) {
throw new ClientException(path + "." + JSON_KEY_DATA + " is empty, JSON content=" + content);
}
final JsonNode bundle = data.next();
if (bundle.get(JSON_KEY_STATE) == null) {
throw new ClientException(path + ".data[0].state missing, JSON content=" + content);
}
return bundle;
}
use of org.codehaus.jackson.JsonNode in project sling by apache.
the class OsgiConsoleClient method getConfiguration.
//
// OSGi configurations
//
/**
* Returns a map of all properties set for the config referenced by the PID, where the map keys
* are the property names.
*
* @param pid the pid of the configuration
* @param expectedStatus list of accepted statuses of the response
* @return the properties as a map
* @throws ClientException if the response status does not match any of the expectedStatus
*/
public Map<String, Object> getConfiguration(String pid, int... expectedStatus) throws ClientException {
// make the request
SlingHttpResponse resp = this.doPost(URL_CONFIGURATION + "/" + pid, null);
// check the returned status
HttpUtils.verifyHttpStatus(resp, HttpUtils.getExpectedStatus(SC_OK, expectedStatus));
// get the JSON node
JsonNode rootNode = JsonUtils.getJsonNodeFromString(resp.getContent());
// go through the params
Map<String, Object> props = new HashMap<String, Object>();
if (rootNode.get("properties") == null)
return props;
JsonNode properties = rootNode.get("properties");
for (Iterator<String> it = properties.getFieldNames(); it.hasNext(); ) {
String propName = it.next();
JsonNode value = properties.get(propName).get("value");
if (value != null) {
props.put(propName, value.getValueAsText());
continue;
}
value = properties.get(propName).get("values");
if (value != null) {
Iterator<JsonNode> iter = value.getElements();
List<String> list = new ArrayList<String>();
while (iter.hasNext()) {
list.add(iter.next().getValueAsText());
}
props.put(propName, list.toArray(new String[list.size()]));
}
}
return props;
}
use of org.codehaus.jackson.JsonNode in project sling by apache.
the class OsgiConsoleClient method getBundleId.
/**
* Get the id of the bundle
* @param symbolicName bundle symbolic name
* @return the id
* @throws ClientException if the id cannot be retrieved
*/
public long getBundleId(String symbolicName) throws ClientException {
final JsonNode bundle = getBundleData(symbolicName);
final JsonNode idNode = bundle.get(JSON_KEY_ID);
if (idNode == null) {
throw new ClientException("Cannot get id from bundle json");
}
return idNode.getLongValue();
}
use of org.codehaus.jackson.JsonNode in project sling by apache.
the class OsgiConsoleClient method getBundleVersion.
/**
* Get the version of the bundle
* @param symbolicName bundle symbolic name
* @return bundle version
* @throws ClientException
*/
public String getBundleVersion(String symbolicName) throws ClientException {
final JsonNode bundle = getBundleData(symbolicName);
final JsonNode versionNode = bundle.get(JSON_KEY_VERSION);
if (versionNode == null) {
throw new ClientException("Cannot get version from bundle json");
}
return versionNode.getTextValue();
}
use of org.codehaus.jackson.JsonNode in project stanbol by apache.
the class AnalyzedTextParser method parseSpan.
private void parseSpan(AnalysedText at, JsonNode node) throws IOException {
if (node.isObject()) {
ObjectNode jSpan = (ObjectNode) node;
int[] spanPos = new int[] { -1, -1 };
Collection<Entry<String, JsonNode>> jAnnotations = new ArrayList<Entry<String, JsonNode>>(4);
SpanTypeEnum spanType = parseSpanData(jSpan, spanPos, jAnnotations);
if (spanType == null || spanPos[0] < 0 || spanPos[1] < 0) {
log.warn("Illegal or missing span type, start and/or end position (ignored, json: " + jSpan);
return;
}
//now create the Span
Span span;
switch(spanType) {
case Text:
log.warn("Encounterd 'Text' span that is not the first span in the " + "'spans' array (ignored, json: " + node + ")");
return;
case TextSection:
log.warn("Encountered 'TextSection' span. This SpanTypeEnum entry " + "is currently unused. If this is no longer the case please " + "update this implementation (ignored, json: " + node + ")");
return;
case Sentence:
span = at.addSentence(spanPos[0], spanPos[1]);
break;
case Chunk:
span = at.addChunk(spanPos[0], spanPos[1]);
break;
case Token:
span = at.addToken(spanPos[0], spanPos[1]);
break;
default:
log.warn("Unsupported SpanTypeEnum '" + spanType + "'!. Please " + "update this implementation (ignored, json: " + node + ")");
return;
}
if (!jAnnotations.isEmpty()) {
parseAnnotations(span, jAnnotations);
}
} else {
log.warn("Unable to parse Span form JsonNode " + node + " (expected JSON object)!");
}
}
Aggregations