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 403675
Collapse All | Expand All

(-)a/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF (-5 / +12 lines)
Lines 14-24 Export-Package: org.eclipse.ecf.internal.remoteservice.rest;x-internal:=true, Link Here
14
 org.eclipse.ecf.remoteservice.rest.client;version="2.2.200",
14
 org.eclipse.ecf.remoteservice.rest.client;version="2.2.200",
15
 org.eclipse.ecf.remoteservice.rest.identity;version="2.2.200",
15
 org.eclipse.ecf.remoteservice.rest.identity;version="2.2.200",
16
 org.eclipse.ecf.remoteservice.rest.util;version="2.2.200"
16
 org.eclipse.ecf.remoteservice.rest.util;version="2.2.200"
17
Import-Package: org.apache.commons.httpclient;version="3.0.1",
17
Import-Package: org.apache.http;version="4.1.2",
18
 org.apache.commons.httpclient.auth;version="3.0.1",
18
 org.apache.http.client;version="4.1.2",
19
 org.apache.commons.httpclient.methods;version="3.1.0",
19
 org.apache.http.client.entity;version="4.1.2",
20
 org.apache.commons.httpclient.params;version="3.0.1",
20
 org.apache.http.client.params;version="4.1.2",
21
 org.apache.commons.httpclient.util,
21
 org.apache.http.impl.auth;version="4.1.2",
22
 org.apache.http.impl.client;version="4.1.2",
23
 org.apache.http.entity;version="4.1.2",
24
 org.apache.http.message;version="4.1.2",
25
 org.apache.http.auth;version="4.1.2",
26
 org.apache.http.client.methods;version="4.1.2",
27
 org.apache.http.params;version="4.1.2",
28
 org.apache.http.util,
22
 org.eclipse.ecf.remoteservice;version="6.0.0",
29
 org.eclipse.ecf.remoteservice;version="6.0.0",
23
 org.eclipse.ecf.remoteservice.client,
30
 org.eclipse.ecf.remoteservice.client,
24
 org.eclipse.ecf.remoteservice.events,
31
 org.eclipse.ecf.remoteservice.events,
(-)a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/AbstractEntityRequestType.java (-11 / +13 lines)
Lines 11-17 Link Here
11
11
12
import java.io.*;
12
import java.io.*;
13
import java.util.Map;
13
import java.util.Map;
14
import org.apache.commons.httpclient.methods.*;
14
import org.apache.http.HttpEntity;
15
import org.apache.http.entity.*;
15
import org.eclipse.ecf.remoteservice.IRemoteCall;
16
import org.eclipse.ecf.remoteservice.IRemoteCall;
16
import org.eclipse.ecf.remoteservice.client.IRemoteCallParameter;
17
import org.eclipse.ecf.remoteservice.client.IRemoteCallParameter;
17
import org.eclipse.ecf.remoteservice.client.IRemoteCallable;
18
import org.eclipse.ecf.remoteservice.client.IRemoteCallable;
Lines 23-35 Link Here
23
	public static final int STRING_REQUEST_ENTITY = 1;
24
	public static final int STRING_REQUEST_ENTITY = 1;
24
	public static final int BYTEARRAY_REQUEST_ENTITY = 2;
25
	public static final int BYTEARRAY_REQUEST_ENTITY = 2;
25
	public static final int FILE_REQUEST_ENTITY = 3;
26
	public static final int FILE_REQUEST_ENTITY = 3;
27
	public static final long CONTENT_LENGTH_AUTO = -2;
26
28
27
	public static final String CHARSET_PARAM_NAME = "charset"; //$NON-NLS-1$
29
	public static final String CHARSET_PARAM_NAME = "charset"; //$NON-NLS-1$
28
	public static final String CONTENT_TYPE_PARAM_NAME = "contentType"; //$NON-NLS-1$
30
	public static final String CONTENT_TYPE_PARAM_NAME = "contentType"; //$NON-NLS-1$
29
	public static final String CONTENT_LENGTH_PARAM_NAME = "contentLength"; //$NON-NLS-1$
31
	public static final String CONTENT_LENGTH_PARAM_NAME = "contentLength"; //$NON-NLS-1$
30
32
31
	protected int requestEntityType = NO_REQUEST_ENTITY;
33
	protected int requestEntityType = NO_REQUEST_ENTITY;
32
	protected long defaultContentLength = InputStreamRequestEntity.CONTENT_LENGTH_AUTO;
34
	protected long defaultContentLength = AbstractEntityRequestType.CONTENT_LENGTH_AUTO;
33
	protected String defaultContentType = null;
35
	protected String defaultContentType = null;
34
	protected String defaultCharset = null;
36
	protected String defaultCharset = null;
35
37
Lines 54-60 public AbstractEntityRequestType(int requestEntityType, String defaultContentTyp Link Here
54
	}
56
	}
55
57
56
	public AbstractEntityRequestType(int requestEntityType, String defaultContentType, Map defaultRequestHeaders) {
58
	public AbstractEntityRequestType(int requestEntityType, String defaultContentType, Map defaultRequestHeaders) {
57
		this(requestEntityType, defaultContentType, InputStreamRequestEntity.CONTENT_LENGTH_AUTO, null, defaultRequestHeaders);
59
		this(requestEntityType, defaultContentType, AbstractEntityRequestType.CONTENT_LENGTH_AUTO, null, defaultRequestHeaders);
58
	}
60
	}
59
61
60
	public AbstractEntityRequestType(int requestEntityType, String defaultContentType) {
62
	public AbstractEntityRequestType(int requestEntityType, String defaultContentType) {
Lines 77-95 public boolean useRequestEntity() { Link Here
77
		return requestEntityType > -1;
79
		return requestEntityType > -1;
78
	}
80
	}
79
81
80
	public RequestEntity generateRequestEntity(String uri, IRemoteCall call, IRemoteCallable callable, IRemoteCallParameter paramDefault, Object paramToSerialize) throws NotSerializableException {
82
	public HttpEntity generateRequestEntity(String uri, IRemoteCall call, IRemoteCallable callable, IRemoteCallParameter paramDefault, Object paramToSerialize) throws NotSerializableException {
81
		if (paramToSerialize instanceof RequestEntity)
83
		if (paramToSerialize instanceof HttpEntity)
82
			return (RequestEntity) paramToSerialize;
84
			return (HttpEntity) paramToSerialize;
83
		switch (requestEntityType) {
85
		switch (requestEntityType) {
84
			case INPUT_STREAM_REQUEST_ENTITY :
86
			case INPUT_STREAM_REQUEST_ENTITY :
85
				if (paramToSerialize instanceof InputStream) {
87
				if (paramToSerialize instanceof InputStream) {
86
					return new InputStreamRequestEntity((InputStream) paramToSerialize, getContentLength(call, callable, paramDefault), getContentType(call, callable, paramDefault));
88
					return new InputStreamEntity((InputStream) paramToSerialize, getContentLength(call, callable, paramDefault));
87
				}
89
				}
88
				throw new NotSerializableException("Cannot generate request entity.  Expecting InputStream and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
90
				throw new NotSerializableException("Cannot generate request entity.  Expecting InputStream and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
89
			case STRING_REQUEST_ENTITY :
91
			case STRING_REQUEST_ENTITY :
90
				if (paramToSerialize instanceof String) {
92
				if (paramToSerialize instanceof String) {
91
					try {
93
					try {
92
						return new StringRequestEntity((String) paramToSerialize, getContentType(call, callable, paramDefault), getCharset(call, callable, paramDefault));
94
						return new StringEntity((String) paramToSerialize, getContentType(call, callable, paramDefault), getCharset(call, callable, paramDefault));
93
					} catch (UnsupportedEncodingException e) {
95
					} catch (UnsupportedEncodingException e) {
94
						throw new NotSerializableException("Could not create request entity from call parameters: " + e.getMessage()); //$NON-NLS-1$
96
						throw new NotSerializableException("Could not create request entity from call parameters: " + e.getMessage()); //$NON-NLS-1$
95
					}
97
					}
Lines 97-108 public RequestEntity generateRequestEntity(String uri, IRemoteCall call, IRemote Link Here
97
				throw new NotSerializableException("Cannot generate request entity.  Expecting String and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
99
				throw new NotSerializableException("Cannot generate request entity.  Expecting String and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
98
			case BYTEARRAY_REQUEST_ENTITY :
100
			case BYTEARRAY_REQUEST_ENTITY :
99
				if (paramToSerialize instanceof byte[]) {
101
				if (paramToSerialize instanceof byte[]) {
100
					return new ByteArrayRequestEntity((byte[]) paramToSerialize, getContentType(call, callable, paramDefault));
102
					return new ByteArrayEntity((byte[]) paramToSerialize);
101
				}
103
				}
102
				throw new NotSerializableException("Cannot generate request entity.  Expecting byte[] and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
104
				throw new NotSerializableException("Cannot generate request entity.  Expecting byte[] and got class=" + paramToSerialize.getClass().getName()); //$NON-NLS-1$
103
			case FILE_REQUEST_ENTITY :
105
			case FILE_REQUEST_ENTITY :
104
				if (paramToSerialize instanceof File) {
106
				if (paramToSerialize instanceof File) {
105
					return new FileRequestEntity((File) paramToSerialize, getContentType(call, callable, paramDefault));
107
					return new FileEntity((File) paramToSerialize, getContentType(call, callable, paramDefault));
106
				}
108
				}
107
				throw new NotSerializableException("Remote call parameter with name=" + paramDefault.getName() + " is incorrect type for creating request entity."); //$NON-NLS-1$ //$NON-NLS-2$
109
				throw new NotSerializableException("Remote call parameter with name=" + paramDefault.getName() + " is incorrect type for creating request entity."); //$NON-NLS-1$ //$NON-NLS-2$
108
			default :
110
			default :
Lines 139-145 protected long getContentLength(IRemoteCall call, IRemoteCallable callable, IRem Link Here
139
						try {
141
						try {
140
							return Integer.parseInt((String) o);
142
							return Integer.parseInt((String) o);
141
						} catch (NumberFormatException e) {
143
						} catch (NumberFormatException e) {
142
							return InputStreamRequestEntity.CONTENT_LENGTH_AUTO;
144
							return AbstractEntityRequestType.CONTENT_LENGTH_AUTO;
143
						}
145
						}
144
					}
146
					}
145
				}
147
				}
(-)a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java (-53 / +71 lines)
Lines 9-22 Link Here
9
 *******************************************************************************/
9
 *******************************************************************************/
10
package org.eclipse.ecf.remoteservice.rest.client;
10
package org.eclipse.ecf.remoteservice.rest.client;
11
11
12
import java.io.IOException;
12
import java.io.*;
13
import java.io.NotSerializableException;
14
import java.util.*;
13
import java.util.*;
15
import org.apache.commons.httpclient.*;
14
import org.apache.http.*;
16
import org.apache.commons.httpclient.auth.AuthScope;
15
import org.apache.http.auth.*;
17
import org.apache.commons.httpclient.methods.*;
16
import org.apache.http.client.HttpClient;
18
import org.apache.commons.httpclient.params.HttpClientParams;
17
import org.apache.http.client.entity.UrlEncodedFormEntity;
19
import org.apache.commons.httpclient.params.HttpMethodParams;
18
import org.apache.http.client.methods.*;
19
import org.apache.http.client.params.ClientPNames;
20
import org.apache.http.impl.auth.BasicScheme;
21
import org.apache.http.impl.client.DefaultHttpClient;
22
import org.apache.http.message.AbstractHttpMessage;
23
import org.apache.http.message.BasicNameValuePair;
24
import org.apache.http.params.CoreConnectionPNames;
25
import org.apache.http.params.CoreProtocolPNames;
20
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Status;
27
import org.eclipse.core.runtime.Status;
22
import org.eclipse.ecf.core.security.*;
28
import org.eclipse.ecf.core.security.*;
Lines 39-54 Link Here
39
45
40
	protected final static String DEFAULT_HTTP_CONTENT_CHARSET = "UTF-8"; //$NON-NLS-1$
46
	protected final static String DEFAULT_HTTP_CONTENT_CHARSET = "UTF-8"; //$NON-NLS-1$
41
47
48
	private static final String CONNECTION_MANAGER_TIMEOUT = "http.connection-manager.timeout"; //$NON-NLS-1$
49
42
	protected HttpClient httpClient;
50
	protected HttpClient httpClient;
43
	protected int responseBufferSize = DEFAULT_RESPONSE_BUFFER_SIZE;
51
	protected int responseBufferSize = DEFAULT_RESPONSE_BUFFER_SIZE;
44
52
45
	public RestClientService(RestClientContainer container, RemoteServiceClientRegistration registration) {
53
	public RestClientService(RestClientContainer container, RemoteServiceClientRegistration registration) {
46
		super(container, registration);
54
		super(container, registration);
47
		this.httpClient = new HttpClient();
55
		this.httpClient = new DefaultHttpClient();
48
	}
56
	}
49
57
50
	private boolean isResponseOk(int httpResponseCode) {
58
	private boolean isResponseOk(HttpResponse response) {
51
		int isOkCode = httpResponseCode - 200;
59
		int isOkCode = response.getStatusLine().getStatusCode() - 200;
52
		return (isOkCode >= 0 && isOkCode < 100);
60
		return (isOkCode >= 0 && isOkCode < 100);
53
	}
61
	}
54
62
Lines 65-108 private boolean isResponseOk(int httpResponseCode) { Link Here
65
	 */
73
	 */
66
	protected Object invokeRemoteCall(final IRemoteCall call, final IRemoteCallable callable) throws ECFException {
74
	protected Object invokeRemoteCall(final IRemoteCall call, final IRemoteCallable callable) throws ECFException {
67
		String uri = prepareEndpointAddress(call, callable);
75
		String uri = prepareEndpointAddress(call, callable);
68
		HttpMethod httpMethod = createAndPrepareHttpMethod(uri, call, callable);
76
		HttpRequestBase httpMethod = createAndPrepareHttpMethod(uri, call, callable);
69
		// execute method
77
		// execute method
70
		byte[] responseBody = null;
78
		byte[] responseBody = null;
71
		int responseCode = -1;
79
		int responseCode = 500;
80
		HttpResponse response = null;
72
		try {
81
		try {
73
			responseCode = httpClient.executeMethod(httpMethod);
82
			response = httpClient.execute(httpMethod);
74
			if (isResponseOk(responseCode)) {
83
			responseCode = response.getStatusLine().getStatusCode();
84
			if (isResponseOk(response)) {
75
				// Get responseBody as String
85
				// Get responseBody as String
76
				responseBody = getResponseAsBytes(httpMethod);
86
				responseBody = getResponseAsBytes(response);
77
			} else {
87
			} else {
78
				// If this method returns true, we should retrieve the response body
88
				// If this method returns true, we should retrieve the response body
79
				if (retrieveErrorResponseBody(responseCode)) {
89
				if (retrieveErrorResponseBody(response)) {
80
					responseBody = getResponseAsBytes(httpMethod);
90
					responseBody = getResponseAsBytes(response);
81
				}
91
				}
82
				// Now pass to the exception handler
92
				// Now pass to the exception handler
83
				handleException("Http response not OK.  URL=" + uri + " responseCode=" + new Integer(responseCode), null, responseCode, responseBody); //$NON-NLS-1$ //$NON-NLS-2$
93
				handleException("Http response not OK.  URL=" + uri + " responseCode=" + new Integer(responseCode), null, responseCode, responseBody); //$NON-NLS-1$ //$NON-NLS-2$
84
			}
94
			}
85
		} catch (HttpException e) {
86
			handleException("Transport HttpException", e, responseCode); //$NON-NLS-1$
87
		} catch (IOException e) {
95
		} catch (IOException e) {
88
			handleException("Transport IOException", e, responseCode); //$NON-NLS-1$
96
			handleException("Transport IOException", e, responseCode); //$NON-NLS-1$
89
		}
97
		}
90
		Object result = null;
98
		Object result = null;
91
		try {
99
		try {
92
			result = processResponse(uri, call, callable, convertResponseHeaders(httpMethod.getResponseHeaders()), responseBody);
100
			result = processResponse(uri, call, callable, convertResponseHeaders(response.getAllHeaders()), responseBody);
93
		} catch (NotSerializableException e) {
101
		} catch (NotSerializableException e) {
94
			handleException("Exception deserializing response.  URL=" + uri + " responseCode=" + new Integer(responseCode), e, responseCode); //$NON-NLS-1$ //$NON-NLS-2$
102
			handleException("Exception deserializing response.  URL=" + uri + " responseCode=" + new Integer(responseCode), e, responseCode); //$NON-NLS-1$ //$NON-NLS-2$
95
		}
103
		}
96
		return result;
104
		return result;
97
	}
105
	}
98
106
99
	protected boolean retrieveErrorResponseBody(int responseCode) {
107
	protected boolean retrieveErrorResponseBody(HttpResponse response) {
100
		// XXX this needs to be defined differently for 
108
		// XXX this needs to be defined differently for 
101
		return false;
109
		return false;
102
	}
110
	}
103
111
104
	protected byte[] getResponseAsBytes(HttpMethod httpMethod) throws IOException {
112
	protected byte[] getResponseAsBytes(HttpResponse response) throws IOException {
105
		return httpMethod.getResponseBody();
113
		ByteArrayOutputStream os = new ByteArrayOutputStream();
114
		response.getEntity().writeTo(os);
115
		return os.toByteArray();
106
	}
116
	}
107
117
108
	protected void handleException(String message, Throwable e, int responseCode, byte[] responseBody) throws RestException {
118
	protected void handleException(String message, Throwable e, int responseCode, byte[] responseBody) throws RestException {
Lines 120-128 protected void setupTimeouts(HttpClient httpClient, IRemoteCall call, IRemoteCal Link Here
120
			callTimeout = callable.getDefaultTimeout();
130
			callTimeout = callable.getDefaultTimeout();
121
131
122
		int timeout = (int) callTimeout;
132
		int timeout = (int) callTimeout;
123
		httpClient.getHttpConnectionManager().getParams().setSoTimeout(timeout);
133
		httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
124
		httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
134
		httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
125
		httpClient.getParams().setConnectionManagerTimeout(timeout);
135
		httpClient.getParams().setIntParameter(CONNECTION_MANAGER_TIMEOUT, timeout);
126
	}
136
	}
127
137
128
	private Map convertResponseHeaders(Header[] headers) {
138
	private Map convertResponseHeaders(Header[] headers) {
Lines 137-143 private Map convertResponseHeaders(Header[] headers) { Link Here
137
		return result;
147
		return result;
138
	}
148
	}
139
149
140
	protected void addRequestHeaders(HttpMethod httpMethod, IRemoteCall call, IRemoteCallable callable) {
150
	protected void addRequestHeaders(AbstractHttpMessage httpMethod, IRemoteCall call, IRemoteCallable callable) {
141
		// Add request headers from the callable
151
		// Add request headers from the callable
142
		Map requestHeaders = (callable.getRequestType() instanceof AbstractRequestType) ? ((AbstractRequestType) callable.getRequestType()).getDefaultRequestHeaders() : new HashMap();
152
		Map requestHeaders = (callable.getRequestType() instanceof AbstractRequestType) ? ((AbstractRequestType) callable.getRequestType()).getDefaultRequestHeaders() : new HashMap();
143
		if (requestHeaders == null)
153
		if (requestHeaders == null)
Lines 154-165 protected void addRequestHeaders(HttpMethod httpMethod, IRemoteCall call, IRemot Link Here
154
		for (int i = 0; i < headers.length; i++) {
164
		for (int i = 0; i < headers.length; i++) {
155
			String key = (String) headers[i];
165
			String key = (String) headers[i];
156
			String value = (String) requestHeaders.get(key);
166
			String value = (String) requestHeaders.get(key);
157
			httpMethod.addRequestHeader(key, value);
167
			httpMethod.addHeader(key, value);
158
		}
168
		}
159
	}
169
	}
160
170
161
	protected HttpMethod createAndPrepareHttpMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws RestException {
171
	protected HttpRequestBase createAndPrepareHttpMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws RestException {
162
		HttpMethod httpMethod = null;
172
		HttpRequestBase httpMethod = null;
163
173
164
		IRemoteCallableRequestType requestType = callable.getRequestType();
174
		IRemoteCallableRequestType requestType = callable.getRequestType();
165
		if (requestType == null)
175
		if (requestType == null)
Lines 180-193 protected HttpMethod createAndPrepareHttpMethod(String uri, IRemoteCall call, IR Link Here
180
			String message = "Could not serialize parameters for uri=" + uri + " call=" + call + " callable=" + callable; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
190
			String message = "Could not serialize parameters for uri=" + uri + " call=" + call + " callable=" + callable; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
181
			logException(message, e);
191
			logException(message, e);
182
			throw new RestException(message);
192
			throw new RestException(message);
193
		} catch (UnsupportedEncodingException e) {
194
			String message = "Could not serialize parameters for uri=" + uri + " call=" + call + " callable=" + callable; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
195
			logException(message, e);
196
			throw new RestException(message);
183
		}
197
		}
184
		// add additional request headers
198
		// add additional request headers
185
		addRequestHeaders(httpMethod, call, callable);
199
		addRequestHeaders(httpMethod, call, callable);
186
		// handle authentication
200
		// handle authentication
187
		setupAuthenticaton(httpClient, httpMethod);
201
		setupAuthenticaton(httpClient, httpMethod);
188
		// needed because a resource can link to another resource
202
		// needed because a resource can link to another resource
189
		httpClient.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, new Boolean(true));
203
		httpClient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, new Boolean(true));
190
		httpClient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, DEFAULT_HTTP_CONTENT_CHARSET);
204
		httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, DEFAULT_HTTP_CONTENT_CHARSET);
191
		setupTimeouts(httpClient, call, callable);
205
		setupTimeouts(httpClient, call, callable);
192
		return httpMethod;
206
		return httpMethod;
193
	}
207
	}
Lines 195-206 protected HttpMethod createAndPrepareHttpMethod(String uri, IRemoteCall call, IR Link Here
195
	/**
209
	/**
196
	 * @throws RestException  
210
	 * @throws RestException  
197
	 */
211
	 */
198
	protected HttpMethod prepareDeleteMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws RestException {
212
	protected HttpRequestBase prepareDeleteMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws RestException {
199
		return new DeleteMethod(uri);
213
		return new HttpDelete(uri);
200
	}
214
	}
201
215
202
	protected HttpMethod preparePutMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws NotSerializableException {
216
	protected HttpRequestBase preparePutMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws NotSerializableException, UnsupportedEncodingException {
203
		PutMethod result = new PutMethod(uri);
217
		HttpPut result = new HttpPut(uri);
204
		HttpPutRequestType putRequestType = (HttpPutRequestType) callable.getRequestType();
218
		HttpPutRequestType putRequestType = (HttpPutRequestType) callable.getRequestType();
205
219
206
		IRemoteCallParameter[] defaultParameters = callable.getDefaultParameters();
220
		IRemoteCallParameter[] defaultParameters = callable.getDefaultParameters();
Lines 208-242 protected HttpMethod preparePutMethod(String uri, IRemoteCall call, IRemoteCalla Link Here
208
222
209
		if (putRequestType.useRequestEntity()) {
223
		if (putRequestType.useRequestEntity()) {
210
			if (defaultParameters != null && defaultParameters.length > 0 && parameters != null && parameters.length > 0) {
224
			if (defaultParameters != null && defaultParameters.length > 0 && parameters != null && parameters.length > 0) {
211
				RequestEntity requestEntity = putRequestType.generateRequestEntity(uri, call, callable, defaultParameters[0], parameters[0]);
225
				HttpEntity requestEntity = putRequestType.generateRequestEntity(uri, call, callable, defaultParameters[0], parameters[0]);
212
				result.setRequestEntity(requestEntity);
226
				result.setEntity(requestEntity);
213
			}
227
			}
214
		} else {
228
		} else {
215
			NameValuePair[] params = toNameValuePairs(uri, call, callable);
229
			NameValuePair[] params = toNameValuePairs(uri, call, callable);
216
			if (params != null)
230
			if (params != null) {
217
				result.setQueryString(params);
231
				result.setEntity(new UrlEncodedFormEntity(Arrays.asList(params)));
232
			}
218
		}
233
		}
219
		return result;
234
		return result;
220
	}
235
	}
221
236
222
	/**
237
	/**
238
	 * @throws UnsupportedEncodingException 
223
	 * @throws ECFException  
239
	 * @throws ECFException  
224
	 */
240
	 */
225
	protected HttpMethod preparePostMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws NotSerializableException {
241
	protected HttpRequestBase preparePostMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws NotSerializableException, UnsupportedEncodingException {
226
		PostMethod result = new PostMethod(uri);
242
		HttpPost result = new HttpPost(uri);
227
		HttpPostRequestType postRequestType = (HttpPostRequestType) callable.getRequestType();
243
		HttpPostRequestType postRequestType = (HttpPostRequestType) callable.getRequestType();
228
244
229
		IRemoteCallParameter[] defaultParameters = callable.getDefaultParameters();
245
		IRemoteCallParameter[] defaultParameters = callable.getDefaultParameters();
230
		Object[] parameters = call.getParameters();
246
		Object[] parameters = call.getParameters();
231
		if (postRequestType.useRequestEntity()) {
247
		if (postRequestType.useRequestEntity()) {
232
			if (defaultParameters != null && defaultParameters.length > 0 && parameters != null && parameters.length > 0) {
248
			if (defaultParameters != null && defaultParameters.length > 0 && parameters != null && parameters.length > 0) {
233
				RequestEntity requestEntity = postRequestType.generateRequestEntity(uri, call, callable, defaultParameters[0], parameters[0]);
249
				HttpEntity requestEntity = postRequestType.generateRequestEntity(uri, call, callable, defaultParameters[0], parameters[0]);
234
				result.setRequestEntity(requestEntity);
250
				result.setEntity(requestEntity);
235
			}
251
			}
236
		} else {
252
		} else {
237
			NameValuePair[] params = toNameValuePairs(uri, call, callable);
253
			NameValuePair[] params = toNameValuePairs(uri, call, callable);
238
			if (params != null)
254
			if (params != null)
239
				result.setQueryString(params);
255
				result.setEntity(new UrlEncodedFormEntity(Arrays.asList(params)));
240
		}
256
		}
241
		return result;
257
		return result;
242
	}
258
	}
Lines 244-254 protected HttpMethod preparePostMethod(String uri, IRemoteCall call, IRemoteCall Link Here
244
	/**
260
	/**
245
	 * @throws ECFException  
261
	 * @throws ECFException  
246
	 */
262
	 */
247
	protected HttpMethod prepareGetMethod(String uri, IRemoteCall call, IRemoteCallable callable) throws NotSerializableException {
263
	protected HttpRequestBase prepareGetMethod(String uri, IRemoteCall call, IRemoteCallable callable) {
248
		HttpMethod result = new GetMethod(uri);
264
		HttpRequestBase result = new HttpGet(uri);
265
		/**
266
		 * FIXME: is this still supported in httpclient 4.0?
249
		NameValuePair[] params = toNameValuePairs(uri, call, callable);
267
		NameValuePair[] params = toNameValuePairs(uri, call, callable);
250
		if (params != null)
268
		if (params != null)
251
			result.setQueryString(params);
269
			result.setQueryString(params);
270
		**/
252
		return result;
271
		return result;
253
	}
272
	}
254
273
Lines 265-278 protected HttpMethod prepareGetMethod(String uri, IRemoteCall call, IRemoteCalla Link Here
265
					parameterValue = o.toString();
284
					parameterValue = o.toString();
266
				}
285
				}
267
				if (parameterValue != null) {
286
				if (parameterValue != null) {
268
					nameValueList.add(new NameValuePair(restParameters[i].getName(), parameterValue));
287
					nameValueList.add(new BasicNameValuePair(restParameters[i].getName(), parameterValue));
269
				}
288
				}
270
			}
289
			}
271
		}
290
		}
272
		return (NameValuePair[]) nameValueList.toArray(new NameValuePair[nameValueList.size()]);
291
		return (NameValuePair[]) nameValueList.toArray(new NameValuePair[nameValueList.size()]);
273
	}
292
	}
274
293
275
	protected void setupAuthenticaton(HttpClient httpClient, HttpMethod method) {
294
	protected void setupAuthenticaton(HttpClient httpClient, HttpRequestBase method) {
276
		IConnectContext connectContext = container.getConnectContextForAuthentication();
295
		IConnectContext connectContext = container.getConnectContextForAuthentication();
277
		if (connectContext != null) {
296
		if (connectContext != null) {
278
			NameCallback nameCallback = new NameCallback(""); //$NON-NLS-1$
297
			NameCallback nameCallback = new NameCallback(""); //$NON-NLS-1$
Lines 285-298 protected void setupAuthenticaton(HttpClient httpClient, HttpMethod method) { Link Here
285
				callbackHandler.handle(callbacks);
304
				callbackHandler.handle(callbacks);
286
				String username = nameCallback.getName();
305
				String username = nameCallback.getName();
287
				String password = (String) passwordCallback.getObject();
306
				String password = (String) passwordCallback.getObject();
288
				AuthScope authscope = new AuthScope(null, -1);
289
				Credentials credentials = new UsernamePasswordCredentials(username, password);
307
				Credentials credentials = new UsernamePasswordCredentials(username, password);
290
				httpClient.getState().setCredentials(authscope, credentials);
308
				method.addHeader(new BasicScheme().authenticate(credentials, method));
291
				method.setDoAuthentication(true);
292
			} catch (IOException e) {
309
			} catch (IOException e) {
293
				logException("IOException setting credentials for rest httpclient", e); //$NON-NLS-1$
310
				logException("IOException setting credentials for rest httpclient", e); //$NON-NLS-1$
294
			} catch (UnsupportedCallbackException e) {
311
			} catch (UnsupportedCallbackException e) {
295
				logException("UnsupportedCallbackException setting credentials for rest httpclient", e); //$NON-NLS-1$
312
				logException("UnsupportedCallbackException setting credentials for rest httpclient", e); //$NON-NLS-1$
313
			} catch (AuthenticationException e) {
314
				logException("AuthenticationException setting credentials for rest httpclient", e); //$NON-NLS-1$
296
			}
315
			}
297
316
298
		}
317
		}
299
- 

Return to bug 403675