Skip to main content
summaryrefslogtreecommitdiffstats
blob: bb5f8d5fcdb239dcaf676a81c908cd97314f7145 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
/*******************************************************************************
 * Copyright (c) 2009 Tasktop Technologies 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:
 *      Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.oslc.core.client;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.net.AbstractWebLocation;
import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.commons.net.WebUtil;
import org.eclipse.mylyn.internal.oslc.core.IOslcCoreConstants;
import org.eclipse.mylyn.internal.oslc.core.OslcCreationDialogDescriptor;
import org.eclipse.mylyn.internal.oslc.core.OslcSelectionDialogDescriptor;
import org.eclipse.mylyn.internal.oslc.core.OslcServiceDescriptor;
import org.eclipse.mylyn.internal.oslc.core.OslcServiceFactory;
import org.eclipse.mylyn.internal.oslc.core.OslcServiceProvider;
import org.eclipse.mylyn.internal.oslc.core.OslcServiceProviderCatalog;
import org.eclipse.mylyn.internal.oslc.core.ServiceHome;
import org.eclipse.mylyn.internal.oslc.core.cm.AbstractChangeRequest;
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.filter.ElementFilter;
import org.jdom.input.SAXBuilder;

/**
 * Base class from which to implement an OSLC client
 * 
 * @author Robert Elves
 */
public abstract class AbstractOslcClient {

	protected final AbstractWebLocation location;

	protected final HttpClient httpClient;

	protected final OslcServiceDescriptor configuration;

	public AbstractOslcClient(AbstractWebLocation location, OslcServiceDescriptor data) {
		this.location = location;
		this.httpClient = createHttpClient();
		this.configuration = data;
	}

	protected HttpClient createHttpClient() {
		HttpClient httpClient = new HttpClient();
		httpClient.setHttpConnectionManager(WebUtil.getConnectionManager());
		httpClient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);

		// See: https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=85127\
		// Added to support fix session cookie issue when talking to tomcat
		httpClient.getParams().setParameter("http.protocol.single-cookie-header", true); //$NON-NLS-1$

		WebUtil.configureHttpClient(httpClient, getUserAgent());
		return httpClient;
	}

	/**
	 * Return your unique connector identifier i.e. com.mycompany.myconnector
	 */
	public abstract String getUserAgent();

	/**
	 * Exposed at connector level via IOslcCoreConnector.getAvailableServices()
	 */
	public List<OslcServiceProvider> getAvailableServices(String url, IProgressMonitor monitor) throws CoreException {

		RequestHandler<List<OslcServiceProvider>> handler = new RequestHandler<List<OslcServiceProvider>>(
				"Requesting Available Services") { //$NON-NLS-1$

			@Override
			public List<OslcServiceProvider> run(HttpMethodBase method, IProgressMonitor monitor) throws CoreException {
				try {
					final List<OslcServiceProvider> result = new ArrayList<OslcServiceProvider>();
					parseServices(method.getResponseBodyAsStream(), result, monitor);
					return result;
				} catch (IOException e) {
					throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
							"Network error occurred retrieving available services: " + e.getMessage(), e)); //$NON-NLS-1$
				}
			}
		};

		return executeMethod(createGetMethod(url), handler, monitor);
	}

	protected Document getDocumentFromMethod(HttpMethodBase method) throws CoreException {
		try {
			return getDocumentFromStream(method.getResponseBodyAsStream());
		} catch (IOException e) {
			throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
					"Network error obtaining response from server: " + e.getMessage(), e)); //$NON-NLS-1$
		}
	}

	protected Document getDocumentFromStream(InputStream inStream) throws CoreException {
		SAXBuilder builder = new SAXBuilder();
		builder.setExpandEntities(false);
		try {
			return builder.build(inStream);
		} catch (JDOMException e) {
			throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
					"Error parsing response: " + e.getMessage(), e)); //$NON-NLS-1$
		} catch (IOException e) {
			throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
					"Network error parsing response: " + e.getMessage(), e)); //$NON-NLS-1$
		}
	}

	/**
	 * public for testing
	 */
	public void parseServices(InputStream inStream, Collection<OslcServiceProvider> providers, IProgressMonitor monitor)
			throws CoreException {

		Document doc = getDocumentFromStream(inStream);

		Iterator<?> itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_SERVICE_PROVIDER_CATALOG));
		while (itr.hasNext()) {
			Element element = (Element) itr.next();
			if (element.getParent() != doc.getRootElement()) {
				Attribute attrResource = element.getAttribute(IOslcCoreConstants.ATTRIBUTE_RESOURCE,
						IOslcCoreConstants.NAMESPACE_RDF);
				String title = element.getChild(IOslcCoreConstants.ELEMENT_TITLE, IOslcCoreConstants.NAMESPACE_DC)
						.getText();
				if (attrResource != null && attrResource.getValue().length() > 0) {
					providers.add(new OslcServiceProviderCatalog(title, attrResource.getValue()));
				}
			}
		}
		itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_SERVICE_PROVIDER));
		while (itr.hasNext()) {
			Element element = (Element) itr.next();
			String title = element.getChild(IOslcCoreConstants.ELEMENT_TITLE, IOslcCoreConstants.NAMESPACE_DC)
					.getText();
			Element service = element.getChild(IOslcCoreConstants.ELEMENT_SERVICES,
					IOslcCoreConstants.NAMESPACE_OSLC_DISCOVERY_1_0);
			if (service != null) {
				String resource = service.getAttributeValue(IOslcCoreConstants.ATTRIBUTE_RESOURCE,
						IOslcCoreConstants.NAMESPACE_RDF);
				providers.add(new OslcServiceProvider(title, resource));
			}
		}
	}

	/**
	 * Retrieve a service descriptor for the given service provider. Exposed at connector level by
	 * IOslcConnector.getServiceDescriptor()
	 * 
	 * @throws CoreException
	 */
	public OslcServiceDescriptor getServiceDescriptor(OslcServiceProvider provider, IProgressMonitor monitor)
			throws CoreException {
		OslcServiceDescriptor configuration = new OslcServiceDescriptor(provider.getUrl());
		downloadServiceDescriptor(configuration, monitor);
		return configuration;
	}

	/**
	 * Populate the provided configuration with new data from the remote repository.
	 */
	protected void downloadServiceDescriptor(final OslcServiceDescriptor config, IProgressMonitor monitor)
			throws CoreException {

		RequestHandler<OslcServiceDescriptor> handler = new RequestHandler<OslcServiceDescriptor>(
				"Retrieving Service Descriptor") { //$NON-NLS-1$

			@Override
			public OslcServiceDescriptor run(HttpMethodBase method, IProgressMonitor monitor) throws CoreException,
					IOException {
				config.clear();
				parseServiceDescriptor(method.getResponseBodyAsStream(), config, monitor);
				return config;
			}
		};

		executeMethod(createGetMethod(config.getAboutUrl()), handler, monitor);

	}

	/**
	 * public for testing
	 */
	public void parseServiceDescriptor(InputStream inStream, OslcServiceDescriptor config, IProgressMonitor monitor)
			throws CoreException {
		Document doc = getDocumentFromStream(inStream);

		Iterator<?> itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_TITLE,
				IOslcCoreConstants.NAMESPACE_DC));
		if (itr.hasNext()) {
			Element element = (Element) itr.next();
			config.setTitle(element.getText());
		}

		itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_DESCRIPTION,
				IOslcCoreConstants.NAMESPACE_DC));
		if (itr.hasNext()) {
			Element element = (Element) itr.next();
			config.setDescription(element.getText());
		}

		itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_CREATIONDIALOG));
		while (itr.hasNext()) {
			boolean isDefault = false;
			Element element = (Element) itr.next();
			String label = element.getChild(IOslcCoreConstants.ELEMENT_TITLE, IOslcCoreConstants.NAMESPACE_DC)
					.getText();
			String url = element.getChild(IOslcCoreConstants.ELEMENT_URL, IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0)
					.getText();
			Attribute attrDefault = element.getAttribute(IOslcCoreConstants.ATTRIBUTE_DEFAULT,
					IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0);
			if (attrDefault != null && attrDefault.getValue().equals("true")) { //$NON-NLS-1$
				isDefault = true;
			}
			OslcCreationDialogDescriptor recordType = new OslcCreationDialogDescriptor(label, url);
			config.addCreationDialog(recordType);
			if (isDefault) {
				config.setDefaultCreationDialog(recordType);
			}
		}

		itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_SIMPLEQUERY));
		if (itr.hasNext()) {
			Element element = (Element) itr.next();
			String url = element.getChild(IOslcCoreConstants.ELEMENT_URL, IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0)
					.getText();
			if (url != null) {
				config.setSimpleQueryUrl(url);
			}
		}

		itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_FACTORY));
		while (itr.hasNext()) {
			boolean isDefault = false;
			Element element = (Element) itr.next();
			String title = element.getChild(IOslcCoreConstants.ELEMENT_TITLE, IOslcCoreConstants.NAMESPACE_DC)
					.getText();
			String url = element.getChild(IOslcCoreConstants.ELEMENT_URL, IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0)
					.getText();
			if (element.getAttribute(IOslcCoreConstants.ATTRIBUTE_DEFAULT) != null
					&& element.getAttribute(IOslcCoreConstants.ATTRIBUTE_DEFAULT).getValue().equals("true")) { //$NON-NLS-1$
				isDefault = true;
			}
			OslcServiceFactory factory = new OslcServiceFactory(title, url);
			if (isDefault) {
				config.setDefaultFactory(factory);
			}
			config.addServiceFactory(factory);
		}

		itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_HOME));
		if (itr.hasNext()) {
			Element element = (Element) itr.next();
			Element childTitle = element.getChild(IOslcCoreConstants.ELEMENT_TITLE, IOslcCoreConstants.NAMESPACE_DC);
			Element childUrl = element.getChild(IOslcCoreConstants.ELEMENT_URL,
					IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0);
			if (childTitle != null && childTitle.getText().length() > 0 && childUrl != null
					&& childUrl.getText().length() > 0) {
				ServiceHome home = new ServiceHome(childTitle.getText(), childUrl.getText());
				config.setHome(home);
			}
		}

		itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_SELECTIONDIALOG));
		if (itr.hasNext()) {
			Element element = (Element) itr.next();
			Element childTitle = element.getChild(IOslcCoreConstants.ELEMENT_TITLE, IOslcCoreConstants.NAMESPACE_DC);
			Element childUrl = element.getChild(IOslcCoreConstants.ELEMENT_URL,
					IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0);
			if (childTitle != null && childTitle.getText().length() > 0 && childUrl != null
					&& childUrl.getText().length() > 0) {

				OslcSelectionDialogDescriptor selection = new OslcSelectionDialogDescriptor(childTitle.getText(),
						childUrl.getText());

				String isDefault = element.getAttributeValue(IOslcCoreConstants.ATTRIBUTE_DEFAULT,
						IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0);
				if (isDefault != null) {
					selection.setDefault(isDefault.equals("true")); //$NON-NLS-1$
				}

				String hintHeight = element.getAttributeValue(IOslcCoreConstants.ATTRIBUTE_HINTHEIGHT,
						IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0);
				if (hintHeight != null) {
					selection.setHintHeight(hintHeight);
				}

				String hintWidth = element.getAttributeValue(IOslcCoreConstants.ATTRIBUTE_HINTWIDTH,
						IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0);
				if (hintWidth != null) {
					selection.setHintWidth(hintWidth);
				}

				String label = element.getChildText(IOslcCoreConstants.ELEMENT_LABEL,
						IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0);
				if (label != null) {
					selection.setLabel(label);
				}

				config.addSelectionDialog(selection);
			}
		}

	}

	public Collection<AbstractChangeRequest> performQuery(String queryUrl, IProgressMonitor monitor)
			throws CoreException {

		RequestHandler<Collection<AbstractChangeRequest>> handler = new RequestHandler<Collection<AbstractChangeRequest>>(
				"Performing Query") { //$NON-NLS-1$

			@Override
			public Collection<AbstractChangeRequest> run(HttpMethodBase method, IProgressMonitor monitor)
					throws CoreException, IOException {
				Collection<AbstractChangeRequest> result = new ArrayList<AbstractChangeRequest>();
				parseQueryResponse(method.getResponseBodyAsStream(), result, monitor);
				return result;
			}
		};

		return executeMethod(createGetMethod(queryUrl), handler, monitor);

	}

	// TODO: Handle pagination
	public void parseQueryResponse(InputStream inStream, Collection<AbstractChangeRequest> requests,
			IProgressMonitor monitor) throws CoreException {
		Document doc = getDocumentFromStream(inStream);

		Iterator<?> itr = doc.getDescendants(new ElementFilter(IOslcCoreConstants.ELEMENT_CHANGEREQUEST,
				IOslcCoreConstants.NAMESPACE_OSLC_CM_1_0));
		while (itr.hasNext()) {
			Element element = (Element) itr.next();
			String title = element.getChildText(IOslcCoreConstants.ELEMENT_TITLE, IOslcCoreConstants.NAMESPACE_DC);
			String id = element.getChildText(IOslcCoreConstants.ELEMENT_IDENTIFIER, IOslcCoreConstants.NAMESPACE_DC);

			if (title != null && id != null) {
				AbstractChangeRequest request = createChangeRequest(id, title);
				request.setType(element.getChildText(IOslcCoreConstants.ELEMENT_TYPE, IOslcCoreConstants.NAMESPACE_DC));
				request.setDescription(element.getChildText(IOslcCoreConstants.ELEMENT_DESCRIPTION,
						IOslcCoreConstants.NAMESPACE_DC));
				request.setSubject(element.getChildText(IOslcCoreConstants.ELEMENT_SUBJECT,
						IOslcCoreConstants.NAMESPACE_DC));
				request.setCreator(element.getChildText(IOslcCoreConstants.ELEMENT_CREATOR,
						IOslcCoreConstants.NAMESPACE_DC));
				request.setModified(element.getChildText(IOslcCoreConstants.ELEMENT_MODIFIED,
						IOslcCoreConstants.NAMESPACE_DC));
				requests.add(request);
			}

		}
	}

	protected abstract AbstractChangeRequest createChangeRequest(String id, String title);

	/**
	 * Updates this clients 'repository configuration'. If old types were in use (locally cached) and still exist they
	 * are re-read from repository.
	 */
	public void updateRepositoryConfiguration(IProgressMonitor monitor) throws CoreException {
		configuration.clear();
		downloadServiceDescriptor(configuration, monitor);
	}

	public abstract TaskData getTaskData(final String encodedTaskId, TaskAttributeMapper mapper,
			IProgressMonitor monitor) throws CoreException;

	public abstract RepositoryResponse putTaskData(TaskData taskData, Set<TaskAttribute> oldValues,
			IProgressMonitor monitor) throws CoreException;

	protected GetMethod createGetMethod(String requestPath) {
		GetMethod method = new GetMethod(getRequestPath(requestPath));
		method.setFollowRedirects(false);
		method.setDoAuthentication(true);
		// application/xml is returned by oslc servers by default
		//method.setRequestHeader("Accept", "application/xml");
		return method;
	}

	protected PostMethod createPostMethod(String requestPath) {
		PostMethod method = new PostMethod(getRequestPath(requestPath));
		method.setFollowRedirects(false);
		method.setDoAuthentication(true);
//		this.entity = getRequestEntity(method);
//		if (pairs != null) {
//			method.setRequestBody(pairs);
//		} else if (entity != null) {
//			method.setRequestEntity(entity);
//		} else {
//			StatusHandler.log(new Status(IStatus.WARNING, IOslcCoreConstants.ID_PLUGIN,
//					"Request body or entity missing upon post.")); //$NON-NLS-1$
//		}
		return method;
	}

	protected PutMethod createPutMethod(String requestPath) {
		PutMethod method = new PutMethod(getRequestPath(requestPath));
		method.setFollowRedirects(false);
		method.setDoAuthentication(true);
		return method;
	}

	protected <T> T executeMethod(HttpMethodBase method, RequestHandler<T> handler, IProgressMonitor monitor)
			throws CoreException {
		monitor = Policy.monitorFor(monitor);
		try {
			monitor.beginTask(handler.getRequestName(), IProgressMonitor.UNKNOWN);

			HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor);
			int code = WebUtil.execute(httpClient, hostConfiguration, method, monitor);

			handler.handleReturnCode(code, method);

			return handler.run(method, monitor);
		} catch (IOException e) {
			throw new CoreException(new Status(IStatus.WARNING, IOslcCoreConstants.ID_PLUGIN,
					"An unexpected network error has occurred: " + e.getMessage(), e)); //$NON-NLS-1$
		} finally {
			if (method != null) {
				method.releaseConnection();
			}
			monitor.done();
		}

	}

	public String getRequestPath(String repositoryUrl) {
		if (repositoryUrl.startsWith("./")) { //$NON-NLS-1$
			return WebUtil.getRequestPath(location.getUrl()) + repositoryUrl.substring(1);
		} else if (repositoryUrl.startsWith("/")) { //$NON-NLS-1$
			return WebUtil.getRequestPath(location.getUrl()) + repositoryUrl;
		}
		return WebUtil.getRequestPath(repositoryUrl);
	}

	public abstract class RequestHandler<T> {

		private final String requestName;

		public RequestHandler(String requestName) {
			this.requestName = requestName;
		}

		public abstract T run(HttpMethodBase method, IProgressMonitor monitor) throws CoreException, IOException;

		public String getRequestName() {
			return requestName;
		}

		protected void handleReturnCode(int code, HttpMethodBase method) throws CoreException {
			try {
				if (code == java.net.HttpURLConnection.HTTP_OK) {
					return;// Status.OK_STATUS;
				} else if (code == java.net.HttpURLConnection.HTTP_MOVED_TEMP
						|| code == java.net.HttpURLConnection.HTTP_CREATED) {
					// A new resource created...
					return;// Status.OK_STATUS;
				} else if (code == java.net.HttpURLConnection.HTTP_UNAUTHORIZED
						|| code == java.net.HttpURLConnection.HTTP_FORBIDDEN) {
					throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
							"Unable to log into server, ensure repository credentials are correct.")); //$NON-NLS-1$
				} else if (code == java.net.HttpURLConnection.HTTP_PRECON_FAILED) {
					// Mid-air collision
					throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
							"Mid-air collision occurred.")); //$NON-NLS-1$
				} else if (code == java.net.HttpURLConnection.HTTP_CONFLICT) {
					throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN,
							"A conflict occurred.")); //$NON-NLS-1$
				} else {
					throw new CoreException(
							new Status(
									IStatus.ERROR,
									IOslcCoreConstants.ID_PLUGIN,
									"Unknown error occurred. Http Code: " + code + " Request: " + method.getURI() + " Response: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
											+ method.getResponseBodyAsString()));
				}
			} catch (URIException e) {
				throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN, "Network Error: " //$NON-NLS-1$
						+ e.getMessage()));
			} catch (IOException e) {
				throw new CoreException(new Status(IStatus.ERROR, IOslcCoreConstants.ID_PLUGIN, "Network Error: " //$NON-NLS-1$
						+ e.getMessage()));
			}
		}

	}
}

Back to the top