From 04155492bbc640d666e05df2eb828bbf2d0856cb Mon Sep 17 00:00:00 2001 From: psytester Date: Thu, 22 Feb 2018 11:36:12 +0100 Subject: [PATCH 1/3] invokeAPI() --> ApiException() if non HTTP 200 There was no error indication in case the restapi request gets back a non HTTP 200 code, e.g. HTTP 400 / 401 / 403 / .... --- src/main/java/com/docusign/esign/client/ApiClient.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/docusign/esign/client/ApiClient.java b/src/main/java/com/docusign/esign/client/ApiClient.java index 7c5beba5..ba408e49 100644 --- a/src/main/java/com/docusign/esign/client/ApiClient.java +++ b/src/main/java/com/docusign/esign/client/ApiClient.java @@ -22,6 +22,7 @@ import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.MediaType; @@ -746,6 +747,10 @@ public T invokeAPI(String path, String method, List queryParams, Objec ClientResponse response = getAPIResponse(path, method, queryParams, body, headerParams, formParams, accept, contentType, authNames); + if (response.getStatusInfo().getStatusCode() != Status.OK.getStatusCode()) { + throw new ApiException("Error while requesting server, received HTTP code: "+ response.getStatusInfo().getStatusCode() + " / with response Body: " + response.getEntity(String.class)); + } + statusCode = response.getStatusInfo().getStatusCode(); responseHeaders = response.getHeaders(); From 025fcd20b111401f11bc5dfca3c7ae283046da7a Mon Sep 17 00:00:00 2001 From: psytester Date: Mon, 19 Mar 2018 14:49:15 +0100 Subject: [PATCH 2/3] invokeAPI check against Family.SUCCESSFUL I changed the the check against Family.SUCCESSFUL to catch all 2xx HTTP codes, the 201 Created, too. According to DocuSign API it should be sufficient to detect successful cases. Why I throw this exception to indicate a bad server response: If we exit the method at line 757 or 760 with "return null;" we can not react on upper level in our application side based on HTTP code. No indication is possible what's going wrong in that api call. If this is not what you asked, please give me a hint ;-) --- src/main/java/com/docusign/esign/client/ApiClient.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/docusign/esign/client/ApiClient.java b/src/main/java/com/docusign/esign/client/ApiClient.java index ba408e49..912a76b0 100644 --- a/src/main/java/com/docusign/esign/client/ApiClient.java +++ b/src/main/java/com/docusign/esign/client/ApiClient.java @@ -22,7 +22,6 @@ import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; import org.apache.oltu.oauth2.common.exception.OAuthSystemException; -import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.MediaType; @@ -747,8 +746,8 @@ public T invokeAPI(String path, String method, List queryParams, Objec ClientResponse response = getAPIResponse(path, method, queryParams, body, headerParams, formParams, accept, contentType, authNames); - if (response.getStatusInfo().getStatusCode() != Status.OK.getStatusCode()) { - throw new ApiException("Error while requesting server, received HTTP code: "+ response.getStatusInfo().getStatusCode() + " / with response Body: " + response.getEntity(String.class)); + if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { + throw new ApiException("Error while requesting server, received HTTP code: " + response.getStatusInfo().getStatusCode() + " / with response Body: " + response.getEntity(String.class)); } statusCode = response.getStatusInfo().getStatusCode(); From 56eb79dd036c4f2c0cdde66c5ee5c7b14121cffd Mon Sep 17 00:00:00 2001 From: psytester Date: Tue, 20 Mar 2018 14:43:45 +0100 Subject: [PATCH 3/3] incorporated PR62 into this PR Just in case the last change for non HTTP 2xx handling will be rejected once more and not to loose the latest changes, I added the setReadTimeout code from PR62 --- .../com/docusign/esign/client/ApiClient.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/docusign/esign/client/ApiClient.java b/src/main/java/com/docusign/esign/client/ApiClient.java index 912a76b0..071a8428 100644 --- a/src/main/java/com/docusign/esign/client/ApiClient.java +++ b/src/main/java/com/docusign/esign/client/ApiClient.java @@ -57,6 +57,7 @@ public class ApiClient { private String basePath = "https://www.docusign.net/restapi"; private boolean debugging = false; private int connectionTimeout = 0; + private int readTimeout = 0; private Client httpClient; private ObjectMapper mapper; @@ -320,6 +321,24 @@ public ApiClient setConnectTimeout(int connectionTimeout) { return this; } + /** + * Read timeout (in milliseconds). + */ + public int getReadTimeout() { + return readTimeout; + } + + /** + * Set the read timeout (in milliseconds). + * A value of 0 means no timeout, otherwise values must be between 1 and + * {@link Integer#MAX_VALUE}. + */ + public ApiClient setReadTimeout(int readTimeout) { + this.readTimeout = readTimeout; + httpClient.setReadTimeout(readTimeout); + return this; + } + /** * Get the date format used to parse/format date parameters. */