From d8f7cb5a0725051910e9c6cbba86c04cea803223 Mon Sep 17 00:00:00 2001 From: Luc Boudreau Date: Fri, 10 Jul 2009 19:16:24 +0000 Subject: [PATCH] Fixed a race condition where data would remain in the HTTP proxy buffer upon an HTTP exception, so connections would remain in WAIT mode at the OS level for quite a while. We now attenpt to empty the input stream buffer just in case there is still something stuck in it. git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@263 c6a108a4-781c-0410-a6c6-c2d559e19af0 --- .../xmla/proxy/XmlaOlap4jHttpProxy.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java b/src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java index 4aaa063..6dd4dba 100644 --- a/src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java +++ b/src/org/olap4j/driver/xmla/proxy/XmlaOlap4jHttpProxy.java @@ -47,9 +47,10 @@ public XmlaOlap4jHttpProxy(XmlaOlap4jDriver driver) { public byte[] getResponse(URL url, String request) throws XmlaOlap4jProxyException { + URLConnection urlConnection = null; try { // Open connection to manipulate the properties - URLConnection urlConnection = url.openConnection(); + urlConnection = url.openConnection(); urlConnection.setDoOutput(true); // Set headers @@ -102,6 +103,26 @@ public byte[] getResponse(URL url, String request) // All exceptions should be trapped here. // The response will only be available here anyways. } catch (Exception e) { + // In order to prevent the JDK from keeping this connection + // in WAIT mode, we need to empty the error stream cache. + try { + final int espCode = + ((HttpURLConnection)urlConnection).getResponseCode(); + InputStream errorStream = + ((HttpURLConnection)urlConnection).getErrorStream(); + + final ByteArrayOutputStream baos = + new ByteArrayOutputStream(); + final byte[] buf = new byte[1024]; + int count; + while ((count = errorStream.read(buf)) > 0) { + baos.write(buf, 0, count); + } + errorStream.close(); + baos.close(); + } catch(IOException ex) { + // Well, we tried. No point notifying the user here. + } throw new XmlaOlap4jProxyException( "This proxy encountered an exception while processing the " + "query.",