Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfbecker2010-04-02 08:15:56 +0000
committerfbecker2010-04-02 08:15:56 +0000
commitdd00fd827cb494016f2975fbed6188d9cd7b3c6c (patch)
treebd15328abb64b6338b1dc023051e3a4fa728889f /org.eclipse.mylyn.bugzilla.core
parent9baf3b6ab656241205751a4522e412a0e582b143 (diff)
downloadorg.eclipse.mylyn.tasks-dd00fd827cb494016f2975fbed6188d9cd7b3c6c.tar.gz
org.eclipse.mylyn.tasks-dd00fd827cb494016f2975fbed6188d9cd7b3c6c.tar.xz
org.eclipse.mylyn.tasks-dd00fd827cb494016f2975fbed6188d9cd7b3c6c.zip
ASSIGNED - bug 299555: Bugzilla connector should not invoke getResponseBody()
https://bugs.eclipse.org/bugs/show_bug.cgi?id=299555
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java76
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java12
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java12
3 files changed, 58 insertions, 42 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
index 945c66643..c17d569bb 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
@@ -67,17 +67,17 @@ import org.eclipse.mylyn.commons.net.AbstractWebLocation;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer;
+import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer.Token;
import org.eclipse.mylyn.commons.net.HtmlTag;
import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.commons.net.WebUtil;
-import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer.Token;
import org.eclipse.mylyn.internal.bugzilla.core.history.BugzillaTaskHistoryParser;
import org.eclipse.mylyn.internal.bugzilla.core.history.TaskHistory;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
+import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind;
import org.eclipse.mylyn.tasks.core.RepositoryStatus;
import org.eclipse.mylyn.tasks.core.TaskRepository;
-import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource;
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentPartSource;
@@ -524,7 +524,7 @@ public class BugzillaClient {
}
}
}
-
+ // because html is not a valid config content type it is save to get the response here
parseHtmlError(getResponseStream(postMethod, monitor));
} finally {
if (postMethod != null) {
@@ -661,7 +661,7 @@ public class BugzillaClient {
try {
int status = WebUtil.execute(httpClient, hostConfiguration, method, monitor);
if (status == HttpStatus.SC_OK) {
-// ignore the response
+ //copy the response
InputStream instream = method.getResponseBodyAsStream();
byte[] buffer = new byte[4096];
int len;
@@ -866,26 +866,25 @@ public class BugzillaClient {
postMethod.setRequestBody(formData);
postMethod.setDoAuthentication(true);
- try {
- int status = WebUtil.execute(httpClient, hostConfiguration, postMethod, monitor);
- if (status == HttpStatus.SC_OK) {
- return postMethod;
- } else if (status == HttpStatus.SC_MOVED_TEMPORARILY) {
- String redirectLocation;
- Header locationHeader = postMethod.getResponseHeader("location"); //$NON-NLS-1$
- if (locationHeader != null) {
- redirectLocation = locationHeader.getValue();
- throw new RedirectException(redirectLocation);
- }
-
+ int status = WebUtil.execute(httpClient, hostConfiguration, postMethod, monitor);
+ if (status == HttpStatus.SC_OK) {
+ return postMethod;
+ } else if (status == HttpStatus.SC_MOVED_TEMPORARILY) {
+ String redirectLocation;
+ Header locationHeader = postMethod.getResponseHeader("location"); //$NON-NLS-1$
+ if (locationHeader != null) {
+ redirectLocation = locationHeader.getValue();
+ postMethod.getResponseBodyNoop();
+ postMethod.releaseConnection();
+ throw new RedirectException(redirectLocation);
}
- throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
- RepositoryStatus.ERROR_IO, repositoryUrl.toString(), new IOException(
- "Communication error occurred during upload. \n\n" + HttpStatus.getStatusText(status)))); //$NON-NLS-1$
- } finally {
- postMethod.getResponseBodyNoop();
- postMethod.releaseConnection();
+
}
+ postMethod.getResponseBodyNoop();
+ postMethod.releaseConnection();
+ throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
+ RepositoryStatus.ERROR_IO, repositoryUrl.toString(), new IOException(
+ "Communication error occurred during upload. \n\n" + HttpStatus.getStatusText(status)))); //$NON-NLS-1$
}
public void postUpdateAttachment(TaskAttribute taskAttribute, String action, IProgressMonitor monitor)
@@ -1818,6 +1817,7 @@ public class BugzillaClient {
}
if (!parseable) {
+ // because html is not a valid config content type it is save to get the response here
parseHtmlError(getResponseStream(method, monitor));
break;
}
@@ -1898,10 +1898,7 @@ public class BugzillaClient {
code = WebUtil.execute(httpClient, hostConfiguration, headMethod, monitor);
} catch (IOException e) {
// ignore the response
- InputStream instream = headMethod.getResponseBodyAsStream();
- byte[] buffer = new byte[4096];
- while (instream.read(buffer) > 0) {
- }
+ consumeResponse(headMethod);
headMethod.releaseConnection();
throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
RepositoryStatus.ERROR_IO, repositoryUrl.toString(), e));
@@ -1911,10 +1908,7 @@ public class BugzillaClient {
return headMethod;
} else if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
// ignore the response
- InputStream instream = headMethod.getResponseBodyAsStream();
- byte[] buffer = new byte[4096];
- while (instream.read(buffer) > 0) {
- }
+ consumeResponse(headMethod);
// login or reauthenticate due to an expired session
headMethod.releaseConnection();
loggedIn = false;
@@ -1922,20 +1916,14 @@ public class BugzillaClient {
} else if (code == HttpURLConnection.HTTP_PROXY_AUTH) {
loggedIn = false;
// ignore the response
- InputStream instream = headMethod.getResponseBodyAsStream();
- byte[] buffer = new byte[4096];
- while (instream.read(buffer) > 0) {
- }
+ consumeResponse(headMethod);
headMethod.releaseConnection();
throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
RepositoryStatus.ERROR_REPOSITORY_LOGIN, repositoryUrl.toString(),
"Proxy authentication required")); //$NON-NLS-1$
} else {
// ignore the response
- InputStream instream = headMethod.getResponseBodyAsStream();
- byte[] buffer = new byte[4096];
- while (instream.read(buffer) > 0) {
- }
+ consumeResponse(headMethod);
headMethod.releaseConnection();
throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
RepositoryStatus.ERROR_NETWORK, "Http error: " + HttpStatus.getStatusText(code))); //$NON-NLS-1$
@@ -2096,4 +2084,16 @@ public class BugzillaClient {
RepositoryStatus.ERROR_INTERNAL, "Unable to parse response from " + repositoryUrl.toString() + ".")); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+
+ private void consumeResponse(HttpMethodBase method) {
+ InputStream instream;
+ try {
+ instream = method.getResponseBodyAsStream();
+ byte[] buffer = new byte[4096];
+ while (instream.read(buffer) > 0) {
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java
index bf6dfbcc8..648d2221b 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipGetMethod.java
@@ -12,6 +12,7 @@
package org.eclipse.mylyn.internal.bugzilla.core;
import java.io.IOException;
+import java.io.InputStream;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
@@ -63,8 +64,15 @@ public class GzipGetMethod extends GetMethod {
* @throws IOException
*/
public void getResponseBodyNoop() throws IOException {
- // result is ignored
- super.getResponseBody();
+ InputStream instream;
+ try {
+ instream = getResponseBodyAsStream();
+ byte[] buffer = new byte[4096];
+ while (instream.read(buffer) > 0) {
+ }
+ } catch (IOException e) {
+ // ignore
+ }
}
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java
index d85e002e1..84fad071f 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/GzipPostMethod.java
@@ -12,6 +12,7 @@
package org.eclipse.mylyn.internal.bugzilla.core;
import java.io.IOException;
+import java.io.InputStream;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
@@ -63,7 +64,14 @@ public class GzipPostMethod extends PostMethod {
* @throws IOException
*/
public void getResponseBodyNoop() throws IOException {
- // result is ignored
- super.getResponseBody();
+ InputStream instream;
+ try {
+ instream = getResponseBodyAsStream();
+ byte[] buffer = new byte[4096];
+ while (instream.read(buffer) > 0) {
+ }
+ } catch (IOException e) {
+ // ignore
+ }
}
}

Back to the top