diff options
Diffstat (limited to 'connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestValidateRequest.java')
-rw-r--r-- | connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestValidateRequest.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestValidateRequest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestValidateRequest.java index 407b32244..3d67b3f1a 100644 --- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestValidateRequest.java +++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestValidateRequest.java @@ -12,12 +12,15 @@ package org.eclipse.mylyn.internal.bugzilla.rest.core; import java.io.IOException; +import java.io.InputStreamReader; import org.apache.http.HttpStatus; import org.eclipse.mylyn.commons.core.operations.IOperationMonitor; import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpResponse; import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.ErrorResponse; +import com.google.common.io.CharStreams; +import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; public class BugzillaRestValidateRequest extends BugzillaRestAuthenticatedGetRequest<ErrorResponse> { @@ -28,12 +31,29 @@ public class BugzillaRestValidateRequest extends BugzillaRestAuthenticatedGetReq } @Override - protected void doValidate(CommonHttpResponse response, IOperationMonitor monitor) throws IOException, - BugzillaRestException { + protected void doValidate(CommonHttpResponse response, IOperationMonitor monitor) + throws IOException, BugzillaRestException { // since 4.5.5 we get an HttpStatus.SC_NOT_FOUND instead of an HttpStatus.SC_BAD_REQUEST validate(response, response.getStatusCode() == HttpStatus.SC_NOT_FOUND ? HttpStatus.SC_NOT_FOUND : HttpStatus.SC_BAD_REQUEST, monitor); } + @Override + protected ErrorResponse parseFromJson(InputStreamReader in) throws BugzillaRestException { + String jsonString; + try { + jsonString = CharStreams.toString(in); + } catch (IOException e) { + throw new BugzillaRestException(e); + } + if (jsonString.startsWith("{\"result\":{")) { //$NON-NLS-1$ + jsonString = jsonString.substring(10, jsonString.length() - 1); + } + + TypeToken<ErrorResponse> a = new TypeToken<ErrorResponse>() { + }; + return new Gson().fromJson(jsonString, a.getType()); + } + } |