diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/BaseRepositoryImpl.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/BaseRepositoryImpl.java index 2107c909666d..b97539b7c81e 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/BaseRepositoryImpl.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/BaseRepositoryImpl.java @@ -97,11 +97,11 @@ public abstract class BaseRepositoryImpl extends BaseRepository { protected void configureHttpMethod(HttpMethod method) {} - public abstract class HttpTestConnection extends CancellableConnection { + public abstract class HttpTestConnection extends CancellableConnection { - private HttpMethod myMethod; + private T myMethod; - public HttpTestConnection(HttpMethod method) { + public HttpTestConnection(T method) { myMethod = method; } @@ -115,6 +115,6 @@ public abstract class BaseRepositoryImpl extends BaseRepository { myMethod.abort(); } - protected abstract void doTest(HttpMethod method) throws Exception; + protected abstract void doTest(T method) throws Exception; } } diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/youtrack/YouTrackRepository.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/youtrack/YouTrackRepository.java index e9bd5c68bfdd..fa44f5c5fa33 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/youtrack/YouTrackRepository.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/youtrack/YouTrackRepository.java @@ -71,14 +71,20 @@ public class YouTrackRepository extends BaseRepositoryImpl { return taskList.toArray(new Task[taskList.size()]); } - public void testConnection() throws Exception { - getIssues(null, 10, 0); + @Override + public CancellableConnection createCancellableConnection() { + PostMethod method = new PostMethod(getUrl() + "/rest/user/login"); + return new HttpTestConnection(method) { + @Override + protected void doTest(PostMethod method) throws Exception { + login(method); + } + }; } - private HttpClient login() throws Exception { + private HttpClient login(PostMethod method) throws Exception { HttpClient client = getHttpClient(); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword())); - PostMethod method = new PostMethod(getUrl() + "/rest/user/login"); configureHttpMethod(method); method.addParameter("login", getUsername()); method.addParameter("password", getPassword()); @@ -111,7 +117,7 @@ public class YouTrackRepository extends BaseRepositoryImpl { private HttpMethod doREST(String request, boolean post) throws Exception { - HttpClient client = login(); + HttpClient client = login(new PostMethod(getUrl() + "/rest/user/login")); String uri = getUrl() + request; HttpMethod method = post ? new PostMethod(uri) : new GetMethod(uri); configureHttpMethod(method);