projects
/
frank.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add ability to see raw response from server when something goes wrong. (OC Transpo...
[frank.git]
/
prod
/
net
/
jaekl
/
qd
/
http
/
RequestBroker.java
diff --git
a/prod/net/jaekl/qd/http/RequestBroker.java
b/prod/net/jaekl/qd/http/RequestBroker.java
index 1a4ba4cf76e42b107c1fc8fb90bafc0b7a40e325..b11128900be8b38d084872ab9a0dc17b864001c6 100644
(file)
--- a/
prod/net/jaekl/qd/http/RequestBroker.java
+++ b/
prod/net/jaekl/qd/http/RequestBroker.java
@@
-8,10
+8,13
@@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import net.jaekl.qd.QDException;
import net.jaekl.qd.util.ExceptionUtils;
import java.util.ArrayList;
import net.jaekl.qd.QDException;
import net.jaekl.qd.util.ExceptionUtils;
+import net.jaekl.qd.util.InputStreamWrapper;
+import net.jaekl.qd.xml.ParseErrorHandler;
import net.jaekl.qd.xml.ParseHandler;
import net.jaekl.qd.xml.ParseResult;
import net.jaekl.qd.xml.ParseHandler;
import net.jaekl.qd.xml.ParseResult;
@@
-25,6
+28,7
@@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.apache.http.impl.client.HttpClientBuilder;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
@@
-118,21
+122,32
@@
public class RequestBroker
throws QDException
{
ParseResult result = null;
throws QDException
{
ParseResult result = null;
- InputStream is = null;
+ InputStreamWrapper isw = null;
+ Charset utf8 = null;
try {
try {
+ utf8 = Charset.forName(UTF_8);
if (null == rootTagName) {
result = (ParseResult) rootParserClass.newInstance();
}
else {
result = (ParseResult) rootParserClass.getDeclaredConstructor(String.class).newInstance(rootTagName);
}
if (null == rootTagName) {
result = (ParseResult) rootParserClass.newInstance();
}
else {
result = (ParseResult) rootParserClass.getDeclaredConstructor(String.class).newInstance(rootTagName);
}
- is
= doSubmit(method, passedParams
);
+ is
w = new InputStreamWrapper(doSubmit(method, passedParams)
);
XMLReader reader = XMLReaderFactory.createXMLReader();
ParseHandler ph = new ParseHandler(result);
XMLReader reader = XMLReaderFactory.createXMLReader();
ParseHandler ph = new ParseHandler(result);
+ ParseErrorHandler peh = new ParseErrorHandler();
reader.setContentHandler(ph);
reader.setContentHandler(ph);
- reader.parse(new InputSource(is));
+ reader.setErrorHandler(peh);
+ reader.parse(new InputSource(isw));
}
}
+ catch ( SAXParseException saxpe ) {
+ String response = "<n/a>";
+ if (null != isw) {
+ response = new String(isw.getHeadBytes(), utf8);
+ }
+ throw new InvalidResponseException(saxpe, m_gatewayUrl, method, response);
+ }
catch ( InstantiationException
| InvocationTargetException
| IllegalAccessException
catch ( InstantiationException
| InvocationTargetException
| IllegalAccessException
@@
-144,7
+159,7
@@
public class RequestBroker
throw new QDException(e);
}
finally {
throw new QDException(e);
}
finally {
- ExceptionUtils.tryClose(is);
+ ExceptionUtils.tryClose(is
w
);
}
return result;
}
return result;