Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 151896 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaRepositoryConnectorTest.java (-17 lines)
Lines 553-575 Link Here
553
553
554
	}
554
	}
555
555
556
	public void testUrlParsers() {
557
		String url = "https://example.com:444/folder/file.txt";
558
		assertEquals(444, BugzillaAttachmentHandler.getSslPort(url));
559
		assertEquals("example.com", BugzillaAttachmentHandler.getDomain(url));
560
		assertEquals("/folder/file.txt", BugzillaAttachmentHandler.getRequestPath(url));
561
562
		url = "http://example.com/";
563
		assertEquals(443, BugzillaAttachmentHandler.getSslPort(url));
564
		assertEquals("example.com", BugzillaAttachmentHandler.getDomain(url));
565
		assertEquals("/", BugzillaAttachmentHandler.getRequestPath(url));
566
567
		url = "https://example.com:321";
568
		assertEquals(321, BugzillaAttachmentHandler.getSslPort(url));
569
		assertEquals("example.com", BugzillaAttachmentHandler.getDomain(url));
570
		assertEquals("", BugzillaAttachmentHandler.getRequestPath(url));
571
	}
572
573
	public void testTrustAllSslProtocolSocketFactory() throws Exception {
556
	public void testTrustAllSslProtocolSocketFactory() throws Exception {
574
		SslProtocolSocketFactory factory = new SslProtocolSocketFactory();
557
		SslProtocolSocketFactory factory = new SslProtocolSocketFactory();
575
		Socket s;
558
		Socket s;
(-)src/org/eclipse/mylar/internal/trac/MylarTracPlugin.java (+5 lines)
Lines 54-59 Link Here
54
54
55
	public void start(BundleContext context) throws Exception {
55
	public void start(BundleContext context) throws Exception {
56
		super.start(context);
56
		super.start(context);
57
		
58
		// TODO the logging configuration of HttpClient should be done elsewhere
59
		System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
60
		System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "off");
61
		System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "off");
57
	}
62
	}
58
63
59
	public void stop(BundleContext context) throws Exception {
64
	public void stop(BundleContext context) throws Exception {
(-)META-INF/MANIFEST.MF (-1 lines)
Lines 10-16 Link Here
10
 org.eclipse.core.runtime,
10
 org.eclipse.core.runtime,
11
 org.eclipse.mylar.context.core,
11
 org.eclipse.mylar.context.core,
12
 org.eclipse.mylar.tasks.ui,
12
 org.eclipse.mylar.tasks.ui,
13
 org.apache.xmlrpc,
14
 org.eclipse.mylar.tasks.core
13
 org.eclipse.mylar.tasks.core
15
Eclipse-LazyStart: true
14
Eclipse-LazyStart: true
16
Export-Package: org.eclipse.mylar.internal.trac,
15
Export-Package: org.eclipse.mylar.internal.trac,
(-)src/org/eclipse/mylar/internal/trac/core/TracXmlRpcClient.java (-165 / +77 lines)
Lines 1-26 Link Here
1
package org.eclipse.mylar.internal.trac.core;
1
package org.eclipse.mylar.internal.trac.core;
2
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.OutputStream;
6
import java.net.HttpURLConnection;
3
import java.net.HttpURLConnection;
7
import java.net.URL;
4
import java.net.URL;
8
import java.util.ArrayList;
5
import java.util.ArrayList;
9
import java.util.Collections;
6
import java.util.Collections;
10
import java.util.Hashtable;
7
import java.util.HashMap;
11
import java.util.List;
8
import java.util.List;
12
import java.util.Vector;
9
import java.util.Map;
13
10
14
import org.apache.xmlrpc.XmlRpc;
15
import org.apache.xmlrpc.XmlRpcClient;
16
import org.apache.xmlrpc.XmlRpcClientException;
17
import org.apache.xmlrpc.XmlRpcException;
11
import org.apache.xmlrpc.XmlRpcException;
18
import org.apache.xmlrpc.XmlRpcTransport;
12
import org.apache.xmlrpc.client.XmlRpcClient;
19
import org.apache.xmlrpc.XmlRpcTransportFactory;
13
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
20
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.OperationCanceledException;
15
import org.eclipse.core.runtime.OperationCanceledException;
22
import org.eclipse.mylar.context.core.MylarStatusHandler;
16
import org.eclipse.mylar.context.core.MylarStatusHandler;
23
import org.eclipse.mylar.internal.trac.MylarTracPlugin;
17
import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory.TracHttpException;
24
import org.eclipse.mylar.internal.trac.model.TracComponent;
18
import org.eclipse.mylar.internal.trac.model.TracComponent;
25
import org.eclipse.mylar.internal.trac.model.TracMilestone;
19
import org.eclipse.mylar.internal.trac.model.TracMilestone;
26
import org.eclipse.mylar.internal.trac.model.TracPriority;
20
import org.eclipse.mylar.internal.trac.model.TracPriority;
Lines 52-60 Link Here
52
			return xmlrpc;
46
			return xmlrpc;
53
		}
47
		}
54
48
55
		// initialize XML-RPC library
49
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
56
		XmlRpc.setDefaultInputEncoding(ITracClient.CHARSET);
50
		config.setEncoding(ITracClient.CHARSET);
51
		config.setBasicUserName(username);
52
		config.setBasicPassword(password);
53
		config.setServerURL(getXmlRpcUrl());
54
		
55
		xmlrpc = new XmlRpcClient();
56
		xmlrpc.setConfig(config);
57
		
58
		TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc);
59
		xmlrpc.setTransportFactory(factory);
57
60
61
		return xmlrpc;
62
	}
63
64
	private URL getXmlRpcUrl() throws TracException {
58
		try {
65
		try {
59
			String location = repositoryUrl.toString();
66
			String location = repositoryUrl.toString();
60
			if (hasAuthenticationCredentials()) {
67
			if (hasAuthenticationCredentials()) {
Lines 62-90 Link Here
62
			}
69
			}
63
			location += XMLRPC_URL;
70
			location += XMLRPC_URL;
64
71
65
			URL url = new URL(location);
72
			return new URL(location);
66
			TransportFactory transport = new TransportFactory(url);
67
			xmlrpc = new XmlRpcClient(url, transport);
68
		} catch (Exception e) {
73
		} catch (Exception e) {
69
			throw new TracException(e);
74
			throw new TracException(e);
70
		}
75
		}
71
72
		return xmlrpc;
73
	}
76
	}
74
77
75
	private Object call(String method, Object... parameters) throws TracException {
78
	private Object call(String method, Object... parameters) throws TracException {
76
		getClient();
79
		getClient();
77
80
78
		Vector<Object> params = new Vector<Object>();
79
		for (Object parameter : parameters) {
80
			params.add(parameter);
81
		}
82
83
		try {
81
		try {
84
			return xmlrpc.execute(method, params);
82
			return xmlrpc.execute(method, parameters);
85
		} catch (HttpException e) {
83
		} catch (TracHttpException e) {
86
			if (e.responseCode == HttpURLConnection.HTTP_FORBIDDEN
84
			if (e.code == HttpURLConnection.HTTP_FORBIDDEN
87
					|| e.responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
85
					|| e.code == HttpURLConnection.HTTP_UNAUTHORIZED) {
88
				throw new TracLoginException();
86
				throw new TracLoginException();
89
			} else {
87
			} else {
90
				throw new TracException(e);
88
				throw new TracException(e);
Lines 96-103 Link Here
96
		}
94
		}
97
	}
95
	}
98
96
99
	private Vector multicall(Hashtable<String, Object>... calls) throws TracException {
97
	private Object[] multicall(Map<String, Object>... calls) throws TracException {
100
		Vector result = (Vector) call("system.multicall", new Object[] { calls });
98
		Object[] result = (Object[]) call("system.multicall", new Object[] { calls });
101
		for (Object item : result) {
99
		for (Object item : result) {
102
			try {
100
			try {
103
				checkForException(item);
101
				checkForException(item);
Lines 111-118 Link Here
111
	}
109
	}
112
110
113
	private void checkForException(Object result) throws NumberFormatException, XmlRpcException {
111
	private void checkForException(Object result) throws NumberFormatException, XmlRpcException {
114
		if (result instanceof Hashtable) {
112
		if (result instanceof Map) {
115
			Hashtable exceptionData = (Hashtable) result;
113
			Map exceptionData = (Map) result;
116
			if (exceptionData.containsKey("faultCode") && exceptionData.containsKey("faultString")) {
114
			if (exceptionData.containsKey("faultCode") && exceptionData.containsKey("faultString")) {
117
				throw new XmlRpcException(Integer.parseInt(exceptionData.get("faultCode").toString()),
115
				throw new XmlRpcException(Integer.parseInt(exceptionData.get("faultCode").toString()),
118
						(String) exceptionData.get("faultString"));
116
						(String) exceptionData.get("faultString"));
Lines 120-138 Link Here
120
		}
118
		}
121
	}
119
	}
122
120
123
	private Hashtable<String, Object> createMultiCall(String methodName, Object... parameters) throws TracException {
121
	private Map<String, Object> createMultiCall(String methodName, Object... parameters) throws TracException {
124
		Hashtable<String, Object> table = new Hashtable<String, Object>();
122
		Map<String, Object> table = new HashMap<String, Object>();
125
		table.put("methodName", methodName);
123
		table.put("methodName", methodName);
126
		table.put("params", parameters);
124
		table.put("params", parameters);
127
		return table;
125
		return table;
128
	}
126
	}
129
127
130
	private Object getMultiCallResult(Object item) {
128
	private Object getMultiCallResult(Object item) {
131
		return ((Vector) item).get(0);
129
		return ((Object[]) item)[0];
132
	}
130
	}
133
131
134
	public void validate() throws TracException {
132
	public void validate() throws TracException {
135
		Vector result = (Vector) call("system.listMethods");
133
		Object[] result = (Object[]) call("system.listMethods");
136
		boolean hasGetTicket = false, hasQuery = false;
134
		boolean hasGetTicket = false, hasQuery = false;
137
		for (Object methodName : result) {
135
		for (Object methodName : result) {
138
			if ("ticket.get".equals(methodName)) {
136
			if ("ticket.get".equals(methodName)) {
Lines 151-173 Link Here
151
	}
149
	}
152
150
153
	public TracTicket getTicket(int id) throws TracException {
151
	public TracTicket getTicket(int id) throws TracException {
154
		Vector result = (Vector) call("ticket.get", id);
152
		Object[] result = (Object[]) call("ticket.get", id);
155
		return parseTicket(result);
153
		return parseTicket(result);
156
	}
154
	}
157
155
158
	@SuppressWarnings("unchecked")
156
	@SuppressWarnings("unchecked")
159
	public List<TracTicket> getTickets(int[] ids) throws TracException {
157
	public List<TracTicket> getTickets(int[] ids) throws TracException {
160
		Hashtable<String, Object>[] calls = new Hashtable[ids.length];
158
		Map<String, Object>[] calls = new Map[ids.length];
161
		for (int i = 0; i < calls.length; i++) {
159
		for (int i = 0; i < calls.length; i++) {
162
			calls[i] = createMultiCall("ticket.get", ids[i]);
160
			calls[i] = createMultiCall("ticket.get", ids[i]);
163
		}
161
		}
164
162
165
		Vector result = multicall(calls);
163
		Object[] result = multicall(calls);
166
		assert result.size() == ids.length;
164
		assert result.length == ids.length;
167
165
168
		List<TracTicket> tickets = new ArrayList<TracTicket>(result.size());
166
		List<TracTicket> tickets = new ArrayList<TracTicket>(result.length);
169
		for (Object item : result) {
167
		for (Object item : result) {
170
			Vector ticketResult = (Vector) getMultiCallResult(item);
168
			Object[] ticketResult = (Object[]) getMultiCallResult(item);
171
			tickets.add(parseTicket(ticketResult));
169
			tickets.add(parseTicket(ticketResult));
172
		}
170
		}
173
171
Lines 177-201 Link Here
177
	@SuppressWarnings("unchecked")
175
	@SuppressWarnings("unchecked")
178
	public void search(TracSearch query, List<TracTicket> tickets) throws TracException {
176
	public void search(TracSearch query, List<TracTicket> tickets) throws TracException {
179
		// an empty query string is not valid, therefore prepend order
177
		// an empty query string is not valid, therefore prepend order
180
		Vector result = (Vector) call("ticket.query", "order=id" + query.toQuery());
178
		Object[] result = (Object[]) call("ticket.query", "order=id" + query.toQuery());
181
179
182
		Hashtable<String, Object>[] calls = new Hashtable[result.size()];
180
		Map<String, Object>[] calls = new Map[result.length];
183
		for (int i = 0; i < calls.length; i++) {
181
		for (int i = 0; i < calls.length; i++) {
184
			calls[i] = createMultiCall("ticket.get", result.get(i));
182
			calls[i] = createMultiCall("ticket.get", result[i]);
185
		}
183
		}
186
		result = multicall(calls);
184
		result = multicall(calls);
187
185
188
		for (Object item : result) {
186
		for (Object item : result) {
189
			Vector ticketResult = (Vector) getMultiCallResult(item);
187
			Object[] ticketResult = (Object[]) getMultiCallResult(item);
190
			tickets.add(parseTicket(ticketResult));
188
			tickets.add(parseTicket(ticketResult));
191
		}
189
		}
192
	}
190
	}
193
191
194
	private TracTicket parseTicket(Vector result) throws InvalidTicketException {
192
	private TracTicket parseTicket(Object[] ticketResult) throws InvalidTicketException {
195
		TracTicket ticket = new TracTicket((Integer) result.get(0));
193
		TracTicket ticket = new TracTicket((Integer) ticketResult[0]);
196
		ticket.setCreated((Integer) result.get(1));
194
		ticket.setCreated((Integer) ticketResult[1]);
197
		ticket.setLastChanged((Integer) result.get(2));
195
		ticket.setLastChanged((Integer) ticketResult[2]);
198
		Hashtable attributes = (Hashtable) result.get(3);
196
		Map attributes = (Map) ticketResult[3];
199
		for (Object key : attributes.keySet()) {
197
		for (Object key : attributes.keySet()) {
200
			ticket.putTracValue(key.toString(), attributes.get(key).toString());
198
			ticket.putTracValue(key.toString(), attributes.get(key).toString());
201
		}
199
		}
Lines 205-230 Link Here
205
	public synchronized void updateAttributes(IProgressMonitor monitor) throws TracException {
203
	public synchronized void updateAttributes(IProgressMonitor monitor) throws TracException {
206
		monitor.beginTask("Updating attributes", 8);
204
		monitor.beginTask("Updating attributes", 8);
207
205
208
		Vector result = getAttributes("ticket.component");
206
		Object[] result = getAttributes("ticket.component");
209
		components = new ArrayList<TracComponent>(result.size());
207
		components = new ArrayList<TracComponent>(result.length);
210
		for (Object item : result) {
208
		for (Object item : result) {
211
			components.add(parseComponent((Hashtable) getMultiCallResult(item)));
209
			components.add(parseComponent((Map) getMultiCallResult(item)));
212
		}
210
		}
213
		monitor.worked(1);
211
		monitor.worked(1);
214
		if (monitor.isCanceled())
212
		if (monitor.isCanceled())
215
			throw new OperationCanceledException();
213
			throw new OperationCanceledException();
216
214
217
		result = getAttributes("ticket.milestone");
215
		result = getAttributes("ticket.milestone");
218
		milestones = new ArrayList<TracMilestone>(result.size());
216
		milestones = new ArrayList<TracMilestone>(result.length);
219
		for (Object item : result) {
217
		for (Object item : result) {
220
			milestones.add(parseMilestone((Hashtable) getMultiCallResult(item)));
218
			milestones.add(parseMilestone((Map) getMultiCallResult(item)));
221
		}
219
		}
222
		monitor.worked(1);
220
		monitor.worked(1);
223
		if (monitor.isCanceled())
221
		if (monitor.isCanceled())
224
			throw new OperationCanceledException();
222
			throw new OperationCanceledException();
225
223
226
		List<TicketAttributeResult> attributes = getTicketAttributes("ticket.priority");
224
		List<TicketAttributeResult> attributes = getTicketAttributes("ticket.priority");
227
		priorities = new ArrayList<TracPriority>(result.size());
225
		priorities = new ArrayList<TracPriority>(result.length);
228
		for (TicketAttributeResult attribute : attributes) {
226
		for (TicketAttributeResult attribute : attributes) {
229
			priorities.add(new TracPriority(attribute.name, attribute.value));
227
			priorities.add(new TracPriority(attribute.name, attribute.value));
230
		}
228
		}
Lines 234-240 Link Here
234
			throw new OperationCanceledException();
232
			throw new OperationCanceledException();
235
233
236
		attributes = getTicketAttributes("ticket.resolution");
234
		attributes = getTicketAttributes("ticket.resolution");
237
		ticketResolutions = new ArrayList<TracTicketResolution>(result.size());
235
		ticketResolutions = new ArrayList<TracTicketResolution>(result.length);
238
		for (TicketAttributeResult attribute : attributes) {
236
		for (TicketAttributeResult attribute : attributes) {
239
			ticketResolutions.add(new TracTicketResolution(attribute.name, attribute.value));
237
			ticketResolutions.add(new TracTicketResolution(attribute.name, attribute.value));
240
		}
238
		}
Lines 244-250 Link Here
244
			throw new OperationCanceledException();
242
			throw new OperationCanceledException();
245
243
246
		attributes = getTicketAttributes("ticket.severity");
244
		attributes = getTicketAttributes("ticket.severity");
247
		severities = new ArrayList<TracSeverity>(result.size());
245
		severities = new ArrayList<TracSeverity>(result.length);
248
		for (TicketAttributeResult attribute : attributes) {
246
		for (TicketAttributeResult attribute : attributes) {
249
			severities.add(new TracSeverity(attribute.name, attribute.value));
247
			severities.add(new TracSeverity(attribute.name, attribute.value));
250
		}
248
		}
Lines 254-260 Link Here
254
			throw new OperationCanceledException();
252
			throw new OperationCanceledException();
255
253
256
		attributes = getTicketAttributes("ticket.status");
254
		attributes = getTicketAttributes("ticket.status");
257
		ticketStatus = new ArrayList<TracTicketStatus>(result.size());
255
		ticketStatus = new ArrayList<TracTicketStatus>(result.length);
258
		for (TicketAttributeResult attribute : attributes) {
256
		for (TicketAttributeResult attribute : attributes) {
259
			ticketStatus.add(new TracTicketStatus(attribute.name, attribute.value));
257
			ticketStatus.add(new TracTicketStatus(attribute.name, attribute.value));
260
		}
258
		}
Lines 264-270 Link Here
264
			throw new OperationCanceledException();
262
			throw new OperationCanceledException();
265
263
266
		attributes = getTicketAttributes("ticket.type");
264
		attributes = getTicketAttributes("ticket.type");
267
		ticketTypes = new ArrayList<TracTicketType>(result.size());
265
		ticketTypes = new ArrayList<TracTicketType>(result.length);
268
		for (TicketAttributeResult attribute : attributes) {
266
		for (TicketAttributeResult attribute : attributes) {
269
			ticketTypes.add(new TracTicketType(attribute.name, attribute.value));
267
			ticketTypes.add(new TracTicketType(attribute.name, attribute.value));
270
		}
268
		}
Lines 274-296 Link Here
274
			throw new OperationCanceledException();
272
			throw new OperationCanceledException();
275
273
276
		result = getAttributes("ticket.version");
274
		result = getAttributes("ticket.version");
277
		versions = new ArrayList<TracVersion>(result.size());
275
		versions = new ArrayList<TracVersion>(result.length);
278
		for (Object item : result) {
276
		for (Object item : result) {
279
			versions.add(parseVersion((Hashtable) getMultiCallResult(item)));
277
			versions.add(parseVersion((Map) getMultiCallResult(item)));
280
		}
278
		}
281
		monitor.worked(1);
279
		monitor.worked(1);
282
		if (monitor.isCanceled())
280
		if (monitor.isCanceled())
283
			throw new OperationCanceledException();
281
			throw new OperationCanceledException();
284
	}
282
	}
285
283
286
	private TracComponent parseComponent(Hashtable result) {
284
	private TracComponent parseComponent(Map result) {
287
		TracComponent component = new TracComponent((String) result.get("name"));
285
		TracComponent component = new TracComponent((String) result.get("name"));
288
		component.setOwner((String) result.get("owner"));
286
		component.setOwner((String) result.get("owner"));
289
		component.setDescription((String) result.get("description"));
287
		component.setDescription((String) result.get("description"));
290
		return component;
288
		return component;
291
	}
289
	}
292
290
293
	private TracMilestone parseMilestone(Hashtable result) {
291
	private TracMilestone parseMilestone(Map result) {
294
		TracMilestone milestone = new TracMilestone((String) result.get("name"));
292
		TracMilestone milestone = new TracMilestone((String) result.get("name"));
295
		milestone.setCompleted(TracUtils.parseDate((Integer) result.get("completed")));
293
		milestone.setCompleted(TracUtils.parseDate((Integer) result.get("completed")));
296
		milestone.setDue(TracUtils.parseDate((Integer) result.get("due")));
294
		milestone.setDue(TracUtils.parseDate((Integer) result.get("due")));
Lines 298-304 Link Here
298
		return milestone;
296
		return milestone;
299
	}
297
	}
300
298
301
	private TracVersion parseVersion(Hashtable result) {
299
	private TracVersion parseVersion(Map result) {
302
		TracVersion version = new TracVersion((String) result.get("name"));
300
		TracVersion version = new TracVersion((String) result.get("name"));
303
		version.setTime(TracUtils.parseDate((Integer) result.get("time")));
301
		version.setTime(TracUtils.parseDate((Integer) result.get("time")));
304
		version.setDescription((String) result.get("description"));
302
		version.setDescription((String) result.get("description"));
Lines 306-341 Link Here
306
	}
304
	}
307
305
308
	@SuppressWarnings("unchecked")
306
	@SuppressWarnings("unchecked")
309
	private Vector getAttributes(String attributeType) throws TracException {
307
	private Object[] getAttributes(String attributeType) throws TracException {
310
		Vector ids = (Vector) call(attributeType + ".getAll");
308
		Object[] ids = (Object[]) call(attributeType + ".getAll");
311
		Hashtable<String, Object>[] calls = new Hashtable[ids.size()];
309
		Map<String, Object>[] calls = new Map[ids.length];
312
		for (int i = 0; i < calls.length; i++) {
310
		for (int i = 0; i < calls.length; i++) {
313
			calls[i] = createMultiCall(attributeType + ".get", ids.get(i));
311
			calls[i] = createMultiCall(attributeType + ".get", ids[i]);
314
		}
312
		}
315
313
316
		Vector result = multicall(calls);
314
		Object[] result = multicall(calls);
317
		assert result.size() == ids.size();
315
		assert result.length == ids.length;
318
316
319
		return result;
317
		return result;
320
	}
318
	}
321
319
322
	@SuppressWarnings("unchecked")
320
	@SuppressWarnings("unchecked")
323
	private List<TicketAttributeResult> getTicketAttributes(String attributeType) throws TracException {
321
	private List<TicketAttributeResult> getTicketAttributes(String attributeType) throws TracException {
324
		Vector ids = (Vector) call(attributeType + ".getAll");
322
		Object[] ids = (Object[]) call(attributeType + ".getAll");
325
		Hashtable<String, Object>[] calls = new Hashtable[ids.size()];
323
		Map<String, Object>[] calls = new Map[ids.length];
326
		for (int i = 0; i < calls.length; i++) {
324
		for (int i = 0; i < calls.length; i++) {
327
			calls[i] = createMultiCall(attributeType + ".get", ids.get(i));
325
			calls[i] = createMultiCall(attributeType + ".get", ids[i]);
328
		}
326
		}
329
327
330
		Vector result = multicall(calls);
328
		Object[] result = multicall(calls);
331
		assert result.size() == ids.size();
329
		assert result.length == ids.length;
332
330
333
		List<TicketAttributeResult> attributes = new ArrayList<TicketAttributeResult>(result.size());
331
		List<TicketAttributeResult> attributes = new ArrayList<TicketAttributeResult>(result.length);
334
		for (int i = 0; i < calls.length; i++) {
332
		for (int i = 0; i < calls.length; i++) {
335
			try {
333
			try {
336
				TicketAttributeResult attribute = new TicketAttributeResult();
334
				TicketAttributeResult attribute = new TicketAttributeResult();
337
				attribute.name = (String) ids.get(i);
335
				attribute.name = (String) ids[i];
338
				attribute.value = Integer.parseInt((String) getMultiCallResult(result.get(i)));
336
				attribute.value = Integer.parseInt((String) getMultiCallResult(result[i]));
339
				attributes.add(attribute);
337
				attributes.add(attribute);
340
			} catch (NumberFormatException e) {
338
			} catch (NumberFormatException e) {
341
				MylarStatusHandler.log(e, "Invalid response from Trac repository for attribute type: '" + attributeType
339
				MylarStatusHandler.log(e, "Invalid response from Trac repository for attribute type: '" + attributeType
Lines 354-443 Link Here
354
352
355
	}
353
	}
356
354
357
	/**
358
	 * A custom transport factory used to establish XML-RPC connections. Uses
359
	 * the Eclipse proxy settings.
360
	 * 
361
	 * @author Steffen Pingel
362
	 */
363
	private class TransportFactory implements XmlRpcTransportFactory {
364
365
		private URL url;
366
367
		public TransportFactory(URL url) {
368
			assert url != null;
369
370
			this.url = url;
371
		}
372
373
		public XmlRpcTransport createTransport() throws XmlRpcClientException {
374
			return new XmlRpcTransport() {
375
376
				private HttpURLConnection connection;
377
378
				public void endClientRequest() throws XmlRpcClientException {
379
					assert connection != null;
380
381
					try {
382
						connection.getInputStream().close();
383
					} catch (Exception e) {
384
						throw new XmlRpcClientException("Exception closing connection", e);
385
					}
386
				}
387
388
				public InputStream sendXmlRpc(byte[] request) throws IOException, XmlRpcClientException {
389
					try {
390
						connection = MylarTracPlugin.getHttpConnection(url);
391
					} catch (Exception e) {
392
						throw new IOException(e.toString());
393
					}
394
395
					connection.setDoInput(true);
396
					connection.setDoOutput(true);
397
					connection.setUseCaches(false);
398
					connection.setAllowUserInteraction(false);
399
400
					connection.setRequestProperty("Content-Length", request.length + "");
401
					connection.setRequestProperty("Content-Type", "text/xml");
402
					if (hasAuthenticationCredentials()) {
403
						MylarTracPlugin.setAuthCredentials(connection, username, password);
404
					}
405
406
					OutputStream out = connection.getOutputStream();
407
					out.write(request);
408
					out.flush();
409
					out.close();
410
411
					connection.connect();
412
					int responseCode = connection.getResponseCode();
413
					if (responseCode != HttpURLConnection.HTTP_OK) {
414
						throw new HttpException(responseCode);
415
					}
416
417
					return connection.getInputStream();
418
				}
419
420
			};
421
		}
422
423
		public void setProperty(String key, Object value) {
424
			// ignore, this is never called by the library
425
		}
426
427
	}
428
429
	private class HttpException extends IOException {
430
431
		private static final long serialVersionUID = 7083228933121822248L;
432
433
		final int responseCode;
434
435
		public HttpException(int responseCode) {
436
			super("HTTP Error " + responseCode);
437
438
			this.responseCode = responseCode;
439
		}
440
441
	}
442
443
}
355
}
(-)src/org/eclipse/mylar/internal/trac/core/TracHttpClientTransportFactory.java (+165 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.trac.core;
13
14
import java.io.IOException;
15
import java.io.InputStream;
16
import java.lang.reflect.Field;
17
import java.net.HttpURLConnection;
18
import java.net.Proxy;
19
import java.util.zip.GZIPInputStream;
20
21
import org.apache.commons.httpclient.HttpClient;
22
import org.apache.commons.httpclient.HttpVersion;
23
import org.apache.commons.httpclient.methods.PostMethod;
24
import org.apache.xmlrpc.XmlRpcException;
25
import org.apache.xmlrpc.XmlRpcRequest;
26
import org.apache.xmlrpc.client.XmlRpcClient;
27
import org.apache.xmlrpc.client.XmlRpcCommonsTransport;
28
import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
29
import org.apache.xmlrpc.client.XmlRpcTransport;
30
import org.apache.xmlrpc.client.XmlRpcTransportFactoryImpl;
31
import org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil;
32
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
33
34
/**
35
 * A custom transport factory used to establish XML-RPC connections. Uses the
36
 * Mylar proxy settings.
37
 * 
38
 * @author Steffen Pingel
39
 */
40
public class TracHttpClientTransportFactory extends XmlRpcTransportFactoryImpl {
41
42
	public static class TracHttpException extends XmlRpcException {
43
44
		private static final long serialVersionUID = 9032521978140685830L;
45
46
		public TracHttpException(int responseCode) {
47
			super(responseCode, "HTTP Error " + responseCode);
48
		}
49
50
	}
51
52
	/**
53
	 * A transport that uses the Apache HttpClient library.
54
	 */
55
	public static class TracHttpClientTransport extends XmlRpcCommonsTransport {
56
57
		public TracHttpClientTransport(XmlRpcClient client) {
58
			super(client);
59
60
			XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) client.getConfig();
61
			// this needs to be set to avoid exceptions
62
			getHttpClient().getParams().setAuthenticationPreemptive(config.getBasicUserName() != null);
63
		}
64
65
		public HttpClient getHttpClient() {
66
			return (HttpClient) getValue("client");
67
		}
68
69
		@Override
70
		protected InputStream getInputStream() throws XmlRpcException {
71
			int responseCode = getMethod().getStatusCode();
72
			if (responseCode != HttpURLConnection.HTTP_OK) {
73
				throw new TracHttpException(responseCode);
74
			}
75
76
			return super.getInputStream();
77
		}
78
79
		public PostMethod getMethod() {
80
			return (PostMethod) getValue("method");
81
		}
82
83
		public void setMethod(PostMethod method) {
84
			setValue("method", method);
85
		}
86
87
		private Object getValue(String name) {
88
			try {
89
				Field field = XmlRpcCommonsTransport.class.getDeclaredField(name);
90
				field.setAccessible(true);
91
				return field.get(this);
92
			} catch (Throwable t) {
93
				throw new RuntimeException("Internal error accessing HttpClient", t);
94
			}
95
		}
96
97
		private void setValue(String name, Object value) {
98
			try {
99
				Field field = XmlRpcCommonsTransport.class.getDeclaredField(name);
100
				field.setAccessible(true);
101
				field.set(this, value);
102
			} catch (Throwable t) {
103
				throw new RuntimeException("Internal error accessing HttpClient", t);
104
			}
105
		}
106
107
		/**
108
		 * Based on the implementation of XmlRpcCommonsTransport and its super classes.
109
		 */
110
		@Override
111
		public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
112
			XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) pRequest.getConfig();
113
			
114
			String url = config.getServerURL().toString();
115
			Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
116
			UrlConnectionUtil.setupHttpClient(getHttpClient(), proxySettings, url);
117
			
118
			PostMethod method = new PostMethod(UrlConnectionUtil.getRequestPath(url));
119
	        
120
	        if (config.getConnectionTimeout() != 0)
121
	            getHttpClient().getHttpConnectionManager().getParams().setConnectionTimeout(config.getConnectionTimeout());
122
	        
123
	        if (config.getReplyTimeout() != 0)
124
	        	getHttpClient().getHttpConnectionManager().getParams().setSoTimeout(config.getConnectionTimeout());
125
	        
126
			method.getParams().setVersion(HttpVersion.HTTP_1_1);
127
128
			setMethod(method);
129
			
130
			initHttpHeaders(pRequest);
131
			
132
			boolean closed = false;
133
			try {
134
				RequestWriter writer = newRequestWriter(pRequest);
135
				writeRequest(writer);
136
				InputStream istream = getInputStream();
137
				if (isResponseGzipCompressed(config)) {
138
					istream = new GZIPInputStream(istream);
139
				}
140
				Object result = readResponse(config, istream);
141
				closed = true;
142
				close();
143
				return result;
144
			} catch (IOException e) {
145
				throw new XmlRpcException("Failed to read servers response: "
146
						+ e.getMessage(), e);
147
			} finally {
148
				if (!closed) { try { close(); } catch (Throwable ignore) {} }
149
			}
150
		}
151
152
	}
153
154
	private final TracHttpClientTransport transport;
155
156
	public TracHttpClientTransportFactory(XmlRpcClient client) {
157
		super(client);
158
159
		transport = new TracHttpClientTransport(client);
160
	}
161
162
	public XmlRpcTransport getTransport() {
163
		return transport;
164
	}
165
}
(-)src/org/eclipse/mylar/internal/tasks/core/UrlConnectionUtil.java (+76 lines)
Lines 12-17 Link Here
12
package org.eclipse.mylar.internal.tasks.core;
12
package org.eclipse.mylar.internal.tasks.core;
13
13
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.net.InetSocketAddress;
15
import java.net.Proxy;
16
import java.net.Proxy;
16
import java.net.URL;
17
import java.net.URL;
17
import java.net.URLConnection;
18
import java.net.URLConnection;
Lines 21-31 Link Here
21
import javax.net.ssl.HttpsURLConnection;
22
import javax.net.ssl.HttpsURLConnection;
22
import javax.net.ssl.SSLContext;
23
import javax.net.ssl.SSLContext;
23
24
25
import org.apache.commons.httpclient.HttpClient;
26
import org.apache.commons.httpclient.protocol.Protocol;
27
24
/**
28
/**
25
 * @author Mik Kersten
29
 * @author Mik Kersten
26
 */
30
 */
27
public class UrlConnectionUtil {
31
public class UrlConnectionUtil {
28
32
33
	private static final int HTTP_PORT = 80;
34
	private static final int HTTPS_PORT = 443;
35
29
	/**
36
	/**
30
	 * @param url
37
	 * @param url
31
	 * @param proxy can be null
38
	 * @param proxy can be null
Lines 45-48 Link Here
45
		return connection;
52
		return connection;
46
	}
53
	}
47
54
55
	/**
56
	 * public for testing
57
	 */
58
	public static boolean repositoryUsesHttps(String repositoryUrl) {
59
		return repositoryUrl.matches("https.*");
60
	}
61
62
	public static int getPort(String repositoryUrl) {
63
		int colonSlashSlash = repositoryUrl.indexOf("://");
64
		int colonPort = repositoryUrl.indexOf(':', colonSlashSlash + 1);
65
		if (colonPort < 0)
66
			return repositoryUsesHttps(repositoryUrl) ? HTTPS_PORT : HTTP_PORT;
67
	
68
		int requestPath = repositoryUrl.indexOf('/', colonPort + 1);
69
		
70
		int end;
71
		if (requestPath < 0)
72
			end = repositoryUrl.length();
73
		else
74
			end = requestPath;
75
		
76
		return Integer.parseInt(repositoryUrl.substring(colonPort + 1, end));
77
	}
78
79
	public static String getDomain(String repositoryUrl) {
80
		int colonSlashSlash = repositoryUrl.indexOf("://");
81
		
82
		int colonPort = repositoryUrl.indexOf(':', colonSlashSlash + 1);
83
		int requestPath = repositoryUrl.indexOf('/', colonSlashSlash + 3);
84
		
85
		int substringEnd;
86
		
87
		// minimum positive, or string length
88
		if (colonPort > 0 && requestPath > 0)
89
			substringEnd = Math.min(colonPort, requestPath);
90
		else if (colonPort > 0)
91
			substringEnd = colonPort;
92
		else if (requestPath > 0)
93
			substringEnd = requestPath;
94
		else
95
			substringEnd = repositoryUrl.length(); 
96
		
97
		return repositoryUrl.substring(colonSlashSlash + 3, substringEnd);
98
	}
99
100
	public static String getRequestPath(String repositoryUrl) {
101
		int colonSlashSlash = repositoryUrl.indexOf("://");
102
		int requestPath = repositoryUrl.indexOf('/', colonSlashSlash + 3);
103
		
104
		if (requestPath < 0)
105
			return "";
106
		else
107
			return repositoryUrl.substring(requestPath);
108
	}
109
110
	public static void setupHttpClient(HttpClient client, Proxy proxySettings, String repositoryUrl) {
111
		if (proxySettings != null && proxySettings.address() instanceof InetSocketAddress) {
112
			InetSocketAddress address = (InetSocketAddress)proxySettings.address();
113
			client.getHostConfiguration().setProxy(address.getHostName(), address.getPort());
114
		}
115
		
116
		if (UrlConnectionUtil.repositoryUsesHttps(repositoryUrl)) {
117
			Protocol acceptAllSsl = new Protocol("https", new SslProtocolSocketFactory(), UrlConnectionUtil.getPort(repositoryUrl));
118
			client.getHostConfiguration().setHost(UrlConnectionUtil.getDomain(repositoryUrl), UrlConnectionUtil.getPort(repositoryUrl), acceptAllSsl);
119
		} else {
120
			client.getHostConfiguration().setHost(UrlConnectionUtil.getDomain(repositoryUrl), UrlConnectionUtil.getPort(repositoryUrl));
121
		}
122
	}
123
	
48
}
124
}
(-).refactorings/2006/7/30/refactorings.history (+4 lines)
Added Link Here
1
<?xml version="1.0" encoding="utf-8"?>
2
<session version="1.0">
3
<refactoring comment="Rename method 'org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil.getSslPort(...)' to 'getPort'&#10;- Original element: 'org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil.getSslPort(...)'&#10;- Renamed element: 'org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil.getPort(...)'&#10;- Update references to refactored element" delegate="false" deprecate="true" description="Rename method 'getSslPort'" flags="589830" id="org.eclipse.jdt.ui.rename.method" input="/src&lt;org.eclipse.mylar.internal.tasks.core{UrlConnectionUtil.java[UrlConnectionUtil~getSslPort~QString;" name="getPort" references="true" stamp="1154018801211" version="1.0"/>
4
</session>
(-).refactorings/2006/7/30/refactorings.index (+1 lines)
Added Link Here
1
1154018801211	Rename method 'getSslPort'
(-)src/org/eclipse/mylar/internal/bugzilla/core/BugzillaAttachmentHandler.java (-73 / +3 lines)
Lines 20-26 Link Here
20
import java.io.InputStream;
20
import java.io.InputStream;
21
import java.io.InputStreamReader;
21
import java.io.InputStreamReader;
22
import java.io.OutputStream;
22
import java.io.OutputStream;
23
import java.net.InetSocketAddress;
24
import java.net.Proxy;
23
import java.net.Proxy;
25
import java.net.URL;
24
import java.net.URL;
26
import java.net.URLConnection;
25
import java.net.URLConnection;
Lines 37-47 Link Here
37
import org.apache.commons.httpclient.methods.multipart.PartBase;
36
import org.apache.commons.httpclient.methods.multipart.PartBase;
38
import org.apache.commons.httpclient.methods.multipart.StringPart;
37
import org.apache.commons.httpclient.methods.multipart.StringPart;
39
import org.apache.commons.httpclient.params.HttpMethodParams;
38
import org.apache.commons.httpclient.params.HttpMethodParams;
40
import org.apache.commons.httpclient.protocol.Protocol;
41
import org.eclipse.core.runtime.CoreException;
39
import org.eclipse.core.runtime.CoreException;
42
import org.eclipse.core.runtime.IStatus;
40
import org.eclipse.core.runtime.IStatus;
43
import org.eclipse.core.runtime.Status;
41
import org.eclipse.core.runtime.Status;
44
import org.eclipse.mylar.internal.tasks.core.SslProtocolSocketFactory;
45
import org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil;
42
import org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil;
46
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
43
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
47
import org.eclipse.mylar.tasks.core.IAttachmentHandler;
44
import org.eclipse.mylar.tasks.core.IAttachmentHandler;
Lines 120-140 Link Here
120
		
117
		
121
//		Protocol.registerProtocol("https", new Protocol("https", new TrustAllSslProtocolSocketFactory(), 443));
118
//		Protocol.registerProtocol("https", new Protocol("https", new TrustAllSslProtocolSocketFactory(), 443));
122
		HttpClient client = new HttpClient();
119
		HttpClient client = new HttpClient();
123
		if (proxySettings != null && proxySettings.address() instanceof InetSocketAddress) {
120
		UrlConnectionUtil.setupHttpClient(client, proxySettings, repositoryUrl);
124
			InetSocketAddress address = (InetSocketAddress)proxySettings.address();
121
		PostMethod postMethod = new PostMethod(UrlConnectionUtil.getRequestPath(repositoryUrl) + POST_ARGS_ATTACHMENT_UPLOAD);
125
			client.getHostConfiguration().setProxy(address.getHostName(), address.getPort());
122
126
		}
127
		
128
		PostMethod postMethod;
129
		if (repositoryUsesHttps(repositoryUrl)) {
130
			Protocol acceptAllSsl = new Protocol("https", new SslProtocolSocketFactory(), getSslPort(repositoryUrl));
131
			client.getHostConfiguration().setHost(getDomain(repositoryUrl), getSslPort(repositoryUrl), acceptAllSsl);
132
			
133
			postMethod = new PostMethod(getRequestPath(repositoryUrl) + POST_ARGS_ATTACHMENT_UPLOAD);
134
		}
135
		else {
136
			postMethod = new PostMethod(repositoryUrl + POST_ARGS_ATTACHMENT_UPLOAD);
137
		}
138
		// My understanding is that this option causes the client to first check
123
		// My understanding is that this option causes the client to first check
139
		// with the server to see if it will in fact recieve the post before
124
		// with the server to see if it will in fact recieve the post before
140
		// actually sending the contents.
125
		// actually sending the contents.
Lines 189-249 Link Here
189
		return uploadResult;
174
		return uploadResult;
190
	}
175
	}
191
	
176
	
192
	/**
193
	 * public for testing
194
	 */
195
	public static boolean repositoryUsesHttps(String repositoryUrl) {
196
		return repositoryUrl.matches("https.*");
197
	}
198
199
	public static int getSslPort(String repositoryUrl) {
200
		int colonSlashSlash = repositoryUrl.indexOf("://");
201
		int colonPort = repositoryUrl.indexOf(':', colonSlashSlash + 1);
202
		if (colonPort < 0)
203
			return 443;
204
205
		int requestPath = repositoryUrl.indexOf('/', colonPort + 1);
206
		
207
		int end;
208
		if (requestPath < 0)
209
			end = repositoryUrl.length();
210
		else
211
			end = requestPath;
212
		
213
		return Integer.parseInt(repositoryUrl.substring(colonPort + 1, end));
214
	}
215
216
	public static String getDomain(String repositoryUrl) {
217
		int colonSlashSlash = repositoryUrl.indexOf("://");
218
		
219
		int colonPort = repositoryUrl.indexOf(':', colonSlashSlash + 1);
220
		int requestPath = repositoryUrl.indexOf('/', colonSlashSlash + 3);
221
		
222
		int substringEnd;
223
		
224
		// minimum positive, or string length
225
		if (colonPort > 0 && requestPath > 0)
226
			substringEnd = Math.min(colonPort, requestPath);
227
		else if (colonPort > 0)
228
			substringEnd = colonPort;
229
		else if (requestPath > 0)
230
			substringEnd = requestPath;
231
		else
232
			substringEnd = repositoryUrl.length(); 
233
		
234
		return repositoryUrl.substring(colonSlashSlash + 3, substringEnd);
235
	}
236
	
237
	public static String getRequestPath(String repositoryUrl) {
238
		int colonSlashSlash = repositoryUrl.indexOf("://");
239
		int requestPath = repositoryUrl.indexOf('/', colonSlashSlash + 3);
240
		
241
		if (requestPath < 0)
242
			return "";
243
		else
244
			return repositoryUrl.substring(requestPath);
245
	}
246
247
	public boolean uploadAttachment(LocalAttachment attachment, String uname, String password, Proxy proxySettings) throws IOException {
177
	public boolean uploadAttachment(LocalAttachment attachment, String uname, String password, Proxy proxySettings) throws IOException {
248
		
178
		
249
		File file = new File(attachment.getFilePath());
179
		File file = new File(attachment.getFilePath());
(-).refactorings/2006/7/30/refactorings.index (+1 lines)
Added Link Here
1
1154018787194	Move members
(-).refactorings/2006/7/30/refactorings.history (+4 lines)
Added Link Here
1
<?xml version="1.0" encoding="utf-8"?>
2
<session version="1.0">
3
<refactoring comment="Move 4 members to 'org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil'&#10;- Original elements:&#10;     org.eclipse.mylar.internal.bugzilla.core.BugzillaAttachmentHandler.getSslPort(...)&#10;     org.eclipse.mylar.internal.bugzilla.core.BugzillaAttachmentHandler.getRequestPath(...)&#10;     org.eclipse.mylar.internal.bugzilla.core.BugzillaAttachmentHandler.repositoryUsesHttps(...)&#10;     org.eclipse.mylar.internal.bugzilla.core.BugzillaAttachmentHandler.getDomain(...)&#10;- Destination type: 'org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil'" delegate="false" deprecate="true" description="Move members" element1="/src&lt;org.eclipse.mylar.internal.bugzilla.core{BugzillaAttachmentHandler.java[BugzillaAttachmentHandler~getSslPort~QString;" element2="/src&lt;org.eclipse.mylar.internal.bugzilla.core{BugzillaAttachmentHandler.java[BugzillaAttachmentHandler~getRequestPath~QString;" element3="/src&lt;org.eclipse.mylar.internal.bugzilla.core{BugzillaAttachmentHandler.java[BugzillaAttachmentHandler~repositoryUsesHttps~QString;" element4="/src&lt;org.eclipse.mylar.internal.bugzilla.core{BugzillaAttachmentHandler.java[BugzillaAttachmentHandler~getDomain~QString;" flags="589830" id="org.eclipse.jdt.ui.move.static" input="/src&lt;org.eclipse.mylar.internal.tasks.core{UrlConnectionUtil.java[UrlConnectionUtil" stamp="1154018787194" version="1.0"/>
4
</session>
(-)src/org/eclipse/mylar/trac/tests/TracXmlRpcClientTest.java (+24 lines)
Lines 12-23 Link Here
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Arrays;
16
import java.util.Comparator;
17
import java.util.Date;
15
18
19
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.mylar.internal.trac.core.ITracClient;
20
import org.eclipse.mylar.internal.trac.core.ITracClient;
17
import org.eclipse.mylar.internal.trac.core.TracLoginException;
21
import org.eclipse.mylar.internal.trac.core.TracLoginException;
18
import org.eclipse.mylar.internal.trac.core.TracRemoteException;
22
import org.eclipse.mylar.internal.trac.core.TracRemoteException;
19
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
23
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
20
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
24
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
25
import org.eclipse.mylar.internal.trac.model.TracVersion;
21
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
26
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
22
27
23
/**
28
/**
Lines 51-54 Link Here
51
		}
56
		}
52
	}
57
	}
53
58
59
	public void testUpdateAttributes() throws Exception {
60
		factory.connectRepository1();
61
		assertNull(factory.repository.getMilestones());
62
		factory.repository.updateAttributes(new NullProgressMonitor());
63
		TracVersion[] versions = factory.repository.getVersions();
64
		assertEquals(2, versions.length);
65
		Arrays.sort(versions, new Comparator<TracVersion>() {
66
			public int compare(TracVersion o1, TracVersion o2) {
67
				return o1.getName().compareTo(o2.getName());
68
			}
69
		});
70
		assertEquals("v1", versions[0].getName());
71
		assertEquals("description1", versions[0].getDescription());
72
		assertEquals(new Date(86400 * 1000), versions[0].getTime());
73
		assertEquals("v2", versions[1].getName());
74
		assertEquals("description2", versions[1].getDescription());
75
		assertEquals(new Date(86400 * 2 * 1000), versions[1].getTime());
76
	}
77
54
}
78
}
(-)src/org/eclipse/mylar/trac/tests/TracXmlRpcTest.java (-109 / +91 lines)
Lines 13-33 Link Here
13
13
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.net.URL;
15
import java.net.URL;
16
import java.util.ArrayList;
16
import java.util.Date;
17
import java.util.Date;
17
import java.util.Hashtable;
18
import java.util.Hashtable;
19
import java.util.List;
20
import java.util.Map;
18
import java.util.Random;
21
import java.util.Random;
19
import java.util.Vector;
20
21
import javax.net.ssl.HttpsURLConnection;
22
import javax.net.ssl.SSLContext;
23
22
24
import junit.framework.TestCase;
23
import junit.framework.TestCase;
25
24
26
import org.apache.xmlrpc.DefaultXmlRpcTransportFactory;
27
import org.apache.xmlrpc.XmlRpc;
28
import org.apache.xmlrpc.XmlRpcClient;
29
import org.apache.xmlrpc.XmlRpcException;
25
import org.apache.xmlrpc.XmlRpcException;
30
import org.eclipse.mylar.internal.trac.TrustAll;
26
import org.apache.xmlrpc.client.XmlRpcClient;
27
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
28
import org.eclipse.mylar.internal.trac.core.TracHttpClientTransportFactory;
31
29
32
/**
30
/**
33
 * Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC
31
 * Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC
Lines 55-87 Link Here
55
53
56
		random = new Random();
54
		random = new Random();
57
55
58
		XmlRpc.setDefaultInputEncoding("UTF-8");
59
60
		createConnection(new URL(Constants.TEST_REPOSITORY1_URL + XMLRPC_URL),
56
		createConnection(new URL(Constants.TEST_REPOSITORY1_URL + XMLRPC_URL),
61
				Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
57
				Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
62
	}
58
	}
63
59
64
	@SuppressWarnings("deprecation")
65
	private void createConnection(URL url, String username, String password) throws Exception {
60
	private void createConnection(URL url, String username, String password) throws Exception {
66
		if (url.toString().startsWith("https")) {
61
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
67
			DefaultXmlRpcTransportFactory transport = new DefaultXmlRpcTransportFactory(url);
62
		config.setEncoding("UTF-8");
68
			transport.setBasicAuthentication(username, password);
63
		config.setBasicUserName(username);
69
64
		config.setBasicPassword(password);
70
			SSLContext ctx = SSLContext.getInstance("TLS");
65
		config.setServerURL(url);
71
66
		
72
			javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[] { new TrustAll() };
67
		xmlrpc = new XmlRpcClient();
73
			ctx.init(null, tm, null);
68
		xmlrpc.setConfig(config);
74
			HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
69
		
75
70
		TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc);
76
			xmlrpc = new XmlRpcClient(url, transport);
71
		xmlrpc.setTransportFactory(factory);
77
		} else {
78
			xmlrpc = new XmlRpcClient(url);
79
80
			// the XML-RPC library is kind of broken: setting authentication
81
			// credentials for
82
			// http connections is only possible through a deprecated method
83
			xmlrpc.setBasicAuthentication(username, password);
84
		}
85
72
86
		this.username = username;
73
		this.username = username;
87
		// this.password = password;
74
		// this.password = password;
Lines 92-112 Link Here
92
	}
79
	}
93
80
94
	private Object call(String method, Object... parameters) throws XmlRpcException, IOException {
81
	private Object call(String method, Object... parameters) throws XmlRpcException, IOException {
95
		Vector<Object> params = new Vector<Object>();
82
		Object result = xmlrpc.execute(method, parameters);
96
		for (Object parameter : parameters) {
97
			params.add(parameter);
98
		}
99
100
		Object result = xmlrpc.execute(method, params);
101
		if (result instanceof XmlRpcException) {
83
		if (result instanceof XmlRpcException) {
102
			throw (XmlRpcException) result;
84
			throw (XmlRpcException) result;
103
		}
85
		}
104
		return result;
86
		return result;
105
	}
87
	}
106
88
107
	public Hashtable<String, Object> createMultiCall(String methodName, Object... parameters) throws XmlRpcException,
89
	public Map<String, Object> createMultiCall(String methodName, Object... parameters) throws XmlRpcException,
108
			IOException {
90
			IOException {
109
		Hashtable<String, Object> table = new Hashtable<String, Object>();
91
		Map<String, Object> table = new Hashtable<String, Object>();
110
		table.put("methodName", methodName);
92
		table.put("methodName", methodName);
111
		table.put("params", parameters);
93
		table.put("params", parameters);
112
		return table;
94
		return table;
Lines 120-126 Link Here
120
102
121
		call(module + ".create", "foo", "bar");
103
		call(module + ".create", "foo", "bar");
122
104
123
		assertHasValue(((Vector) call(module + ".getAll")).toArray(), "foo");
105
		assertHasValue((Object[]) call(module + ".getAll"), "foo");
124
		assertEquals("bar", (String) (call(module + ".get", "foo")));
106
		assertEquals("bar", (String) (call(module + ".get", "foo")));
125
107
126
		call(module + ".update", "foo", "baz");
108
		call(module + ".update", "foo", "baz");
Lines 151-165 Link Here
151
		} catch (XmlRpcException e) {
133
		} catch (XmlRpcException e) {
152
		}
134
		}
153
135
154
		Hashtable<String, Object> attributes = new Hashtable<String, Object>();
136
		Map<String, Object> attributes = new Hashtable<String, Object>();
155
		for (int i = 0; i < fields.length; i += 2) {
137
		for (int i = 0; i < fields.length; i += 2) {
156
			attributes.put((String) fields[i], createValue(fields[i], fields[i + 1]));
138
			attributes.put((String) fields[i], createValue(fields[i], fields[i + 1]));
157
		}
139
		}
158
140
159
		call(module + ".create", "foo", attributes);
141
		call(module + ".create", "foo", attributes);
160
142
161
		assertHasValue(((Vector) call(module + ".getAll")).toArray(), "foo");
143
		assertHasValue((Object[]) call(module + ".getAll"), "foo");
162
		Hashtable values = (Hashtable) call(module + ".get", "foo");
144
		Map values = (Map) call(module + ".get", "foo");
163
		for (String attribute : attributes.keySet()) {
145
		for (String attribute : attributes.keySet()) {
164
			assertEquals(attributes.get(attribute), values.get(attribute));
146
			assertEquals(attributes.get(attribute), values.get(attribute));
165
		}
147
		}
Lines 169-175 Link Here
169
		}
151
		}
170
152
171
		call(module + ".update", "foo", attributes);
153
		call(module + ".update", "foo", attributes);
172
		values = (Hashtable) call(module + ".get", "foo");
154
		values = (Map) call(module + ".get", "foo");
173
		for (String attribute : attributes.keySet()) {
155
		for (String attribute : attributes.keySet()) {
174
			assertEquals(attributes.get(attribute), values.get(attribute));
156
			assertEquals(attributes.get(attribute), values.get(attribute));
175
		}
157
		}
Lines 186-199 Link Here
186
		int due = (int) (System.currentTimeMillis() / 1000) + 1000;
168
		int due = (int) (System.currentTimeMillis() / 1000) + 1000;
187
		int completed = (int) (System.currentTimeMillis() / 1000);
169
		int completed = (int) (System.currentTimeMillis() / 1000);
188
170
189
		Hashtable<String, Object> attributes = new Hashtable<String, Object>();
171
		Map<String, Object> attributes = new Hashtable<String, Object>();
190
		attributes.put("description", "description");
172
		attributes.put("description", "description");
191
		attributes.put("due", due);
173
		attributes.put("due", due);
192
		attributes.put("completed", completed);
174
		attributes.put("completed", completed);
193
175
194
		call("ticket.milestone.create", "foo", attributes);
176
		call("ticket.milestone.create", "foo", attributes);
195
177
196
		Hashtable values = (Hashtable) call("ticket.milestone.get", "foo");
178
		Map values = (Map) call("ticket.milestone.get", "foo");
197
		assertEquals(new Integer(due), (Integer) values.get("due"));
179
		assertEquals(new Integer(due), (Integer) values.get("due"));
198
		assertEquals(new Integer(completed), (Integer) values.get("completed"));
180
		assertEquals(new Integer(completed), (Integer) values.get("completed"));
199
181
Lines 209-236 Link Here
209
		fail("Could not find expected value: " + value);
191
		fail("Could not find expected value: " + value);
210
	}
192
	}
211
193
212
	private void assertTicketHasAttributes(Hashtable<String, Object> attributes, int id, Vector ticket) {
194
	private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket) {
213
		assertTicketHasAttributes(attributes, id, ticket, true);
195
		assertTicketHasAttributes(attributes, id, ticket, true);
214
	}
196
	}
215
197
216
	private void assertTicketHasAttributes(Hashtable<String, Object> attributes, int id, Vector ticket,
198
	private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket,
217
			boolean newTicket) {
199
			boolean newTicket) {
218
		assertEquals(id, ticket.get(0));
200
		assertEquals(id, ticket[0]);
219
		assertTrue(ticket.get(1) instanceof Integer); // time created
201
		assertTrue(ticket[1] instanceof Integer); // time created
220
		// time changed
202
		// time changed
221
		if (newTicket) {
203
		if (newTicket) {
222
			assertEquals(ticket.get(1), ticket.get(2));
204
			assertEquals(ticket[1], ticket[2]);
223
		} else {
205
		} else {
224
			assertTrue((Integer) ticket.get(2) >= (Integer) ticket.get(1));
206
			assertTrue((Integer) ticket[2] >= (Integer) ticket[1]);
225
		}
207
		}
226
		Hashtable values = (Hashtable) ticket.get(3);
208
		Map values = (Map) ticket[3];
227
		for (String attribute : attributes.keySet()) {
209
		for (String attribute : attributes.keySet()) {
228
			assertEquals(attributes.get(attribute), values.get(attribute));
210
			assertEquals(attributes.get(attribute), values.get(attribute));
229
		}
211
		}
230
	}
212
	}
231
213
232
	public void testGetTicket() throws XmlRpcException, IOException {
214
	public void testGetTicket() throws XmlRpcException, IOException {
233
		Hashtable<String, Object> attributes = new Hashtable<String, Object>();
215
		Map<String, Object> attributes = new Hashtable<String, Object>();
234
		attributes.put("type", "task");
216
		attributes.put("type", "task");
235
		attributes.put("status", "closed");
217
		attributes.put("status", "closed");
236
		int id = (Integer) call("ticket.create", "summary", "description", attributes);
218
		int id = (Integer) call("ticket.create", "summary", "description", attributes);
Lines 238-244 Link Here
238
		attributes.put("summary", "summary");
220
		attributes.put("summary", "summary");
239
		attributes.put("description", "description");
221
		attributes.put("description", "description");
240
222
241
		Vector ticket = (Vector) call("ticket.get", id);
223
		Object[] ticket = (Object[]) call("ticket.get", id);
242
		assertTicketHasAttributes(attributes, id, ticket);
224
		assertTicketHasAttributes(attributes, id, ticket);
243
225
244
		call("ticket.delete", id);
226
		call("ticket.delete", id);
Lines 252-258 Link Here
252
		}
234
		}
253
235
254
		try {
236
		try {
255
			Vector ticket = (Vector) call("ticket.get", Integer.MAX_VALUE);
237
			List ticket = (List) call("ticket.get", Integer.MAX_VALUE);
256
			fail("Expected XmlRpcException, got ticket instead: " + ticket);
238
			fail("Expected XmlRpcException, got ticket instead: " + ticket);
257
		} catch (XmlRpcException e) {
239
		} catch (XmlRpcException e) {
258
			// ignore
240
			// ignore
Lines 260-272 Link Here
260
	}
242
	}
261
243
262
	public void testGetTicketUmlaute() throws XmlRpcException, IOException {
244
	public void testGetTicketUmlaute() throws XmlRpcException, IOException {
263
		Hashtable<String, Object> attributes = new Hashtable<String, Object>();
245
		Map<String, Object> attributes = new Hashtable<String, Object>();
264
		int id = (Integer) call("ticket.create", "summaryäÖÜ", "ßßß", attributes);
246
		int id = (Integer) call("ticket.create", "summaryäÖÜ", "ßßß", attributes);
265
247
266
		attributes.put("summary", "summaryäÖÜ");
248
		attributes.put("summary", "summaryäÖÜ");
267
		attributes.put("description", "ßßß");
249
		attributes.put("description", "ßßß");
268
250
269
		Vector ticket = (Vector) call("ticket.get", id);
251
		Object[] ticket = (Object[]) call("ticket.get", id);
270
		assertTicketHasAttributes(attributes, id, ticket);
252
		assertTicketHasAttributes(attributes, id, ticket);
271
253
272
		call("ticket.delete", id);
254
		call("ticket.delete", id);
Lines 275-288 Link Here
275
	public void testUpdateTicket() throws XmlRpcException, IOException {
257
	public void testUpdateTicket() throws XmlRpcException, IOException {
276
		int id = (Integer) call("ticket.create", "summary", "description", new Hashtable());
258
		int id = (Integer) call("ticket.create", "summary", "description", new Hashtable());
277
259
278
		Hashtable<String, Object> attributes = new Hashtable<String, Object>();
260
		Map<String, Object> attributes = new Hashtable<String, Object>();
279
		attributes.put("summary", "changed");
261
		attributes.put("summary", "changed");
280
		call("ticket.update", id, "my comment", attributes);
262
		call("ticket.update", id, "my comment", attributes);
281
263
282
		attributes.put("description", "description");
264
		attributes.put("description", "description");
283
265
284
		Vector ticket = (Vector) call("ticket.get", id);
266
		Object[] ticket = (Object[]) call("ticket.get", id);
285
		Hashtable values = (Hashtable) ticket.get(3);
267
		Map values = (Map) ticket[3];
286
		for (String attribute : attributes.keySet()) {
268
		for (String attribute : attributes.keySet()) {
287
			assertEquals(attributes.get(attribute), values.get(attribute));
269
			assertEquals(attributes.get(attribute), values.get(attribute));
288
		}
270
		}
Lines 291-297 Link Here
291
	}
273
	}
292
274
293
	public void testTicketCustomFields() throws XmlRpcException, IOException {
275
	public void testTicketCustomFields() throws XmlRpcException, IOException {
294
		Hashtable<String, Object> attributes = new Hashtable<String, Object>();
276
		Map<String, Object> attributes = new Hashtable<String, Object>();
295
		attributes.put("custom_text_field", "myvalue");
277
		attributes.put("custom_text_field", "myvalue");
296
		int id = (Integer) call("ticket.create", "summary", "description", attributes);
278
		int id = (Integer) call("ticket.create", "summary", "description", attributes);
297
279
Lines 301-307 Link Here
301
		attributes.put("custom_radio_field", "baz");
283
		attributes.put("custom_radio_field", "baz");
302
		attributes.put("custom_textarea_field", "default text");
284
		attributes.put("custom_textarea_field", "default text");
303
285
304
		Vector ticket = (Vector) call("ticket.get", id);
286
		Object[] ticket = (Object[]) call("ticket.get", id);
305
		assertTicketHasAttributes(attributes, id, ticket);
287
		assertTicketHasAttributes(attributes, id, ticket);
306
288
307
		attributes.put("custom_text_field", "myvalue2");
289
		attributes.put("custom_text_field", "myvalue2");
Lines 312-318 Link Here
312
294
313
		call("ticket.update", id, "my comment", attributes);
295
		call("ticket.update", id, "my comment", attributes);
314
296
315
		ticket = (Vector) call("ticket.get", id);
297
		ticket = (Object[]) call("ticket.get", id);
316
		assertTicketHasAttributes(attributes, id, ticket, false);
298
		assertTicketHasAttributes(attributes, id, ticket, false);
317
299
318
		call("ticket.delete", id);
300
		call("ticket.delete", id);
Lines 321-337 Link Here
321
	public void testGetChangeLog() throws XmlRpcException, IOException {
303
	public void testGetChangeLog() throws XmlRpcException, IOException {
322
		int id = (Integer) call("ticket.create", "summary", "description", new Hashtable());
304
		int id = (Integer) call("ticket.create", "summary", "description", new Hashtable());
323
305
324
		Hashtable<String, Object> attributes = new Hashtable<String, Object>();
306
		Map<String, Object> attributes = new Hashtable<String, Object>();
325
		attributes.put("summary", "changed");
307
		attributes.put("summary", "changed");
326
		call("ticket.update", id, "my comment", attributes);
308
		call("ticket.update", id, "my comment", attributes);
327
309
328
		Vector log = (Vector) call("ticket.changeLog", id, 0);
310
		Object[] log = (Object[]) call("ticket.changeLog", id, 0);
329
		Vector entry = (Vector) log.get(0);
311
		Object[] entry = (Object[]) log[0];
330
		assertTrue(entry.get(0) instanceof Integer); // time
312
		assertTrue(entry[0] instanceof Integer); // time
331
		assertEquals(username, entry.get(1)); // author
313
		assertEquals(username, entry[1]); // author
332
		assertEquals("summary", entry.get(2)); // field
314
		assertEquals("summary", entry[2]); // field
333
		assertEquals("summary", entry.get(3)); // old value
315
		assertEquals("summary", entry[3]); // old value
334
		assertEquals("changed", entry.get(4)); // new value
316
		assertEquals("changed", entry[4]); // new value
335
317
336
		call("ticket.delete", id);
318
		call("ticket.delete", id);
337
	}
319
	}
Lines 340-357 Link Here
340
		int id1 = (Integer) call("ticket.create", "summary1", "description1", new Hashtable());
322
		int id1 = (Integer) call("ticket.create", "summary1", "description1", new Hashtable());
341
		int id2 = (Integer) call("ticket.create", "summary2", "description2", new Hashtable());
323
		int id2 = (Integer) call("ticket.create", "summary2", "description2", new Hashtable());
342
324
343
		Vector<Hashtable> calls = new Vector<Hashtable>();
325
		List<Map> calls = new ArrayList<Map>();
344
		calls.add(createMultiCall("ticket.get", id1));
326
		calls.add(createMultiCall("ticket.get", id1));
345
		calls.add(createMultiCall("ticket.get", id2));
327
		calls.add(createMultiCall("ticket.get", id2));
346
		Vector ret = (Vector) call("system.multicall", calls);
328
		Object[] ret = (Object[]) call("system.multicall", calls);
347
329
348
		Vector ticket = (Vector) ((Vector) ret.get(0)).get(0);
330
		Object[] ticket = (Object[]) ((Object[]) ret[0])[0];
349
		Hashtable<String, Object> attributes = new Hashtable<String, Object>();
331
		Map<String, Object> attributes = new Hashtable<String, Object>();
350
		attributes.put("summary", "summary1");
332
		attributes.put("summary", "summary1");
351
		attributes.put("description", "description1");
333
		attributes.put("description", "description1");
352
		assertTicketHasAttributes(attributes, id1, ticket);
334
		assertTicketHasAttributes(attributes, id1, ticket);
353
335
354
		ticket = (Vector) ((Vector) ret.get(1)).get(0);
336
		ticket = (Object[]) ((Object[]) ret[1])[0];
355
		attributes.clear();
337
		attributes.clear();
356
		attributes.put("summary", "summary2");
338
		attributes.put("summary", "summary2");
357
		attributes.put("description", "description2");
339
		attributes.put("description", "description2");
Lines 369-377 Link Here
369
		// attachment named "attach.txt"
351
		// attachment named "attach.txt"
370
		// assertEquals("attach.txt", filename);
352
		// assertEquals("attach.txt", filename);
371
353
372
		Vector ret = (Vector) call("ticket.listAttachments", id);
354
		Object[] ret = (Object[]) call("ticket.listAttachments", id);
373
		assertEquals(1, ret.size());
355
		assertEquals(1, ret.length);
374
		assertHasValue(ret.toArray(), filename);
356
		assertHasValue(ret, filename);
375
357
376
		byte[] bytes = (byte[]) call("ticket.getAttachment", id, filename);
358
		byte[] bytes = (byte[]) call("ticket.getAttachment", id, filename);
377
		String data = new String(bytes);
359
		String data = new String(bytes);
Lines 379-394 Link Here
379
361
380
		String filename2 = (String) call("ticket.putAttachment", id, filename, "data".getBytes(), true);
362
		String filename2 = (String) call("ticket.putAttachment", id, filename, "data".getBytes(), true);
381
		assertEquals(filename, filename2);
363
		assertEquals(filename, filename2);
382
		ret = (Vector) call("ticket.listAttachments", id);
364
		ret = (Object[]) call("ticket.listAttachments", id);
383
		assertEquals(1, ret.size());
365
		assertEquals(1, ret.length);
384
		assertHasValue(ret.toArray(), filename);
366
		assertHasValue(ret, filename);
385
367
386
		String filename3 = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), false);
368
		String filename3 = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), false);
387
		assertFalse("attach.txt".equals(filename3));
369
		assertFalse("attach.txt".equals(filename3));
388
		ret = (Vector) call("ticket.listAttachments", id);
370
		ret = (Object[]) call("ticket.listAttachments", id);
389
		assertEquals(2, ret.size());
371
		assertEquals(2, ret.length);
390
		assertHasValue(ret.toArray(), filename);
372
		assertHasValue(ret, filename);
391
		assertHasValue(ret.toArray(), filename3);
373
		assertHasValue(ret, filename3);
392
374
393
		call("ticket.delete", id);
375
		call("ticket.delete", id);
394
	}
376
	}
Lines 398-417 Link Here
398
380
399
		String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true);
381
		String filename = (String) call("ticket.putAttachment", id, "attach.txt", "data".getBytes(), true);
400
382
401
		Vector ret = (Vector) call("ticket.listAttachments", id);
383
		Object[] ret = (Object[]) call("ticket.listAttachments", id);
402
		assertEquals(1, ret.size());
384
		assertEquals(1, ret.length);
403
		assertHasValue(ret.toArray(), filename);
385
		assertHasValue(ret, filename);
404
386
405
		call("ticket.deleteAttachment", id, filename);
387
		call("ticket.deleteAttachment", id, filename);
406
388
407
		ret = (Vector) call("ticket.listAttachments", id);
389
		ret = (Object[]) call("ticket.listAttachments", id);
408
		assertEquals(0, ret.size());
390
		assertEquals(0, ret.length);
409
391
410
		call("ticket.delete", id);
392
		call("ticket.delete", id);
411
	}
393
	}
412
394
413
	public void testQuery() throws XmlRpcException, IOException {
395
	public void testQuery() throws XmlRpcException, IOException {
414
		Vector ret = (Vector) call("ticket.query", "summary~=foo|bar|baz|summary|ticket");
396
		Object[] ret = (Object[]) call("ticket.query", "summary~=foo|bar|baz|summary|ticket");
415
		for (Object id : ret) {
397
		for (Object id : ret) {
416
			call("ticket.delete", (Integer) id);
398
			call("ticket.delete", (Integer) id);
417
		}
399
		}
Lines 420-444 Link Here
420
		int id2 = (Integer) call("ticket.create", "foobaz summary2", "description", new Hashtable());
402
		int id2 = (Integer) call("ticket.create", "foobaz summary2", "description", new Hashtable());
421
		int id3 = (Integer) call("ticket.create", "ticket3", "description3", new Hashtable());
403
		int id3 = (Integer) call("ticket.create", "ticket3", "description3", new Hashtable());
422
404
423
		ret = (Vector) call("ticket.query", "summary=foobarsummary1|foobaz summary2");
405
		ret = (Object[]) call("ticket.query", "summary=foobarsummary1|foobaz summary2");
424
		assertEquals(2, ret.size());
406
		assertEquals(2, ret.length);
425
		assertEquals(ret.get(0), id1);
407
		assertEquals(id1, ret[0]);
426
		assertEquals(ret.get(1), id2);
408
		assertEquals(id2, ret[1]);
427
409
428
		ret = (Vector) call("ticket.query", "summary~=fooba&summary~=summary");
410
		ret = (Object[]) call("ticket.query", "summary~=fooba&summary~=summary");
429
		assertEquals(2, ret.size());
411
		assertEquals(2, ret.length);
430
		assertEquals(ret.get(0), id1);
412
		assertEquals(id1, ret[0]);
431
		assertEquals(ret.get(1), id2);
413
		assertEquals(id2, ret[1]);
432
414
433
		// ret = (Vector) call("ticket.query", "summary~=bar&summary~=baz");
415
		// ret = (Vector) call("ticket.query", "summary~=bar&summary~=baz");
434
		// assertEquals(0, ret.size());
416
		// assertEquals(0, ret.size());
435
417
436
		ret = (Vector) call("ticket.query", "summary~=bar|baz");
418
		ret = (Object[]) call("ticket.query", "summary~=bar|baz");
437
		assertEquals(2, ret.size());
419
		assertEquals(2, ret.length);
438
420
439
		ret = (Vector) call("ticket.query", "description~=description3");
421
		ret = (Object[]) call("ticket.query", "description~=description3");
440
		assertEquals(1, ret.size());
422
		assertEquals(1, ret.length);
441
		assertEquals(ret.get(0), id3);
423
		assertEquals(id3, ret[0]);
442
424
443
		call("ticket.delete", id1);
425
		call("ticket.delete", id1);
444
		call("ticket.delete", id2);
426
		call("ticket.delete", id2);
Lines 448-456 Link Here
448
	public void testQueryAll() throws XmlRpcException, IOException {
430
	public void testQueryAll() throws XmlRpcException, IOException {
449
		int id = (Integer) call("ticket.create", "foo", "description", new Hashtable());
431
		int id = (Integer) call("ticket.create", "foo", "description", new Hashtable());
450
432
451
		Vector ret = (Vector) call("ticket.query", "order=id");
433
		Object[] ret = (Object[]) call("ticket.query", "order=id");
452
		assertTrue(ret.size() > 0);
434
		assertTrue(ret.length > 0);
453
		assertHasValue(ret.toArray(), id);
435
		assertHasValue(ret, id);
454
436
455
		call("ticket.delete", id);
437
		call("ticket.delete", id);
456
	}
438
	}
(-)src/org/eclipse/mylar/trac/tests/AbstractTracClientSearchTest.java (-2 / +1 lines)
Lines 12-18 Link Here
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Hashtable;
16
import java.util.List;
15
import java.util.List;
17
import java.util.Map;
16
import java.util.Map;
18
17
Lines 61-67 Link Here
61
	protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception {
60
	protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception {
62
		assertTrue(tracTicket.isValid());
61
		assertTrue(tracTicket.isValid());
63
62
64
		Hashtable expectedValues = ticket.getValues();
63
		Map expectedValues = ticket.getValues();
65
		Map<String, String> values = tracTicket.getValues();
64
		Map<String, String> values = tracTicket.getValues();
66
		for (String key : values.keySet()) {
65
		for (String key : values.keySet()) {
67
			assertEquals("Values for key '" + key + "' did not match", expectedValues.get(key), values.get(key));
66
			assertEquals("Values for key '" + key + "' did not match", expectedValues.get(key), values.get(key));
(-)src/org/eclipse/mylar/trac/tests/Trac09ClientTest.java (+20 lines)
Lines 12-21 Link Here
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.net.URL;
14
import java.net.URL;
15
import java.util.Arrays;
16
import java.util.Comparator;
15
17
18
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.mylar.internal.trac.core.ITracClient;
19
import org.eclipse.mylar.internal.trac.core.ITracClient;
17
import org.eclipse.mylar.internal.trac.core.Trac09Client;
20
import org.eclipse.mylar.internal.trac.core.Trac09Client;
18
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
21
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
22
import org.eclipse.mylar.internal.trac.model.TracVersion;
19
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
23
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
20
24
21
/**
25
/**
Lines 36-39 Link Here
36
		factory.repository.validate();
40
		factory.repository.validate();
37
	}
41
	}
38
42
43
	public void testUpdateAttributes() throws Exception {
44
		factory.connectRepository1();
45
		assertNull(factory.repository.getMilestones());
46
		factory.repository.updateAttributes(new NullProgressMonitor());
47
		TracVersion[] versions = factory.repository.getVersions();
48
		assertEquals(2, versions.length);
49
		Arrays.sort(versions, new Comparator<TracVersion>() {
50
			public int compare(TracVersion o1, TracVersion o2) {
51
				return o1.getName().compareTo(o2.getName());
52
			}
53
		});
54
		assertEquals("v1", versions[0].getName());
55
		assertEquals("v2", versions[1].getName());
56
	}
57
58
39
}
59
}
(-)src/org/eclipse/mylar/trac/tests/AllTracTests.java (-3 / +4 lines)
Lines 22-29 Link Here
22
22
23
	public static Test suite() {
23
	public static Test suite() {
24
		TestSuite suite = new TestSuite("Test for org.eclipse.mylar.trac.tests");
24
		TestSuite suite = new TestSuite("Test for org.eclipse.mylar.trac.tests");
25
		//$JUnit-BEGIN$
25
		// $JUnit-BEGIN$
26
		suite.addTestSuite(TracXmlRpcTest.class);
26
		// suite.addTestSuite(TracXmlRpcTest.class);
27
		suite.addTestSuite(TracSearchTest.class);
27
		suite.addTestSuite(TracSearchTest.class);
28
		suite.addTestSuite(TracTicketTest.class);
28
		suite.addTestSuite(TracTicketTest.class);
29
		suite.addTestSuite(TracXmlRpcClientTest.class);
29
		suite.addTestSuite(TracXmlRpcClientTest.class);
Lines 33-39 Link Here
33
		suite.addTestSuite(TracClientFactoryTest.class);
33
		suite.addTestSuite(TracClientFactoryTest.class);
34
		suite.addTestSuite(TracRepositoryConnectorTest.class);
34
		suite.addTestSuite(TracRepositoryConnectorTest.class);
35
		suite.addTestSuite(TracQueryTest.class);
35
		suite.addTestSuite(TracQueryTest.class);
36
		//$JUnit-END$
36
		suite.addTestSuite(TracRepositoryQueryTest.class);
37
		// $JUnit-END$
37
		return suite;
38
		return suite;
38
	}
39
	}
39
40
(-)src/org/eclipse/mylar/trac/tests/TracClientFactoryTest.java (+10 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.mylar.trac.tests;
12
package org.eclipse.mylar.trac.tests;
13
13
14
import java.net.Authenticator;
15
14
import junit.framework.TestCase;
16
import junit.framework.TestCase;
15
17
16
import org.eclipse.mylar.internal.trac.core.ITracClient;
18
import org.eclipse.mylar.internal.trac.core.ITracClient;
Lines 26-31 Link Here
26
 */
28
 */
27
public class TracClientFactoryTest extends TestCase {
29
public class TracClientFactoryTest extends TestCase {
28
30
31
	@Override
32
	protected void setUp() throws Exception {
33
		super.setUp();
34
		
35
		// make sure no dialog pops up to prompt for a password
36
		Authenticator.setDefault(null);
37
	}
38
	
29
	public void testCreateClient() throws Exception {
39
	public void testCreateClient() throws Exception {
30
		ITracClient client = TracClientFactory.createClient(Constants.TEST_REPOSITORY1_URL, Version.TRAC_0_9, "user",
40
		ITracClient client = TracClientFactory.createClient(Constants.TEST_REPOSITORY1_URL, Version.TRAC_0_9, "user",
31
				"password");
41
				"password");
(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 7-13 Link Here
7
Require-Bundle: org.junit,
7
Require-Bundle: org.junit,
8
 org.eclipse.ui,
8
 org.eclipse.ui,
9
 org.eclipse.core.runtime,
9
 org.eclipse.core.runtime,
10
 org.apache.xmlrpc,
10
 org.eclipse.mylar.context.core,
11
 org.eclipse.mylar.tasks.ui,
11
 org.eclipse.mylar.tasks.ui,
12
 org.eclipse.mylar.trac,
12
 org.eclipse.mylar.trac,
13
 org.eclipse.mylar.tasks.core
13
 org.eclipse.mylar.tasks.core
(-)src/org/eclipse/mylar/trac/tests/support/XmlRpcServer.java (-18 / +11 lines)
Lines 18-27 Link Here
18
import java.util.Arrays;
18
import java.util.Arrays;
19
import java.util.Hashtable;
19
import java.util.Hashtable;
20
import java.util.List;
20
import java.util.List;
21
import java.util.Map;
21
import java.util.Vector;
22
import java.util.Vector;
22
23
23
import org.apache.xmlrpc.XmlRpcClient;
24
import org.apache.xmlrpc.XmlRpcException;
24
import org.apache.xmlrpc.XmlRpcException;
25
import org.apache.xmlrpc.client.XmlRpcClient;
25
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
26
import org.eclipse.mylar.internal.trac.core.TracXmlRpcClient;
26
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
27
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
27
28
Lines 80-91 Link Here
80
		}
81
		}
81
82
82
		public ModelEnum deleteAndCreate(Object... params) throws Exception {
83
		public ModelEnum deleteAndCreate(Object... params) throws Exception {
83
			try {
84
			if (Arrays.asList(getAll()).contains(id)) {
84
				if (Arrays.asList(getAll()).contains(id)) {
85
				delete();
85
					delete();
86
				}
87
			} catch (Exception e) {
88
				// ignore
89
			}
86
			}
90
87
91
			return create(params);
88
			return create(params);
Lines 102-108 Link Here
102
99
103
		@SuppressWarnings("unchecked")
100
		@SuppressWarnings("unchecked")
104
		public String[] getAll() throws Exception {
101
		public String[] getAll() throws Exception {
105
			return (String[]) ((Vector) call(module + ".getAll")).toArray(new String[0]);
102
			return Arrays.asList((Object[]) call(module + ".getAll")).toArray(new String[0]);
106
		}
103
		}
107
104
108
		private Hashtable<String, Object> toMap(Object... params) {
105
		private Hashtable<String, Object> toMap(Object... params) {
Lines 178-190 Link Here
178
			return getValues().get(key);
175
			return getValues().get(key);
179
		}
176
		}
180
177
181
		public Hashtable getValues() throws Exception {
178
		public Map getValues() throws Exception {
182
			return (Hashtable) ((Vector) call("ticket.get", id)).get(3);
179
			return (Map) ((Object[]) call("ticket.get", id))[3];
183
		}
180
		}
184
181
185
		@SuppressWarnings("unchecked")
182
		@SuppressWarnings("unchecked")
186
		public Integer[] getAll() throws Exception {
183
		public Integer[] getAll() throws Exception {
187
			return (Integer[]) ((Vector) call("ticket.query", "order=id")).toArray(new Integer[0]);
184
			return Arrays.asList((Object[]) call("ticket.query", "order=id")).toArray(new Integer[0]);
188
		}
185
		}
189
186
190
		public int getId() {
187
		public int getId() {
Lines 245-256 Link Here
245
		}
242
		}
246
243
247
		public TicketEnum deleteAndCreate(String param) throws Exception {
244
		public TicketEnum deleteAndCreate(String param) throws Exception {
248
			try {
245
			if (Arrays.asList(getAll()).contains(id)) {
249
				if (Arrays.asList(getAll()).contains(id)) {
246
				delete();
250
					delete();
251
				}
252
			} catch (Exception e) {
253
				// ignore
254
			}
247
			}
255
248
256
			return create(param);
249
			return create(param);
Lines 262-268 Link Here
262
255
263
		@SuppressWarnings("unchecked")
256
		@SuppressWarnings("unchecked")
264
		public String[] getAll() throws Exception {
257
		public String[] getAll() throws Exception {
265
			return (String[]) ((Vector) call(module + ".getAll")).toArray(new String[0]);
258
			return Arrays.asList((Object[]) call(module + ".getAll")).toArray(new String[0]);
266
		}
259
		}
267
260
268
		public TicketEnum update(String param) throws Exception {
261
		public TicketEnum update(String param) throws Exception {
(-)src/org/eclipse/mylar/trac/tests/support/TestFixture.java (+4 lines)
Lines 30-35 Link Here
30
			XmlRpcServer server = new XmlRpcServer(Constants.TEST_REPOSITORY1_URL,
30
			XmlRpcServer server = new XmlRpcServer(Constants.TEST_REPOSITORY1_URL,
31
					Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
31
					Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
32
32
33
			server.ticketVersion(null).deleteAll();
34
			server.ticketVersion("v1").create(86400, "description1");
35
			server.ticketVersion("v2").create(86400 * 2, "description2");
36
			
33
			server.ticket().deleteAll();
37
			server.ticket().deleteAll();
34
38
35
			server.ticketMilestone("m1").deleteAndCreate();
39
			server.ticketMilestone("m1").deleteAndCreate();
(-)src/org/eclipse/mylar/trac/tests/TracRepositoryQueryTest.java (+46 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.trac.tests;
13
14
import java.util.Arrays;
15
import java.util.List;
16
17
import junit.framework.TestCase;
18
19
import org.eclipse.mylar.internal.trac.TracRepositoryQuery;
20
import org.eclipse.mylar.internal.trac.core.ITracClient;
21
import org.eclipse.mylar.internal.trac.model.TracSearch;
22
import org.eclipse.mylar.internal.trac.model.TracSearchFilter;
23
24
public class TracRepositoryQueryTest extends TestCase {
25
26
	public void testGetFilterList() {
27
		String repositoryUrl = "https://foo.bar/repo";
28
		String parameterUrl = "&status=new&status=assigned&status=reopened&milestone=0.1";
29
		String queryUrl = repositoryUrl + ITracClient.QUERY_URL + parameterUrl;
30
		TracRepositoryQuery query = new TracRepositoryQuery(repositoryUrl, queryUrl, "description", null);
31
32
		TracSearch filterList = query.getTracSearch();
33
34
		assertEquals(parameterUrl, filterList.toUrl());
35
		assertEquals("&status=new|assigned|reopened&milestone=0.1", filterList.toQuery());
36
37
		List<TracSearchFilter> list = filterList.getFilters();
38
		TracSearchFilter filter = list.get(0);
39
		assertEquals("status", filter.getFieldName());
40
		assertEquals(Arrays.asList("new", "assigned", "reopened"), filter.getValues());
41
		filter = list.get(1);
42
		assertEquals("milestone", filter.getFieldName());
43
		assertEquals(Arrays.asList("0.1"), filter.getValues());
44
	}
45
46
}
(-)src/org/eclipse/mylar/tasks/tests/AllTasksTests.java (+3 lines)
Lines 11-16 Link Here
11
11
12
package org.eclipse.mylar.tasks.tests;
12
package org.eclipse.mylar.tasks.tests;
13
13
14
import org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil;
15
14
import junit.framework.Test;
16
import junit.framework.Test;
15
import junit.framework.TestSuite;
17
import junit.framework.TestSuite;
16
18
Lines 43-48 Link Here
43
		suite.addTestSuite(RepositorySettingsPageTest.class);
45
		suite.addTestSuite(RepositorySettingsPageTest.class);
44
		// suite.addTestSuite(RetrieveTitleFromUrlTest.class);
46
		// suite.addTestSuite(RetrieveTitleFromUrlTest.class);
45
		suite.addTestSuite(TaskHistoryTest.class);
47
		suite.addTestSuite(TaskHistoryTest.class);
48
		suite.addTestSuite(UrlConnectionUtilTest.class);
46
		// $JUnit-END$
49
		// $JUnit-END$
47
		return suite;
50
		return suite;
48
	}
51
	}
(-)src/org/eclipse/mylar/tasks/tests/UrlConnectionUtilTest.java (+34 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 Mylar committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylar.tasks.tests;
10
11
import junit.framework.TestCase;
12
13
import org.eclipse.mylar.internal.tasks.core.UrlConnectionUtil;
14
15
public class UrlConnectionUtilTest extends TestCase {
16
17
	public void testUrlParsers() {
18
		String url = "https://example.com:444/folder/file.txt";
19
		assertEquals(444, UrlConnectionUtil.getPort(url));
20
		assertEquals("example.com", UrlConnectionUtil.getDomain(url));
21
		assertEquals("/folder/file.txt", UrlConnectionUtil.getRequestPath(url));
22
	
23
		url = "http://example.com/";
24
		assertEquals(80, UrlConnectionUtil.getPort(url));
25
		assertEquals("example.com", UrlConnectionUtil.getDomain(url));
26
		assertEquals("/", UrlConnectionUtil.getRequestPath(url));
27
	
28
		url = "https://example.com:321";
29
		assertEquals(321, UrlConnectionUtil.getPort(url));
30
		assertEquals("example.com", UrlConnectionUtil.getDomain(url));
31
		assertEquals("", UrlConnectionUtil.getRequestPath(url));
32
	}
33
34
}

Return to bug 151896