diff options
author | relves | 2006-11-24 22:08:31 +0000 |
---|---|---|
committer | relves | 2006-11-24 22:08:31 +0000 |
commit | 3add3a01d375366363f27bc96482b65e3d5d6081 (patch) | |
tree | 38ff6179c87f5fdcff9742f27b9debce0da63d59 /org.eclipse.mylyn.bugzilla.core | |
parent | 3a3bc6185c5488b6f9b18bf8c355878d2d8b72e9 (diff) | |
download | org.eclipse.mylyn.tasks-3add3a01d375366363f27bc96482b65e3d5d6081.tar.gz org.eclipse.mylyn.tasks-3add3a01d375366363f27bc96482b65e3d5d6081.tar.xz org.eclipse.mylyn.tasks-3add3a01d375366363f27bc96482b65e3d5d6081.zip |
NEW - bug 165705: repository operations time out too quickly
https://bugs.eclipse.org/bugs/show_bug.cgi?id=165705
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
2 files changed, 66 insertions, 58 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 c6de653a4..6489578eb 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 @@ -13,7 +13,6 @@ package org.eclipse.mylar.internal.bugzilla.core; import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -67,6 +66,8 @@ import org.eclipse.mylar.tasks.core.TaskRepository; */ public class BugzillaClient { + private static final String LOGIN_REQUIRED = "goaheadandlogin=1"; + private static final int MAX_RETRY = 2; private static final int CONNECT_TIMEOUT = 60000; @@ -131,8 +132,15 @@ public class BugzillaClient { } public void validate() throws IOException, LoginException, BugzillaException { - logout(); - getConnect(repositoryUrl + "/"); + GetMethod method = null; + try { + logout(); + method = getConnect(repositoryUrl + "/"); + } finally { + if (method != null) { + method.releaseConnection(); + } + } } protected boolean hasAuthenticationCredentials() { @@ -154,12 +162,12 @@ public class BugzillaClient { } GetMethod getMethod = new GetMethod(WebClientUtil.getRequestPath(serverURL)); - //getMethod.getParams().setSoTimeout(CONNECT_TIMEOUT); + // getMethod.getParams().setSoTimeout(CONNECT_TIMEOUT); httpClient.getHttpConnectionManager().getParams().setSoTimeout(CONNECT_TIMEOUT); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT); getMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + characterEncoding); - + // WARNING! Setting browser compatability breaks Bugzilla // authentication // method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); @@ -178,7 +186,7 @@ public class BugzillaClient { httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(currentTimeout * 2); return true; } - if (exception instanceof SocketTimeoutException) { + if (exception instanceof SocketTimeoutException) { httpClient.getHttpConnectionManager().getParams().setSoTimeout(currentTimeout * 2); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(currentTimeout * 2); return true; @@ -245,7 +253,7 @@ public class BugzillaClient { if (tag.getTagType() == HtmlTag.Type.A) { if (tag.hasAttribute("href")) { String id = tag.getAttribute("href"); - if (id != null && id.toLowerCase().contains("goaheadandlogin=1")) { + if (id != null && id.toLowerCase().contains(LOGIN_REQUIRED)) { authenticated = false; return; } @@ -261,8 +269,9 @@ public class BugzillaClient { } catch (ParseException e) { throw new BugzillaException(e); } finally { - method.releaseConnection(); - // httpClient.getParams().setAuthenticationPreemptive(false); + if (method != null) { + method.releaseConnection(); + } } } @@ -321,7 +330,7 @@ public class BugzillaClient { HtmlTag tag = (HtmlTag) token.getValue(); if (tag.getTagType() == HtmlTag.Type.A) { String id = tag.getAttribute("href"); - if (id != null && id.toLowerCase().contains("goaheadandlogin=1")) { + if (id != null && id.toLowerCase().contains(LOGIN_REQUIRED)) { throw new LoginException("Invalid credentials."); } } @@ -381,6 +390,7 @@ public class BugzillaClient { } } } + // public static String addCredentials(String url, String encoding, String // userName, String password) @@ -400,31 +410,37 @@ public class BugzillaClient { public void getSearchHits(AbstractRepositoryQuery query, QueryHitCollector collector, TaskList taskList) throws IOException, BugzillaException, GeneralSecurityException { - String queryUrl = query.getUrl(); - // Test that we don't specify content type twice. - // Should only be specified here (not in passed in url if possible) - if (!queryUrl.contains("ctype=rdf")) { - queryUrl = queryUrl.concat(IBugzillaConstants.CONTENT_TYPE_RDF); - } - GetMethod method = getConnect(queryUrl); - - if (method.getResponseHeader("Content-Type") != null) { - Header responseTypeHeader = method.getResponseHeader("Content-Type"); - for (String type : VALID_CONFIG_CONTENT_TYPES) { - if (responseTypeHeader.getValue().toLowerCase().contains(type)) { - RepositoryQueryResultsFactory queryFactory = new RepositoryQueryResultsFactory(method - .getResponseBodyAsStream(), characterEncoding); - queryFactory.performQuery(taskList, repositoryUrl.toString(), collector, query.getMaxHits()); - return; + GetMethod method = null; + try { + String queryUrl = query.getUrl(); + // Test that we don't specify content type twice. + // Should only be specified here (not in passed in url if possible) + if (!queryUrl.contains("ctype=rdf")) { + queryUrl = queryUrl.concat(IBugzillaConstants.CONTENT_TYPE_RDF); + } + method = getConnect(queryUrl); + + if (method.getResponseHeader("Content-Type") != null) { + Header responseTypeHeader = method.getResponseHeader("Content-Type"); + for (String type : VALID_CONFIG_CONTENT_TYPES) { + if (responseTypeHeader.getValue().toLowerCase().contains(type)) { + RepositoryQueryResultsFactory queryFactory = new RepositoryQueryResultsFactory(method + .getResponseBodyAsStream(), characterEncoding); + queryFactory.performQuery(taskList, repositoryUrl.toString(), collector, query.getMaxHits()); + return; + } } } - } - try { parseHtmlError(new BufferedReader( new InputStreamReader(method.getResponseBodyAsStream(), characterEncoding))); } catch (LoginException e) { authenticated = false; throw e; + + } finally { + if (method != null) { + method.releaseConnection(); + } } } @@ -438,7 +454,7 @@ public class BugzillaClient { BugzillaReportElement.PRIORITY, BugzillaReportElement.BUG_SEVERITY, BugzillaReportElement.ASSIGNED_TO, BugzillaReportElement.TARGET_MILESTONE, BugzillaReportElement.REPORTER, BugzillaReportElement.DEPENDSON, BugzillaReportElement.BLOCKED, BugzillaReportElement.BUG_FILE_LOC, - BugzillaReportElement.NEWCC, BugzillaReportElement.KEYWORDS, BugzillaReportElement.CC}; // BugzillaReportElement.VOTES, + BugzillaReportElement.NEWCC, BugzillaReportElement.KEYWORDS, BugzillaReportElement.CC }; // BugzillaReportElement.VOTES, for (BugzillaReportElement element : reportElements) { RepositoryTaskAttribute reportAttribute = BugzillaClient.makeNewAttribute(element); @@ -517,20 +533,6 @@ public class BugzillaClient { } } - public InputStream getAttachmentInputStream(String id) throws LoginException, IOException, BugzillaException { - GetMethod method = null; - try { - String url = repositoryUrl + IBugzillaConstants.URL_GET_ATTACHMENT_DOWNLOAD + id; - method = getConnect(url); - return method.getResponseBodyAsStream(); - - } finally { - if (method != null) { - method.releaseConnection(); - } - } - } - public void postAttachment(String bugReportID, String comment, String description, File sourceFile, String contentType, boolean isPatch) throws HttpException, IOException, LoginException, BugzillaException { WebClientUtil.setupHttpClient(httpClient, proxy, repositoryUrl.toString(), htAuthUser, htAuthPass); @@ -607,7 +609,12 @@ public class BugzillaClient { } - public InputStream postFormData(String formUrl, NameValuePair[] formData) throws LoginException, IOException, + /** + * calling method must release the connection on the + * returned PostMethod once finished. + * TODO: refactor + */ + public PostMethod postFormData(String formUrl, NameValuePair[] formData) throws LoginException, IOException, BugzillaException { WebClientUtil.setupHttpClient(httpClient, proxy, repositoryUrl.toString(), htAuthUser, htAuthPass); if (!authenticated && hasAuthenticationCredentials()) { @@ -628,7 +635,7 @@ public class BugzillaClient { // httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT); int status = httpClient.executeMethod(postMethod); if (status == HttpStatus.SC_OK) { - return postMethod.getResponseBodyAsStream(); + return postMethod; } else { MylarStatusHandler.log("Post failed: " + HttpStatus.getStatusText(status), this); throw new IOException("Communication error occurred during upload. \n\n" + HttpStatus.getStatusText(status)); diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java index 257352a6c..5141a78f0 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java @@ -24,8 +24,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.httpclient.NameValuePair; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; +import org.apache.commons.httpclient.methods.PostMethod; import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer; import org.eclipse.mylar.internal.tasks.core.HtmlTag; import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token; @@ -324,13 +323,18 @@ public class BugzillaReportSubmitForm { NameValuePair[] formData = fields.values().toArray(new NameValuePair[fields.size()]); InputStream inputStream = null; String result = null; + PostMethod method = null; try { if (isNewBugPost()) { - inputStream = client.postFormData(POST_BUG_CGI, formData); + method = client.postFormData(POST_BUG_CGI, formData); } else { - inputStream = client.postFormData(PROCESS_BUG_CGI, formData); + method = client.postFormData(PROCESS_BUG_CGI, formData); } - BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); + + if (method == null) + throw new BugzillaException("Could not post form"); + + BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); in.mark(10); HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(in, null); @@ -389,14 +393,11 @@ public class BugzillaReportSubmitForm { } catch (ParseException e) { throw new IOException("Could not parse response from server."); } finally { - try { - if (inputStream != null) { - inputStream.close(); - } - - } catch (IOException e) { - BugzillaCorePlugin.log(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.ERROR, - "Problem posting the bug", e)); + if (inputStream != null) { + inputStream.close(); + } + if (method != null) { + method.releaseConnection(); } } // return the bug number |