Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2014-12-05 15:39:26 +0000
committerslewis2014-12-05 15:39:26 +0000
commit992547a678f2018a586d91ff476266e4123043eb (patch)
treef14c0f15407822d8079e879295f678c29bee5b40
parent319dee4bc2efe176872dbd3c44df8d44ce2571e2 (diff)
downloadorg.eclipse.ecf-992547a678f2018a586d91ff476266e4123043eb.tar.gz
org.eclipse.ecf-992547a678f2018a586d91ff476266e4123043eb.tar.xz
org.eclipse.ecf-992547a678f2018a586d91ff476266e4123043eb.zip
Small update to complete RestClientService
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF1
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java61
2 files changed, 44 insertions, 18 deletions
diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF
index cb3cbb55d..c4fa3c94e 100644
--- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF
@@ -17,6 +17,7 @@ Export-Package: org.eclipse.ecf.internal.remoteservice.rest;x-internal:=true,
Import-Package: org.apache.http;version="4.3",
org.apache.http.auth;version="4.3",
org.apache.http.client;version="4.3",
+ org.apache.http.client.config;version="4.3",
org.apache.http.client.entity;version="4.3",
org.apache.http.client.methods;version="4.3",
org.apache.http.client.params;version="4.3",
diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java
index 1f22054dd..97bee6e0b 100644
--- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java
+++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java
@@ -16,16 +16,14 @@ import java.util.*;
import org.apache.http.*;
import org.apache.http.auth.*;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
-import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.AbstractHttpMessage;
import org.apache.http.message.BasicNameValuePair;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.security.*;
@@ -46,12 +44,14 @@ import org.eclipse.ecf.remoteservice.rest.RestException;
*/
public class RestClientService extends AbstractClientService {
+ public static final int socketTimeout = Integer.valueOf(System.getProperty("org.eclipse.ecf.remoteservice.rest.RestClientService.socketTimeout", "-1")).intValue(); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final int connectRequestTimeout = Integer.valueOf(System.getProperty("org.eclipse.ecf.remoteservice.rest.RestClientService.connectRequestTimeout", "-1")).intValue(); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final int connectTimeout = Integer.valueOf(System.getProperty("org.eclipse.ecf.remoteservice.rest.RestClientService.connectTimeout", "-1")).intValue(); //$NON-NLS-1$ //$NON-NLS-2$
+
protected final static int DEFAULT_RESPONSE_BUFFER_SIZE = 1024;
protected final static String DEFAULT_HTTP_CONTENT_CHARSET = "UTF-8"; //$NON-NLS-1$
- private static final String CONNECTION_MANAGER_TIMEOUT = "http.connection-manager.timeout"; //$NON-NLS-1$
-
protected HttpClient httpClient;
protected int responseBufferSize = DEFAULT_RESPONSE_BUFFER_SIZE;
@@ -139,15 +139,11 @@ public class RestClientService extends AbstractClientService {
handleException(message, e, responseCode, null);
}
+ /*
+ * @deprecated
+ */
protected void setupTimeouts(HttpClient httpClient, IRemoteCall call, IRemoteCallable callable) {
- long callTimeout = call.getTimeout();
- if (callTimeout == IRemoteCall.DEFAULT_TIMEOUT)
- callTimeout = callable.getDefaultTimeout();
-
- int timeout = (int) callTimeout;
- httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
- httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
- httpClient.getParams().setIntParameter(CONNECTION_MANAGER_TIMEOUT, timeout);
+ // No longer used
}
private Map convertResponseHeaders(Header[] headers) {
@@ -210,15 +206,44 @@ public class RestClientService extends AbstractClientService {
logException(message, e);
throw new RestException(message);
}
+
+ prepareHttpMethod(httpMethod, call, callable);
+ return httpMethod;
+ }
+
+ protected void prepareHttpMethod(HttpRequestBase httpMethod, IRemoteCall call, IRemoteCallable callable) {
// add additional request headers
addRequestHeaders(httpMethod, call, callable);
// handle authentication
setupAuthenticaton(httpClient, httpMethod);
- // needed because a resource can link to another resource
- httpClient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, new Boolean(true));
- httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, DEFAULT_HTTP_CONTENT_CHARSET);
- setupTimeouts(httpClient, call, callable);
- return httpMethod;
+ // setup http method config (redirects, timesouts, etc)
+ setupHttpMethod(httpMethod, call, callable);
+ }
+
+ protected void setupHttpMethod(HttpRequestBase httpMethod, IRemoteCall call, IRemoteCallable callable) {
+
+ RequestConfig defaultRequestConfig = httpMethod.getConfig();
+ RequestConfig.Builder updatedRequestConfigBuilder = (defaultRequestConfig == null) ? RequestConfig.custom() : RequestConfig.copy(defaultRequestConfig);
+ // setup to allow regular and circular redirects
+ updatedRequestConfigBuilder.setCircularRedirectsAllowed(true);
+ updatedRequestConfigBuilder.setRedirectsEnabled(true);
+
+ int sTimeout = socketTimeout;
+ int scTimeout = connectTimeout;
+ int scrTimeout = connectRequestTimeout;
+
+ long callTimeout = call.getTimeout();
+ if (callTimeout == IRemoteCall.DEFAULT_TIMEOUT)
+ callTimeout = callable.getDefaultTimeout();
+
+ if (callTimeout != IRemoteCall.DEFAULT_TIMEOUT) {
+ sTimeout = scTimeout = scrTimeout = new Long(callTimeout).intValue();
+ }
+ updatedRequestConfigBuilder.setSocketTimeout(sTimeout);
+ updatedRequestConfigBuilder.setConnectTimeout(scTimeout);
+ updatedRequestConfigBuilder.setConnectionRequestTimeout(scrTimeout);
+
+ httpMethod.setConfig(updatedRequestConfigBuilder.build());
}
/**

Back to the top