Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2006-07-27 19:15:18 -0400
committermkersten2006-07-27 19:15:18 -0400
commita78c7ecd6a9f8b9e1064b746a9f77349fbdef290 (patch)
tree629085e619a0f15756a948565f508bcb70123824
parentbe5d594e9c1ce67b5086eef5de3878def1663830 (diff)
downloadorg.eclipse.mylyn.tasks-a78c7ecd6a9f8b9e1064b746a9f77349fbdef290.tar.gz
org.eclipse.mylyn.tasks-a78c7ecd6a9f8b9e1064b746a9f77349fbdef290.tar.xz
org.eclipse.mylyn.tasks-a78c7ecd6a9f8b9e1064b746a9f77349fbdef290.zip
Completed: 151077: Add support for HTTP Digest authentication to Trac connector
https://bugs.eclipse.org/bugs/show_bug.cgi?id=151077
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/UrlConnectionUtil.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java2
-rw-r--r--org.eclipse.mylyn.trac.tests/.cvsignore2
-rw-r--r--org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientRepositoryTest.java70
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java41
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientTest.java72
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java2
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java6
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientSearchTest.java11
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientTest.java30
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java2
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracTestPlugin.java52
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientSearchTest.java14
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java27
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/AbstractTracRepositoryFactory.java52
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java6
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracUiPlugin.java59
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/Trac09Client.java239
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracHttpClientTransportFactory.java53
-rw-r--r--org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/model/TracTicket.java7
21 files changed, 448 insertions, 303 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/UrlConnectionUtil.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/UrlConnectionUtil.java
index 0b0bbd721..9c730e689 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/UrlConnectionUtil.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/UrlConnectionUtil.java
@@ -35,7 +35,7 @@ public class UrlConnectionUtil {
private static final int HTTPS_PORT = 443;
- static {
+ public static void initCommonsLoggingSettings() {
// TODO: move?
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "off");
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
index db4ad9e66..d92e7ee92 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java
@@ -33,6 +33,7 @@ import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.mylar.context.core.ContextCorePlugin;
import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.internal.context.core.MylarPreferenceContstants;
+import org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil;
import org.eclipse.mylar.internal.tasks.ui.IDynamicSubMenuContributor;
import org.eclipse.mylar.internal.tasks.ui.ITaskEditorFactory;
import org.eclipse.mylar.internal.tasks.ui.ITaskHighlighter;
@@ -331,6 +332,7 @@ public class TasksUiPlugin extends AbstractUIPlugin implements IStartup {
super.start(context);
// NOTE: Startup order is very sensitive
try {
+ UrlConnectionUtil.initCommonsLoggingSettings();
initializeDefaultPreferences(getPreferenceStore());
taskListWriter = new TaskListWriter();
diff --git a/org.eclipse.mylyn.trac.tests/.cvsignore b/org.eclipse.mylyn.trac.tests/.cvsignore
index ba077a403..b0b9ecf46 100644
--- a/org.eclipse.mylyn.trac.tests/.cvsignore
+++ b/org.eclipse.mylyn.trac.tests/.cvsignore
@@ -1 +1,3 @@
bin
+credentials.properties
+credentials.properties
diff --git a/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
index c6ff60942..a3827b263 100644
--- a/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
@@ -12,3 +12,5 @@ Require-Bundle: org.junit,
org.eclipse.mylar.trac.ui,
org.eclipse.mylar.tasks.core
Export-Package: org.eclipse.mylar.trac.tests
+Bundle-Activator: org.eclipse.mylar.trac.tests.TracTestPlugin
+Eclipse-LazyStart: true
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientRepositoryTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientRepositoryTest.java
new file mode 100644
index 000000000..fb3d4c5a7
--- /dev/null
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientRepositoryTest.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.trac.tests;
+
+import org.eclipse.mylar.internal.trac.core.TracException;
+import org.eclipse.mylar.internal.trac.core.TracLoginException;
+import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
+
+/**
+ * Test cases for classes that implement {@link ITracClient}.
+ *
+ * @author Steffen Pingel
+ */
+public class AbstractTracClientRepositoryTest extends AbstractTracClientTest {
+
+ public AbstractTracClientRepositoryTest(Version version) {
+ super(version);
+ }
+
+ public void testValidate010() throws Exception {
+ connect010();
+ validate();
+ }
+
+ public void testValidate010DigestAuth() throws Exception {
+ connect010DigestAuth();
+ validate();
+ }
+
+ protected void validate() throws TracException {
+ repository.validate();
+ }
+
+ public void testValidateFailWrongUrl() throws Exception {
+ connect("http://non.existant/repository");
+ try {
+ repository.validate();
+ fail("Expected TracException");
+ } catch (TracException e) {
+ }
+ }
+
+ public void testValidateFailAuthWrongPassword() throws Exception {
+ connect(Constants.TEST_REPOSITORY1_URL, Constants.TEST_REPOSITORY1_ADMIN_USERNAME, "wrongpassword");
+ try {
+ repository.validate();
+ fail("Expected TracLoginException");
+ } catch (TracLoginException e) {
+ }
+ }
+
+ public void testValidateFailAuthWrongUsername() throws Exception {
+ connect(Constants.TEST_REPOSITORY1_URL, "wrongusername", Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
+ try {
+ repository.validate();
+ fail("Expected TracLoginException");
+ } catch (TracLoginException e) {
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java
index d87408678..8cfedbf9c 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java
@@ -15,45 +15,42 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
+import org.eclipse.mylar.internal.trac.core.ITracClient;
import org.eclipse.mylar.internal.trac.core.TracException;
+import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
import org.eclipse.mylar.internal.trac.model.TracSearch;
import org.eclipse.mylar.internal.trac.model.TracTicket;
import org.eclipse.mylar.internal.trac.model.TracTicket.Key;
-import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
import org.eclipse.mylar.trac.tests.support.TestFixture;
import org.eclipse.mylar.trac.tests.support.XmlRpcServer.TestData;
import org.eclipse.mylar.trac.tests.support.XmlRpcServer.Ticket;
/**
* Test cases that validate search results for classes that implement
- * {@link ITracRepositor}.
+ * {@link ITracClient}.
*
* @author Steffen Pingel
*/
-public abstract class AbstractTracClientSearchTest extends TestCase {
-
- protected AbstractTracRepositoryFactory factory;
+public abstract class AbstractTracClientSearchTest extends AbstractTracClientTest {
protected List<Ticket> tickets;
- public AbstractTracClientSearchTest(AbstractTracRepositoryFactory factory) {
- this.factory = factory;
+ public AbstractTracClientSearchTest(Version version) {
+ super(version);
}
protected void setUp() throws Exception {
super.setUp();
- TestData data = TestFixture.initializeRepository1();
+ TestData data = TestFixture.init010();
tickets = data.tickets;
- factory.connectRepository1();
+ connect010();
}
protected void tearDown() throws Exception {
super.tearDown();
-
+
// TestFixture.cleanupRepository1();
}
@@ -68,16 +65,16 @@ public abstract class AbstractTracClientSearchTest extends TestCase {
}
public void testGetTicket() throws Exception {
- TracTicket ticket = factory.repository.getTicket(tickets.get(0).getId());
+ TracTicket ticket = repository.getTicket(tickets.get(0).getId());
assertTicketEquals(tickets.get(0), ticket);
- ticket = factory.repository.getTicket(tickets.get(1).getId());
+ ticket = repository.getTicket(tickets.get(1).getId());
assertTicketEquals(tickets.get(1), ticket);
}
public void testGetTicketInvalidId() throws Exception {
try {
- factory.repository.getTicket(Integer.MAX_VALUE);
+ repository.getTicket(Integer.MAX_VALUE);
fail("Expected TracException");
} catch (TracException e) {
}
@@ -85,8 +82,12 @@ public abstract class AbstractTracClientSearchTest extends TestCase {
public void testSearchAll() throws Exception {
TracSearch search = new TracSearch();
+ // TODO figure out why search must be ordered when logged in (otherwise
+ // no results will be returned)
+ search.setOrderBy("id");
List<TracTicket> result = new ArrayList<TracTicket>();
- factory.repository.search(search, result);
+ repository.search(search, result);
+ System.out.println(result.size());
assertEquals(tickets.size(), result.size());
}
@@ -94,7 +95,7 @@ public abstract class AbstractTracClientSearchTest extends TestCase {
TracSearch search = new TracSearch();
search.addFilter("milestone", "does not exist");
List<TracTicket> result = new ArrayList<TracTicket>();
- factory.repository.search(search, result);
+ repository.search(search, result);
assertEquals(0, result.size());
}
@@ -102,7 +103,7 @@ public abstract class AbstractTracClientSearchTest extends TestCase {
TracSearch search = new TracSearch();
search.addFilter("milestone", "m1");
List<TracTicket> result = new ArrayList<TracTicket>();
- factory.repository.search(search, result);
+ repository.search(search, result);
assertEquals(1, result.size());
assertTicketEquals(tickets.get(0), result.get(0));
}
@@ -113,7 +114,7 @@ public abstract class AbstractTracClientSearchTest extends TestCase {
search.addFilter("milestone", "m2");
search.setOrderBy("id");
List<TracTicket> result = new ArrayList<TracTicket>();
- factory.repository.search(search, result);
+ repository.search(search, result);
assertEquals(3, result.size());
assertTicketEquals(tickets.get(0), result.get(0));
assertTicketEquals(tickets.get(1), result.get(1));
@@ -125,7 +126,7 @@ public abstract class AbstractTracClientSearchTest extends TestCase {
search.addFilter("milestone", "m1");
search.addFilter("summary", "summary1");
List<TracTicket> result = new ArrayList<TracTicket>();
- factory.repository.search(search, result);
+ repository.search(search, result);
assertEquals(1, result.size());
assertTicketEquals(tickets.get(0), result.get(0));
assertEquals("m1", result.get(0).getValue(Key.MILESTONE));
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientTest.java
index 04016d479..f6e937fe5 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientTest.java
@@ -11,45 +11,75 @@
package org.eclipse.mylar.trac.tests;
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.Properties;
+
import junit.framework.TestCase;
-import org.eclipse.mylar.internal.trac.core.TracLoginException;
-import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.mylar.internal.trac.core.ITracClient;
+import org.eclipse.mylar.internal.trac.core.TracClientFactory;
+import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
/**
- * Test cases for classes that implement {@link ITracRepositor}.
+ * Provides a base implementation for test cases that access trac repositories.
*
* @author Steffen Pingel
*/
public abstract class AbstractTracClientTest extends TestCase {
- protected AbstractTracRepositoryFactory factory;
+ public String repositoryUrl;
+
+ public ITracClient repository;
+
+ public String username;
+
+ public String password;
- public AbstractTracClientTest(AbstractTracRepositoryFactory factory) {
- this.factory = factory;
+ private Version version;
+
+ public AbstractTracClientTest(Version version) {
+ this.version = version;
}
- public void testValidate() throws Exception {
- factory.connectRepository1();
- factory.repository.validate();
+ public ITracClient connect096() throws Exception {
+ return connect(Constants.TEST_TRAC_096_URL);
}
- public void testValidateFailAuthWrongPassword() throws Exception {
- factory.connect(Constants.TEST_REPOSITORY1_URL, Constants.TEST_REPOSITORY1_ADMIN_USERNAME, "wrongpassword");
- try {
- factory.repository.validate();
- fail("Expected TracLoginException");
- } catch (TracLoginException e) {
- }
+ public ITracClient connect010() throws Exception {
+ return connect(Constants.TEST_REPOSITORY1_URL, Constants.TEST_REPOSITORY1_ADMIN_USERNAME,
+ Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
}
- public void testValidateFailAuthWrongUsername() throws Exception {
- factory.connect(Constants.TEST_REPOSITORY1_URL, "wrongusername", Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
+ public ITracClient connect010DigestAuth() throws Exception {
+ return connect(Constants.TEST_TRAC_010_DIGEST_AUTH_URL);
+ }
+
+ public ITracClient connect(String url) throws Exception {
try {
- factory.repository.validate();
- fail("Expected TracLoginException");
- } catch (TracLoginException e) {
+ Properties properties = new Properties();
+ URL localURL = FileLocator.toFileURL(TracTestPlugin.getDefault().getBundle().getEntry(
+ "credentials.properties"));
+ properties.load(new FileInputStream(new File(localURL.getFile())));
+ return connect(url, properties.getProperty("username"), properties.getProperty("password"));
+ } catch (Throwable t) {
+ fail("must define credentials in <plug-in dir>/credentials.properties");
}
+ return null; // never reached
+ }
+
+ public ITracClient connect(String url, String username, String password) throws Exception {
+ this.repositoryUrl = url;
+ this.username = username;
+ this.password = password;
+ this.repository = TracClientFactory.createClient(url, version, username, password);
+
+ // make sure no dialog pops up to prompt for a password
+ // Authenticator.setDefault(null);
+
+ return this.repository;
}
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
index eaed32e34..cf4962872 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
@@ -21,6 +21,8 @@ import junit.framework.TestSuite;
public class AllTracTests {
public static Test suite() {
+// UrlConnectionUtil.initCommonsLoggingSettings();
+
TestSuite suite = new TestSuite("Test for org.eclipse.mylar.trac.tests");
// $JUnit-BEGIN$
// suite.addTestSuite(TracXmlRpcTest.class);
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java
index e856d96c7..fff8739d0 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java
@@ -28,4 +28,10 @@ public class Constants {
public static final String TEST_REPOSITORY1_PASSWORD = "trac-test";
+ public static final String TEST_TRAC_096_URL = "http://mylar.eclipse.org/trac096";
+
+ public static final String TEST_TRAC_010_URL = "http://mylar.eclipse.org/trac010";
+
+ public static final String TEST_TRAC_010_DIGEST_AUTH_URL = "http://mylar.eclipse.org/trac010digest";
+
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientSearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientSearchTest.java
index 20f9bc3bc..27c6b809f 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientSearchTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientSearchTest.java
@@ -11,12 +11,7 @@
package org.eclipse.mylar.trac.tests;
-import java.net.URL;
-
-import org.eclipse.mylar.internal.trac.core.ITracClient;
-import org.eclipse.mylar.internal.trac.core.Trac09Client;
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
-import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
/**
* @author Steffen Pingel
@@ -24,11 +19,7 @@ import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
public class Trac09ClientSearchTest extends AbstractTracClientSearchTest {
public Trac09ClientSearchTest() {
- super(new AbstractTracRepositoryFactory() {
- protected ITracClient createRepository(String url, String username, String password) throws Exception {
- return new Trac09Client(new URL(url), Version.TRAC_0_9, username, password);
- }
- });
+ super(Version.TRAC_0_9);
}
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientTest.java
index 43a49efa0..c9d00532a 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Trac09ClientTest.java
@@ -11,40 +11,37 @@
package org.eclipse.mylar.trac.tests;
-import java.net.URL;
import java.util.Arrays;
import java.util.Comparator;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.mylar.internal.trac.core.ITracClient;
-import org.eclipse.mylar.internal.trac.core.Trac09Client;
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
import org.eclipse.mylar.internal.trac.model.TracVersion;
-import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
/**
* @author Steffen Pingel
*/
-public class Trac09ClientTest extends AbstractTracClientTest {
+public class Trac09ClientTest extends AbstractTracClientRepositoryTest {
public Trac09ClientTest() {
- super(new AbstractTracRepositoryFactory() {
- protected ITracClient createRepository(String url, String username, String password) throws Exception {
- return new Trac09Client(new URL(url), Version.TRAC_0_9, username, password);
- }
- });
+ super(Version.TRAC_0_9);
+ }
+
+ public void testValidate096() throws Exception {
+ connect096();
+ validate();
}
public void testValidateAnonymousLogin() throws Exception {
- factory.connect(Constants.TEST_REPOSITORY1_URL, "", "");
- factory.repository.validate();
+ connect(Constants.TEST_REPOSITORY1_URL, "", "");
+ repository.validate();
}
public void testUpdateAttributes() throws Exception {
- factory.connectRepository1();
- assertNull(factory.repository.getMilestones());
- factory.repository.updateAttributes(new NullProgressMonitor());
- TracVersion[] versions = factory.repository.getVersions();
+ connect010();
+ assertNull(repository.getMilestones());
+ repository.updateAttributes(new NullProgressMonitor());
+ TracVersion[] versions = repository.getVersions();
assertEquals(2, versions.length);
Arrays.sort(versions, new Comparator<TracVersion>() {
public int compare(TracVersion o1, TracVersion o2) {
@@ -55,5 +52,4 @@ public class Trac09ClientTest extends AbstractTracClientTest {
assertEquals("v2", versions[1].getName());
}
-
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
index 20d719375..88f80c8b3 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
@@ -67,7 +67,7 @@ public class TracRepositoryConnectorTest extends TestCase {
tasklist = TasksUiPlugin.getTaskListManager().getTaskList();
- data = TestFixture.initializeRepository1();
+ data = TestFixture.init010();
}
protected void tearDown() throws Exception {
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracTestPlugin.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracTestPlugin.java
new file mode 100644
index 000000000..35aa3f5f7
--- /dev/null
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracTestPlugin.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.trac.tests;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ *
+ * @author Steffen Pingel
+ */
+public class TracTestPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.mylar.trac.tests";
+
+ // The shared instance
+ private static TracTestPlugin plugin;
+
+ public TracTestPlugin() {
+ plugin = this;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static TracTestPlugin getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientSearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientSearchTest.java
index 11a432200..9b870c8e0 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientSearchTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientSearchTest.java
@@ -11,17 +11,13 @@
package org.eclipse.mylar.trac.tests;
-import java.net.URL;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.mylar.internal.trac.core.ITracClient;
-import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
import org.eclipse.mylar.internal.trac.model.TracSearch;
import org.eclipse.mylar.internal.trac.model.TracTicket;
import org.eclipse.mylar.internal.trac.model.TracTicket.Key;
-import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
/**
* @author Steffen Pingel
@@ -29,24 +25,20 @@ import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
public class TracXmlRpcClientSearchTest extends AbstractTracClientSearchTest {
public TracXmlRpcClientSearchTest() {
- super(new AbstractTracRepositoryFactory() {
- protected ITracClient createRepository(String url, String username, String password) throws Exception {
- return new TracXmlRpcClient(new URL(url), Version.XML_RPC, username, password);
- }
- });
+ super(Version.XML_RPC);
}
public void testSearchValidateTicket() throws Exception {
TracSearch search = new TracSearch();
search.addFilter("summary", "summary1");
List<TracTicket> result = new ArrayList<TracTicket>();
- factory.repository.search(search, result);
+ repository.search(search, result);
assertEquals(1, result.size());
assertTicketEquals(tickets.get(0), result.get(0));
assertEquals("component1", result.get(0).getValue(Key.COMPONENT));
assertEquals("description1", result.get(0).getValue(Key.DESCRIPTION));
assertEquals("m1", result.get(0).getValue(Key.MILESTONE));
- assertEquals(factory.username, result.get(0).getValue(Key.REPORTER));
+ assertEquals(username, result.get(0).getValue(Key.REPORTER));
assertEquals("summary1", result.get(0).getValue(Key.SUMMARY));
// assertEquals("", result.get(0).getValue(Key.VERSION));
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java
index fdc03af8f..5d527d8f3 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java
@@ -11,56 +11,49 @@
package org.eclipse.mylar.trac.tests;
-import java.net.URL;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.mylar.internal.trac.core.ITracClient;
import org.eclipse.mylar.internal.trac.core.TracLoginException;
import org.eclipse.mylar.internal.trac.core.TracRemoteException;
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
import org.eclipse.mylar.internal.trac.model.TracVersion;
-import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
/**
* @author Steffen Pingel
*/
-public class TracXmlRpcClientTest extends AbstractTracClientTest {
+public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest {
public TracXmlRpcClientTest() {
- super(new AbstractTracRepositoryFactory() {
- protected ITracClient createRepository(String url, String username, String password) throws Exception {
- return new TracXmlRpcClient(new URL(url), Version.XML_RPC, username, password);
- }
- });
+ super(Version.XML_RPC);
}
public void testValidateFailNoAuth() throws Exception {
- factory.connect(Constants.TEST_REPOSITORY1_URL, "", "");
+ connect(Constants.TEST_REPOSITORY1_URL, "", "");
try {
- factory.repository.validate();
+ repository.validate();
fail("Expected TracLoginException");
} catch (TracLoginException e) {
}
}
public void testMulticallExceptions() throws Exception {
- factory.connectRepository1();
+ connect010();
try {
- ((TracXmlRpcClient) factory.repository).getTickets(new int[] { 1, Integer.MAX_VALUE });
+ ((TracXmlRpcClient) repository).getTickets(new int[] { 1, Integer.MAX_VALUE });
fail("Expected TracRemoteException");
} catch (TracRemoteException e) {
}
}
public void testUpdateAttributes() throws Exception {
- factory.connectRepository1();
- assertNull(factory.repository.getMilestones());
- factory.repository.updateAttributes(new NullProgressMonitor());
- TracVersion[] versions = factory.repository.getVersions();
+ connect010();
+ assertNull(repository.getMilestones());
+ repository.updateAttributes(new NullProgressMonitor());
+ TracVersion[] versions = repository.getVersions();
assertEquals(2, versions.length);
Arrays.sort(versions, new Comparator<TracVersion>() {
public int compare(TracVersion o1, TracVersion o2) {
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/AbstractTracRepositoryFactory.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/AbstractTracRepositoryFactory.java
deleted file mode 100644
index e638fcbaa..000000000
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/AbstractTracRepositoryFactory.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Mylar project committers - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylar.trac.tests.support;
-
-import java.net.Authenticator;
-
-import org.eclipse.mylar.internal.trac.core.ITracClient;
-import org.eclipse.mylar.trac.tests.Constants;
-
-/**
- * @author Steffen Pingel
- *
- */
-public abstract class AbstractTracRepositoryFactory {
-
- public String repositoryUrl;
-
- public ITracClient repository;
-
- public String username;
-
- public String password;
-
- public ITracClient connectRepository1() throws Exception {
- return connect(Constants.TEST_REPOSITORY1_URL, Constants.TEST_REPOSITORY1_ADMIN_USERNAME,
- Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
- }
-
- public ITracClient connect(String url, String username, String password) throws Exception {
- this.repositoryUrl = url;
- this.username = username;
- this.password = password;
- this.repository = createRepository(url, username, password);
-
- // make sure no dialog pops up to prompt for a password
- Authenticator.setDefault(null);
-
- return this.repository;
- }
-
- protected abstract ITracClient createRepository(String url, String username, String password) throws Exception;
-
-}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java
index 11bdc5d0d..ae2115472 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java
@@ -25,7 +25,7 @@ public class TestFixture {
public static XmlRpcServer.TestData data1;
- public static XmlRpcServer.TestData initializeRepository1() throws Exception {
+ public static XmlRpcServer.TestData init010() throws Exception {
if (data1 == null) {
XmlRpcServer server = new XmlRpcServer(Constants.TEST_REPOSITORY1_URL,
Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
@@ -33,7 +33,7 @@ public class TestFixture {
server.ticketVersion(null).deleteAll();
server.ticketVersion("v1").create(86400, "description1");
server.ticketVersion("v2").create(86400 * 2, "description2");
-
+
server.ticket().deleteAll();
server.ticketMilestone("m1").deleteAndCreate();
@@ -53,7 +53,7 @@ public class TestFixture {
return data1;
}
- public static void cleanupRepository1() throws Exception {
+ public static void cleanup010() throws Exception {
if (data1 != null) {
data1.cleanup();
data1 = null;
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracUiPlugin.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracUiPlugin.java
index 155ecf784..9acc74ca0 100644
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracUiPlugin.java
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/TracUiPlugin.java
@@ -11,29 +11,14 @@
package org.eclipse.mylar.internal.trac;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.Proxy;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.internal.tasks.ui.views.TaskRepositoriesView;
import org.eclipse.mylar.internal.trac.core.TracException;
import org.eclipse.mylar.internal.trac.core.TracLoginException;
-import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
-import sun.misc.BASE64Encoder;
-
/**
* @author Mik Kersten
* @author Steffen Pingel
@@ -65,49 +50,6 @@ public class TracUiPlugin extends AbstractUIPlugin {
return plugin;
}
- /**
- * Copied from BugzillaPlugin.
- *
- * TODO refactor into common utility method
- */
- public static HttpURLConnection getHttpConnection(URL url) throws IOException, NoSuchAlgorithmException,
- KeyManagementException, MalformedURLException {
- Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
- URLConnection cntx = getUrlConnection(url, proxySettings);
- if (cntx == null || !(cntx instanceof HttpURLConnection)) {
- throw new MalformedURLException();
- }
-
- HttpURLConnection connection = (HttpURLConnection) cntx;
- return connection;
- }
-
- /**
- * Copied from BugzillaPlugin.getUrlConnection().
- *
- * TODO refactor into common utility method
- */
- public static URLConnection getUrlConnection(URL url, Proxy proxy) throws IOException, NoSuchAlgorithmException,
- KeyManagementException {
- SSLContext ctx = SSLContext.getInstance("TLS");
-
- javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[] { new TrustAll() };
- ctx.init(null, tm, null);
- HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
-
- if (proxy == null) {
- proxy = Proxy.NO_PROXY;
- }
- URLConnection connection = url.openConnection(proxy);
- return connection;
- }
-
- public static void setAuthCredentials(URLConnection connection, String username, String password) {
- byte[] credentials = (username + ":" + password).getBytes();
- BASE64Encoder encoder = new BASE64Encoder();
- connection.setRequestProperty("Authorization", "Basic " + encoder.encode(credentials));
- }
-
public static void handleTracException(Throwable e) {
if (e instanceof TracLoginException) {
MessageDialog.openError(null, TITLE_MESSAGE_DIALOG,
@@ -121,4 +63,5 @@ public class TracUiPlugin extends AbstractUIPlugin {
MylarStatusHandler.fail(e, "Unexpected error: " + e.getMessage(), true);
}
}
+
}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/Trac09Client.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/Trac09Client.java
index 4993b9367..17b686e3f 100644
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/Trac09Client.java
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/Trac09Client.java
@@ -11,15 +11,11 @@
package org.eclipse.mylar.internal.trac.core;
-import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -29,13 +25,20 @@ import java.util.StringTokenizer;
import javax.security.auth.login.LoginException;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.cookie.CookiePolicy;
+import org.apache.commons.httpclient.methods.GetMethod;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer;
import org.eclipse.mylar.internal.tasks.core.HtmlTag;
+import org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil;
import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token;
-import org.eclipse.mylar.internal.trac.TracUiPlugin;
+import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory.TracHttpException;
import org.eclipse.mylar.internal.trac.model.TracComponent;
import org.eclipse.mylar.internal.trac.model.TracMilestone;
import org.eclipse.mylar.internal.trac.model.TracPriority;
@@ -49,35 +52,27 @@ import org.eclipse.mylar.internal.trac.model.TracTicketType;
import org.eclipse.mylar.internal.trac.model.TracVersion;
import org.eclipse.mylar.internal.trac.model.TracSearchFilter.CompareOperator;
import org.eclipse.mylar.internal.trac.model.TracTicket.Key;
-
+import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
+
+/**
+ * Represents a Trac repository that is accessed through the Trac's query script
+ * and web interface.
+ *
+ * @author Steffen Pingel
+ */
public class Trac09Client extends AbstractTracClient {
- private static final String TICKET_SUMMARY_PREFIX = " <h2 class=\"summary\">";
-
- private static final String TICKET_SUMMARY_POSTFIX = "</h2>";
+ private HttpClient httpClient = new HttpClient();
- private InputStream in;
-
- private String authCookie;
+ private boolean authenticated;
public Trac09Client(URL url, Version version, String username, String password) {
super(url, version, username, password);
}
- public void close() {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- MylarStatusHandler.log(e, "Error closing connection");
- }
- in = null;
- }
- }
-
- public void connect(String serverURL) throws TracException {
+ private GetMethod connect(String serverURL) throws TracException {
try {
- connectInternal(new URL(serverURL));
+ return connectInternal(serverURL);
} catch (TracException e) {
throw e;
} catch (Exception e) {
@@ -85,58 +80,64 @@ public class Trac09Client extends AbstractTracClient {
}
}
- private void connectInternal(URL serverURL) throws IOException, KeyManagementException, NoSuchAlgorithmException,
- TracLoginException {
- for (int attempt = 0; attempt < 2; attempt++) {
- HttpURLConnection serverConnection = TracUiPlugin.getHttpConnection(serverURL);
- setupSession(serverConnection);
+ private GetMethod connectInternal(String serverURL) throws TracLoginException, IOException, TracHttpException {
+ UrlConnectionUtil.setupHttpClient(httpClient, TasksUiPlugin.getDefault().getProxySettings(), serverURL);
- serverConnection.connect();
+ for (int attempt = 0; attempt < 2; attempt++) {
+ // force authentication
+ if (!authenticated && hasAuthenticationCredentials()) {
+ authenticate();
+ }
- int code = serverConnection.getResponseCode();
- if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
- // retry to authenticate due to an expired session
- authCookie = null;
- continue;
+ GetMethod method = new GetMethod(UrlConnectionUtil.getRequestPath(serverURL));
+ method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
+ int code;
+ try {
+ code = httpClient.executeMethod(method);
+ } catch (IOException e) {
+ method.releaseConnection();
+ throw e;
}
- in = new BufferedInputStream(serverConnection.getInputStream());
- return;
+ if (code == HttpURLConnection.HTTP_OK) {
+ return method;
+ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
+ // login or reauthenticate due to an expired session
+ method.releaseConnection();
+ authenticated = false;
+ authenticate();
+ } else {
+ throw new TracHttpException(code);
+ }
}
throw new TracLoginException();
}
- private void setupSession(HttpURLConnection serverConnection) throws IOException, TracLoginException,
- KeyManagementException, NoSuchAlgorithmException {
- if (hasAuthenticationCredentials()) {
- if (authCookie == null) {
- // go through the /login page redirection
- HttpURLConnection loginConnection = TracUiPlugin
- .getHttpConnection(new URL(repositoryUrl + LOGIN_URL));
- TracUiPlugin.setAuthCredentials(loginConnection, username, password);
-
- loginConnection.connect();
+ private void authenticate() throws TracLoginException, IOException {
+ if (!hasAuthenticationCredentials()) {
+ throw new TracLoginException();
+ }
- int code = loginConnection.getResponseCode();
- if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
- throw new TracLoginException();
- }
+ Credentials credentials = new UsernamePasswordCredentials(username, password);
+ httpClient.getState().setCredentials(
+ new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), credentials);
- String cookie = loginConnection.getHeaderField("Set-Cookie");
- if (cookie == null) {
- throw new TracLoginException("Missing authorization cookie");
- }
+ GetMethod method = new GetMethod(UrlConnectionUtil.getRequestPath(repositoryUrl + LOGIN_URL));
+ method.setFollowRedirects(false);
- int index = cookie.indexOf(";");
- if (index >= 0) {
- cookie = cookie.substring(0, index);
- }
- authCookie = cookie;
+ try {
+ httpClient.getParams().setAuthenticationPreemptive(true);
+ int code = httpClient.executeMethod(method);
+ if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
+ throw new TracLoginException();
}
-
- serverConnection.setRequestProperty("Cookie", authCookie);
+ } finally {
+ method.releaseConnection();
+ httpClient.getParams().setAuthenticationPreemptive(false);
}
+
+ authenticated = true;
}
/**
@@ -147,33 +148,76 @@ public class Trac09Client extends AbstractTracClient {
* @throws LoginException
*/
public TracTicket getTicket(int id) throws TracException {
- connect(repositoryUrl + ITracClient.TICKET_URL + id);
+ GetMethod method = connect(repositoryUrl + ITracClient.TICKET_URL + id);
try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in, ITracClient.CHARSET));
- String line;
- while ((line = reader.readLine()) != null) {
- // look for heading tags in html output
- if (line.startsWith(TICKET_SUMMARY_PREFIX) && line.endsWith(TICKET_SUMMARY_POSTFIX)) {
- String summary = line.substring(TICKET_SUMMARY_PREFIX.length(), line.length()
- - TICKET_SUMMARY_POSTFIX.length());
-
- TracTicket ticket = new TracTicket(id);
- ticket.putBuiltinValue(Key.SUMMARY, summary);
- return ticket;
+ TracTicket ticket = new TracTicket(id);
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(),
+ ITracClient.CHARSET));
+ HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(reader, null);
+ for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
+ if (token.getType() == Token.TAG) {
+ HtmlTag tag = (HtmlTag) token.getValue();
+ if (tag.getTagType() == HtmlTag.Type.TD) {
+ String headers = tag.getAttribute("headers");
+ if ("h_component".equals(headers)) {
+ ticket.putBuiltinValue(Key.COMPONENT, getText(tokenizer));
+ } else if ("h_milestone".equals(headers)) {
+ ticket.putBuiltinValue(Key.MILESTONE, getText(tokenizer));
+ } else if ("h_priority".equals(headers)) {
+ ticket.putBuiltinValue(Key.PRIORITY, getText(tokenizer));
+ } else if ("h_severity".equals(headers)) {
+ ticket.putBuiltinValue(Key.SEVERITY, getText(tokenizer));
+ } else if ("h_version".equals(headers)) {
+ ticket.putBuiltinValue(Key.VERSION, getText(tokenizer));
+ } else if ("h_keywords".equals(headers)) {
+ ticket.putBuiltinValue(Key.KEYWORDS, getText(tokenizer));
+ } else if ("h_cc".equals(headers)) {
+ ticket.putBuiltinValue(Key.CC, getText(tokenizer));
+ } else if ("h_owner".equals(headers)) {
+ ticket.putBuiltinValue(Key.OWNER, getText(tokenizer));
+ } else if ("h_reporter".equals(headers)) {
+ ticket.putBuiltinValue(Key.REPORTER, getText(tokenizer));
+ }
+ // TODO handle custom fields
+ } else if (tag.getTagType() == HtmlTag.Type.H2 && "summary".equals(tag.getAttribute("class"))) {
+ ticket.putBuiltinValue(Key.SUMMARY, getText(tokenizer));
+ } else if (tag.getTagType() == HtmlTag.Type.H3 && "status".equals(tag.getAttribute("class"))) {
+ String text = getStrongText(tokenizer);
+ if (text.length() > 0) {
+ int i = text.indexOf(" (");
+ if (i != -1) {
+ // status contains resolution as well
+ ticket.putBuiltinValue(Key.STATUS, text.substring(0, i));
+ ticket.putBuiltinValue(Key.RESOLUTION, text.substring(i, text.length() - 1));
+ } else {
+ ticket.putBuiltinValue(Key.STATUS, text);
+ }
+ }
+ }
+ // TODO parse description
}
}
+
+ if (ticket.isValid() && ticket.getValue(Key.SUMMARY) != null) {
+ return ticket;
+ }
+
throw new InvalidTicketException();
} catch (IOException e) {
throw new TracException(e);
+ } catch (ParseException e) {
+ throw new TracException(e);
} finally {
- close();
+ method.releaseConnection();
}
}
public void search(TracSearch query, List<TracTicket> tickets) throws TracException {
- connect(repositoryUrl + ITracClient.QUERY_URL + query.toUrl());
+ GetMethod method = connect(repositoryUrl + ITracClient.QUERY_URL + query.toUrl());
try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in, ITracClient.CHARSET));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(),
+ ITracClient.CHARSET));
String line;
Map<String, String> constantValues = getExactMatchValues(query);
@@ -222,7 +266,7 @@ public class Trac09Client extends AbstractTracClient {
} catch (IOException e) {
throw new TracException(e);
} finally {
- close();
+ method.releaseConnection();
}
}
@@ -253,19 +297,17 @@ public class Trac09Client extends AbstractTracClient {
}
public void validate() throws TracException {
- try {
- connect(repositoryUrl + "/");
- } finally {
- close();
- }
+ GetMethod method = connect(repositoryUrl + "/");
+ method.releaseConnection();
}
public void updateAttributes(IProgressMonitor monitor) throws TracException {
monitor.beginTask("Updating attributes", IProgressMonitor.UNKNOWN);
- connect(repositoryUrl + ITracClient.NEW_TICKET_URL);
+ GetMethod method = connect(repositoryUrl + ITracClient.NEW_TICKET_URL);
try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in, ITracClient.CHARSET));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(),
+ ITracClient.CHARSET));
HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(reader, null);
for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
if (monitor.isCanceled()) {
@@ -316,14 +358,14 @@ public class Trac09Client extends AbstractTracClient {
}
}
}
-
+
ticketResolutions = new ArrayList<TracTicketResolution>(5);
ticketResolutions.add(new TracTicketResolution("fixed", 1));
ticketResolutions.add(new TracTicketResolution("invalid", 2));
ticketResolutions.add(new TracTicketResolution("wontfix", 3));
ticketResolutions.add(new TracTicketResolution("duplicate", 4));
ticketResolutions.add(new TracTicketResolution("worksforme", 5));
-
+
ticketStatus = new ArrayList<TracTicketStatus>(4);
ticketStatus.add(new TracTicketStatus("new", 1));
ticketStatus.add(new TracTicketStatus("assigned", 2));
@@ -334,7 +376,7 @@ public class Trac09Client extends AbstractTracClient {
} catch (ParseException e) {
throw new TracException(e);
} finally {
- close();
+ method.releaseConnection();
}
}
@@ -370,4 +412,23 @@ public class Trac09Client extends AbstractTracClient {
return sb.toString();
}
+ /**
+ * Looks for a <code>strong</code> tag and returns the text enclosed by
+ * the tag.
+ */
+ private String getStrongText(HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
+ for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
+ if (token.getType() == Token.TAG && ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.STRONG) {
+ return getText(tokenizer);
+ } else if (token.getType() == Token.COMMENT) {
+ // ignore
+ } else if (token.getType() == Token.TEXT) {
+ // ignore
+ } else {
+ break;
+ }
+ }
+ return "";
+ }
+
}
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracHttpClientTransportFactory.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracHttpClientTransportFactory.java
index bda59e59b..dccc53831 100644
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracHttpClientTransportFactory.java
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/core/TracHttpClientTransportFactory.java
@@ -11,9 +11,12 @@
package org.eclipse.mylar.internal.trac.core;
+import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.util.zip.GZIPInputStream;
@@ -21,6 +24,7 @@ import java.util.zip.GZIPInputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.client.XmlRpcClient;
@@ -28,6 +32,7 @@ import org.apache.xmlrpc.client.XmlRpcCommonsTransport;
import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
import org.apache.xmlrpc.client.XmlRpcTransport;
import org.apache.xmlrpc.client.XmlRpcTransportFactoryImpl;
+import org.apache.xmlrpc.util.XmlRpcIOException;
import org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
@@ -54,6 +59,8 @@ public class TracHttpClientTransportFactory extends XmlRpcTransportFactoryImpl {
*/
public static class TracHttpClientTransport extends XmlRpcCommonsTransport {
+ private int contentLength;
+
public TracHttpClientTransport(XmlRpcClient client) {
super(client);
@@ -149,6 +156,52 @@ public class TracHttpClientTransportFactory extends XmlRpcTransportFactoryImpl {
}
}
+ @Override
+ protected void writeRequest(final RequestWriter pWriter) throws XmlRpcException {
+ getMethod().setRequestEntity(new RequestEntity(){
+ public boolean isRepeatable() { return true; }
+ public void writeRequest(OutputStream pOut) throws IOException {
+ /* Make sure, that the socket is not closed by replacing it with our
+ * own BufferedOutputStream.
+ */
+ BufferedOutputStream bos = new BufferedOutputStream(pOut){
+ public void close() throws IOException {
+ flush();
+ }
+ };
+ try {
+ Method m = RequestWriter.class.getDeclaredMethod("write", new Class[] { OutputStream.class });
+ m.setAccessible(true);
+ m.invoke(pWriter, bos);
+ } catch (Exception e) {
+ throw new XmlRpcIOException(e);
+ }
+ }
+ public long getContentLength() { return contentLength; }
+ public String getContentType() { return "text/xml"; }
+ });
+
+ try {
+ getHttpClient().executeMethod(getMethod());
+ } catch (XmlRpcIOException e) {
+ Throwable t = e.getLinkedException();
+ if (t instanceof XmlRpcException) {
+ throw (XmlRpcException) t;
+ } else {
+ throw new XmlRpcException("Unexpected exception: " + t.getMessage(), t);
+ }
+ } catch (IOException e) {
+ throw new XmlRpcException("I/O error while communicating with HTTP server: " + e.getMessage(), e);
+ }
+ }
+
+ @Override
+ protected void setContentLength(int pLength) {
+ super.setContentLength(pLength);
+
+ this.contentLength = pLength;
+ }
+
}
private final TracHttpClientTransport transport;
diff --git a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/model/TracTicket.java b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/model/TracTicket.java
index 78c7d87bf..46b4efb48 100644
--- a/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/model/TracTicket.java
+++ b/org.eclipse.mylyn.trac.ui/src/org/eclipse/mylyn/internal/trac/model/TracTicket.java
@@ -31,9 +31,10 @@ public class TracTicket {
* @author Steffen Pingel
*/
public enum Key {
- CHANGE_TIME("changetime"), COMPONENT("component"), DESCRIPTION("description"), ID("id"), KEYWORDS("keywords"), MILESTONE(
- "milestone"), OWNER("owner"), PRIORITY("priority"), REPORTER("reporter"), RESOLUTION("resolution"), STATUS(
- "status"), SUMMARY("summary"), TIME("time"), TYPE("type"), VERSION("version");
+ CC("cc"), CHANGE_TIME("changetime"), COMPONENT("component"), DESCRIPTION("description"), ID("id"), KEYWORDS(
+ "keywords"), MILESTONE("milestone"), OWNER("owner"), PRIORITY("priority"), REPORTER("reporter"), RESOLUTION(
+ "resolution"), STATUS("status"), SEVERITY("severity"), SUMMARY("summary"), TIME("time"), TYPE("type"), VERSION(
+ "version");
public static Key fromKey(String name) {
for (Key key : Key.values()) {

Back to the top