You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2014/10/03 16:27:26 UTC
[10/50] [abbrv] git commit: Improve XML compatibility with
trace-level logging
Improve XML compatibility with trace-level logging
Some providers, notably Azure, include a byte-order mark in their XML
responses. ParseSax.apply buffers these responses in a String when
users enable trace-level logging to include the response in any thrown
exceptions. InputSource(InputStream) skips these byte-order marks
while InputSource(Reader) does not, yielding a SAXParseException.
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/e1a5c521
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/e1a5c521
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/e1a5c521
Branch: refs/heads/fix-jclouds-538
Commit: e1a5c521c58a611272a18e488e870215469d82a6
Parents: 3c050e0
Author: Andrew Gaul <ga...@apache.org>
Authored: Fri Sep 5 16:16:07 2014 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Fri Sep 5 17:53:50 2014 -0700
----------------------------------------------------------------------
core/src/main/java/org/jclouds/http/functions/ParseSax.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/e1a5c521/core/src/main/java/org/jclouds/http/functions/ParseSax.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/jclouds/http/functions/ParseSax.java b/core/src/main/java/org/jclouds/http/functions/ParseSax.java
index 31fb7d6..3650344 100644
--- a/core/src/main/java/org/jclouds/http/functions/ParseSax.java
+++ b/core/src/main/java/org/jclouds/http/functions/ParseSax.java
@@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
import static org.jclouds.util.Closeables2.closeQuietly;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
@@ -91,9 +92,11 @@ public class ParseSax<T> implements Function<HttpResponse, T>, InvocationContext
private T convertStreamToStringAndParse(HttpResponse response) {
String from = null;
try {
- from = new String(closeClientButKeepContentStream(response));
+ byte[] fromBytes = closeClientButKeepContentStream(response);
+ from = new String(fromBytes);
validateXml(from);
- return doParse(new InputSource(new StringReader(from)));
+ // Use InputStream to skip over byte order mark.
+ return doParse(new InputSource(new ByteArrayInputStream(fromBytes)));
} catch (Exception e) {
return addDetailsAndPropagate(response, e, from);
}