Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2011-10-26 23:58:16 +0000
committerslewis2011-10-26 23:58:16 +0000
commitda1c6969562414700956a65a363d4dca0708f2cf (patch)
tree9b803ae92d2eb7867eb6c213688eb6c1a8aa9549
parent365395fede158e6b8598ad4a5647875ccc373624 (diff)
downloadorg.eclipse.ecf-da1c6969562414700956a65a363d4dca0708f2cf.tar.gz
org.eclipse.ecf-da1c6969562414700956a65a363d4dca0708f2cf.tar.xz
org.eclipse.ecf-da1c6969562414700956a65a363d4dca0708f2cf.zip
Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=361933
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice.rest/META-INF/MANIFEST.MF2
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/RestException.java11
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/client/RestClientService.java43
3 files changed, 43 insertions, 13 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 668eba2d6..6d3f35226 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
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-Vendor: %plugin.provider
Bundle-SymbolicName: org.eclipse.ecf.remoteservice.rest;singleton:=true
-Bundle-Version: 2.1.0.qualifier
+Bundle-Version: 2.2.100.qualifier
Bundle-Activator: org.eclipse.ecf.internal.remoteservice.rest.Activator
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: global
diff --git a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/RestException.java b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/RestException.java
index 14e16878b..a90471a21 100644
--- a/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/RestException.java
+++ b/framework/bundles/org.eclipse.ecf.remoteservice.rest/src/org/eclipse/ecf/remoteservice/rest/RestException.java
@@ -16,6 +16,7 @@ public class RestException extends ECFException {
private static final long serialVersionUID = -6565657473114300609L;
private int errorCode = -1;
+ private String response = null;
public RestException(IStatus status) {
super(status);
@@ -57,7 +58,17 @@ public class RestException extends ECFException {
this.errorCode = errorCode;
}
+ public RestException(String message, Throwable cause, int errorCode, String response) {
+ super(message, cause);
+ this.errorCode = errorCode;
+ this.response = response;
+ }
+
public int getErrorCode() {
return errorCode;
}
+
+ public String getResponseBody() {
+ return response;
+ }
}
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 9d56db918..118ec23c7 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
@@ -73,17 +73,16 @@ public class RestClientService extends AbstractClientService {
try {
responseCode = httpClient.executeMethod(httpMethod);
if (isResponseOk(responseCode)) {
- // Get response bytes
- byte[] responseBytes = httpMethod.getResponseBody();
- String responseCharSet = null;
- if (httpMethod instanceof HttpMethodBase) {
- HttpMethodBase methodBase = (HttpMethodBase) httpMethod;
- responseCharSet = methodBase.getRequestCharSet();
- }
// Get responseBody as String
- responseBody = getResponseAsString(responseBytes, responseCharSet);
- } else
- handleException("Http response not OK. URL=" + uri + " responseCode=" + new Integer(responseCode), null, responseCode); //$NON-NLS-1$ //$NON-NLS-2$
+ responseBody = getResponseAsString(httpMethod);
+ } else {
+ // If this method returns true, we should retrieve the response body
+ if (retrieveErrorResponseBody(responseCode)) {
+ responseBody = getResponseAsString(httpMethod);
+ }
+ // Now pass to the exception handler
+ handleException("Http response not OK. URL=" + uri + " responseCode=" + new Integer(responseCode), null, responseCode, responseBody); //$NON-NLS-1$ //$NON-NLS-2$
+ }
} catch (HttpException e) {
handleException("Transport HttpException", e, responseCode); //$NON-NLS-1$
} catch (IOException e) {
@@ -98,15 +97,35 @@ public class RestClientService extends AbstractClientService {
return result;
}
+ protected boolean retrieveErrorResponseBody(int responseCode) {
+ // XXX this needs to be defined differently for
+ return false;
+ }
+
+ protected String getResponseAsString(HttpMethod httpMethod) throws IOException {
+ // Get response bytes
+ byte[] responseBytes = httpMethod.getResponseBody();
+ String responseCharSet = null;
+ if (httpMethod instanceof HttpMethodBase) {
+ HttpMethodBase methodBase = (HttpMethodBase) httpMethod;
+ responseCharSet = methodBase.getRequestCharSet();
+ }
+ return getResponseAsString(responseBytes, responseCharSet);
+ }
+
protected String getResponseAsString(byte[] bytes, String responseCharSet) {
if (bytes == null)
return null;
return EncodingUtil.getString(bytes, responseCharSet);
}
- protected void handleException(String message, Throwable e, int responseCode) throws RestException {
+ protected void handleException(String message, Throwable e, int responseCode, String responseBody) throws RestException {
logException(message, e);
- throw new RestException(message, e, responseCode);
+ throw new RestException(message, e, responseCode, responseBody);
+ }
+
+ protected void handleException(String message, Throwable e, int responseCode) throws RestException {
+ handleException(message, e, responseCode, null);
}
protected void setupTimeouts(HttpClient httpClient, IRemoteCall call, IRemoteCallable callable) {

Back to the top