You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by pa...@apache.org on 2020/07/01 05:42:37 UTC
[beam] branch master updated: Bug fix: non 200 response streams are
read twice which cause "Cannot read from closed stream" errors.
This is an automated email from the ASF dual-hosted git repository.
pabloem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new c982a1c Bug fix: non 200 response streams are read twice which cause "Cannot read from closed stream" errors.
new e183ea6 Merge pull request #12103 from lastomato/fix_api_client: Bug fix: non 200 response streams are read twice which cause "Cannot …
c982a1c is described below
commit c982a1cc679037df3d4d1b9117cfba0f440fbaa5
Author: Jie Fan <la...@google.com>
AuthorDate: Fri Jun 26 11:29:48 2020 -0400
Bug fix: non 200 response streams are read twice which cause "Cannot read from closed stream" errors.
---
.../io/gcp/healthcare/HttpHealthcareApiClient.java | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
index 6743d37..33887dd 100644
--- a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
+++ b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
@@ -429,8 +429,9 @@ public class HttpHealthcareApiClient implements HealthcareApiClient, Serializabl
String content = EntityUtils.toString(responseEntity);
// Check 2XX code.
- if (!(response.getStatusLine().getStatusCode() / 100 == 2)) {
- throw HealthcareHttpException.of(response);
+ int statusCode = response.getStatusLine().getStatusCode();
+ if (!(statusCode / 100 == 2)) {
+ throw HealthcareHttpException.of(statusCode, content);
}
HttpBody responseModel = new HttpBody();
responseModel.setData(content);
@@ -442,11 +443,11 @@ public class HttpHealthcareApiClient implements HealthcareApiClient, Serializabl
* HealthcareIOError}.
*/
public static class HealthcareHttpException extends Exception {
- private final Integer statusCode;
+ private final int statusCode;
- HealthcareHttpException(HttpResponse response, String message) {
+ private HealthcareHttpException(int statusCode, String message) {
super(message);
- this.statusCode = response.getStatusLine().getStatusCode();
+ this.statusCode = statusCode;
if (statusCode / 100 == 2) {
throw new IllegalArgumentException(
String.format(
@@ -456,17 +457,18 @@ public class HttpHealthcareApiClient implements HealthcareApiClient, Serializabl
}
/**
- * Create Exception of {@link HttpResponse}.
+ * Creates an exception from a non-OK response.
*
- * @param response the HTTP response
+ * @param statusCode the HTTP status code.
+ * @param message the error message.
* @return the healthcare http exception
* @throws IOException the io exception
*/
- static HealthcareHttpException of(HttpResponse response) throws IOException {
- return new HealthcareHttpException(response, EntityUtils.toString(response.getEntity()));
+ static HealthcareHttpException of(int statusCode, String message) {
+ return new HealthcareHttpException(statusCode, message);
}
- Integer getStatusCode() {
+ int getStatusCode() {
return statusCode;
}
}