You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:58:44 UTC
[sling-org-apache-sling-resource-inventory] 02/04: SLING-4625 : No
resource inventory if mbean attribute value is a double
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.resource.inventory-1.0.4
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resource-inventory.git
commit 3529b237a8b031981d49beeda44beaa6c9ca7124
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Apr 15 10:09:31 2015 +0000
SLING-4625 : No resource inventory if mbean attribute value is a double
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/resource-inventory@1673706 13f79535-47bb-0310-9956-ffa450edef68
---
.../resource/inventory/impl/JsonObjectCreator.java | 50 ++++++++++++++--------
.../impl/ResourceInventoryPrinterFactory.java | 5 ++-
2 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java b/src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java
index 2516edc..34d5d23 100644
--- a/src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java
+++ b/src/main/java/org/apache/sling/resource/inventory/impl/JsonObjectCreator.java
@@ -32,6 +32,7 @@ import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
+import org.slf4j.LoggerFactory;
/**
* Creates a JSONObject from a resource
@@ -128,8 +129,6 @@ public abstract class JsonObjectCreator {
return value;
} else if ( value instanceof Integer ) {
return value;
- } else if ( value instanceof Double ) {
- return value;
} else if ( value != null ) {
return value.toString();
} else {
@@ -149,8 +148,7 @@ public abstract class JsonObjectCreator {
private static void createProperty(final JSONObject obj,
final ValueMap valueMap,
final String key,
- final Object value)
- throws JSONException {
+ final Object value) {
Object[] values = null;
if (value.getClass().isArray()) {
if (value instanceof long[]) {
@@ -176,7 +174,11 @@ public abstract class JsonObjectCreator {
}
// write out empty array
if ( values.length == 0 ) {
- obj.put(key, new JSONArray());
+ try {
+ obj.put(key, new JSONArray());
+ } catch ( final JSONException ignore ) {
+ // we ignore this
+ }
return;
}
}
@@ -188,26 +190,36 @@ public abstract class JsonObjectCreator {
// their name
// (colon is not allowed as a JCR property name)
// in the name, and the value should be the size of the binary data
- if (values == null) {
- obj.put(":" + key, getLength(valueMap, -1, key, (InputStream)value));
- } else {
- final JSONArray result = new JSONArray();
- for (int i = 0; i < values.length; i++) {
- result.put(getLength(valueMap, i, key, (InputStream)values[i]));
+ try {
+ if (values == null) {
+ obj.put(":" + key, getLength(valueMap, -1, key, (InputStream)value));
+ } else {
+ final JSONArray result = new JSONArray();
+ for (int i = 0; i < values.length; i++) {
+ result.put(getLength(valueMap, i, key, (InputStream)values[i]));
+ }
+ obj.put(":" + key, result);
}
- obj.put(":" + key, result);
+ } catch ( final JSONException ignore ) {
+ // we ignore this
+ LoggerFactory.getLogger(JsonObjectCreator.class).warn("Unable to create JSON value", ignore);
}
return;
}
- if (!value.getClass().isArray()) {
- obj.put(key, getValue(value));
- } else {
- final JSONArray result = new JSONArray();
- for (Object v : values) {
- result.put(getValue(v));
+ try {
+ if (!value.getClass().isArray()) {
+ obj.put(key, getValue(value));
+ } else {
+ final JSONArray result = new JSONArray();
+ for (Object v : values) {
+ result.put(getValue(v));
+ }
+ obj.put(key, result);
}
- obj.put(key, result);
+ } catch ( final JSONException ignore ) {
+ // we ignore this
+ LoggerFactory.getLogger(JsonObjectCreator.class).warn("Unable to create JSON value", ignore);
}
}
diff --git a/src/main/java/org/apache/sling/resource/inventory/impl/ResourceInventoryPrinterFactory.java b/src/main/java/org/apache/sling/resource/inventory/impl/ResourceInventoryPrinterFactory.java
index 4591274..77148ad 100644
--- a/src/main/java/org/apache/sling/resource/inventory/impl/ResourceInventoryPrinterFactory.java
+++ b/src/main/java/org/apache/sling/resource/inventory/impl/ResourceInventoryPrinterFactory.java
@@ -35,6 +35,7 @@ import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.commons.json.JSONException;
+import org.slf4j.LoggerFactory;
@Component(configurationFactory=true, policy=ConfigurationPolicy.REQUIRE, metatype=true)
@Service(value=InventoryPrinter.class)
@@ -78,8 +79,8 @@ public class ResourceInventoryPrinterFactory implements InventoryPrinter {
}
} catch (final LoginException e) {
// ignore
- } catch (JSONException e) {
- // ignore
+ } catch (final JSONException ignore) {
+ LoggerFactory.getLogger(this.getClass()).warn("Unable to create resource json", ignore);
} finally {
if ( resolver != null ) {
resolver.close();
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.