X-Git-Url: http://jaekl.net/gitweb/?p=frank.git;a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fqd%2Fhttp%2FRequestBroker.java;fp=prod%2Fnet%2Fjaekl%2Fqd%2Fhttp%2FRequestBroker.java;h=b11128900be8b38d084872ab9a0dc17b864001c6;hp=d0630089eead3805ba77b73a2c6bcf64d873f637;hb=418e4d229a8b607b022cfb867bb702bec1765d13;hpb=d870b8b1ca2e633b0f2b58969cc042888d07db6e diff --git a/prod/net/jaekl/qd/http/RequestBroker.java b/prod/net/jaekl/qd/http/RequestBroker.java index d063008..b111289 100644 --- a/prod/net/jaekl/qd/http/RequestBroker.java +++ b/prod/net/jaekl/qd/http/RequestBroker.java @@ -8,10 +8,12 @@ import java.io.InputStream; 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 net.jaekl.qd.util.InputStreamWrapper; import net.jaekl.qd.xml.ParseErrorHandler; import net.jaekl.qd.xml.ParseHandler; import net.jaekl.qd.xml.ParseResult; @@ -120,25 +122,31 @@ public class RequestBroker throws QDException { ParseResult result = null; - InputStream is = null; + InputStreamWrapper isw = null; + Charset utf8 = null; try { + utf8 = Charset.forName(UTF_8); if (null == rootTagName) { result = (ParseResult) rootParserClass.newInstance(); } else { result = (ParseResult) rootParserClass.getDeclaredConstructor(String.class).newInstance(rootTagName); } - is = doSubmit(method, passedParams); + isw = new InputStreamWrapper(doSubmit(method, passedParams)); XMLReader reader = XMLReaderFactory.createXMLReader(); ParseHandler ph = new ParseHandler(result); ParseErrorHandler peh = new ParseErrorHandler(); reader.setContentHandler(ph); reader.setErrorHandler(peh); - reader.parse(new InputSource(is)); + reader.parse(new InputSource(isw)); } catch ( SAXParseException saxpe ) { - throw new InvalidResponseException(m_gatewayUrl, method, saxpe); + String response = ""; + if (null != isw) { + response = new String(isw.getHeadBytes(), utf8); + } + throw new InvalidResponseException(saxpe, m_gatewayUrl, method, response); } catch ( InstantiationException | InvocationTargetException @@ -151,7 +159,7 @@ public class RequestBroker throw new QDException(e); } finally { - ExceptionUtils.tryClose(is); + ExceptionUtils.tryClose(isw); } return result;