Improved logging for CachedResource (especially when dealing with malformed XML or JSON responses)
This commit is contained in:
parent
00e8c4bc60
commit
7bfb19aa35
|
@ -18,6 +18,7 @@ import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
|
@ -96,8 +97,8 @@ public class CachedResource<K, R> implements Resource<R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return parse.transform(data);
|
return parse.transform(data);
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
debug.warning(format("Fetch failed: %s [%s]", e, url));
|
debug.severe(format("Fetch failed: %s [%s]", e, url));
|
||||||
|
|
||||||
// use previously cached data if possible
|
// use previously cached data if possible
|
||||||
if (element == null || element.getObjectValue() == null) {
|
if (element == null || element.getObjectValue() == null) {
|
||||||
|
@ -126,7 +127,7 @@ public class CachedResource<K, R> implements Resource<R> {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug.fine(format("Fetch failed: Try again in %d seconds (%d more) => %s", retryWaitTime.getSeconds(), retryCount, e));
|
debug.warning(format("Fetch failed: Try again in %d seconds (%d more) => %s", retryWaitTime.getSeconds(), retryCount, e));
|
||||||
Thread.sleep(retryWaitTime.toMillis());
|
Thread.sleep(retryWaitTime.toMillis());
|
||||||
return retry(callable, retryCount - 1, retryWaitTime.multipliedBy(2));
|
return retry(callable, retryCount - 1, retryWaitTime.multipliedBy(2));
|
||||||
}
|
}
|
||||||
|
@ -164,16 +165,26 @@ public class CachedResource<K, R> implements Resource<R> {
|
||||||
public static <T> Transform<T, String> validateXml(Transform<T, String> parse) {
|
public static <T> Transform<T, String> validateXml(Transform<T, String> parse) {
|
||||||
return object -> {
|
return object -> {
|
||||||
String xml = parse.transform(object);
|
String xml = parse.transform(object);
|
||||||
WebRequest.validateXml(xml);
|
try {
|
||||||
return xml;
|
WebRequest.validateXml(xml);
|
||||||
|
return xml;
|
||||||
|
} catch (Exception e) {
|
||||||
|
debug.log(Level.WARNING, xml, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Transform<T, String> validateJson(Transform<T, String> parse) {
|
public static <T> Transform<T, String> validateJson(Transform<T, String> parse) {
|
||||||
return object -> {
|
return object -> {
|
||||||
String json = parse.transform(object);
|
String json = parse.transform(object);
|
||||||
JsonUtilities.readJson(json);
|
try {
|
||||||
return json;
|
JsonUtilities.readJson(json);
|
||||||
|
return json;
|
||||||
|
} catch (Exception e) {
|
||||||
|
debug.log(Level.WARNING, json, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue