Skip to content

Commit

Permalink
Pass string to ObjectMapper instead of InputStream (#531)
Browse files Browse the repository at this point in the history
Pass string to ObjectMapper instead of InputStream in order to avoid No content to map due to end-of-input error caused by jdk.internal.net.http.ResponseSubscribers$HttpResponseInputStream.
An error was discovered in our customers environment
  • Loading branch information
vinokurig authored Jul 12, 2023
1 parent aee2079 commit c5963e0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ private AzureDevOpsUser getUser(String url, String authorizationHeader)
userDataRequest,
response -> {
try {
return OBJECT_MAPPER.readValue(response.body(), AzureDevOpsUser.class);
String result =
CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
return OBJECT_MAPPER.readValue(result, AzureDevOpsUser.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ public BitbucketUser getUser(String slug, @Nullable String token)
request,
inputStream -> {
try {
return OM.readValue(inputStream, BitbucketUser.class);
String result =
CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
return OM.readValue(result, BitbucketUser.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -230,7 +232,9 @@ public void deletePersonalAccessTokens(String userSlug, Long tokenId)
request,
inputStream -> {
try {
return OM.readValue(inputStream, String.class);
String result =
CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
return OM.readValue(result, String.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -271,7 +275,9 @@ public BitbucketPersonalAccessToken createPersonalAccessTokens(
request,
inputStream -> {
try {
return OM.readValue(inputStream, BitbucketPersonalAccessToken.class);
String result =
CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
return OM.readValue(result, BitbucketPersonalAccessToken.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -313,7 +319,9 @@ public BitbucketPersonalAccessToken getPersonalAccessToken(String userSlug, Long
request,
inputStream -> {
try {
return OM.readValue(inputStream, BitbucketPersonalAccessToken.class);
String result =
CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
return OM.readValue(result, BitbucketPersonalAccessToken.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -388,7 +396,9 @@ private <T> Page<T> doGetPage(Class<T> tClass, String api, int start, int limit,
request,
inputStream -> {
try {
return OM.readValue(inputStream, typeReference);
String result =
CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
return OM.readValue(result, typeReference);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public BitbucketUser getUser(String authenticationToken)
request,
response -> {
try {
return OBJECT_MAPPER.readValue(response.body(), BitbucketUser.class);
String result =
CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
return OBJECT_MAPPER.readValue(result, BitbucketUser.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -154,7 +156,9 @@ public BitbucketUserEmail getEmail(String authenticationToken)
request,
response -> {
try {
return OBJECT_MAPPER.readValue(response.body(), BitbucketUserEmail.class);
String result =
CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
return OBJECT_MAPPER.readValue(result, BitbucketUserEmail.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public GithubUser getUser(String authenticationToken)
request,
response -> {
try {
return OBJECT_MAPPER.readValue(response.body(), GithubUser.class);
String result =
CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
return OBJECT_MAPPER.readValue(result, GithubUser.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -140,7 +142,9 @@ public GithubPullRequest getPullRequest(
request,
response -> {
try {
return OBJECT_MAPPER.readValue(response.body(), GithubPullRequest.class);
String result =
CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
return OBJECT_MAPPER.readValue(result, GithubPullRequest.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -181,7 +185,9 @@ public GithubCommit getLatestCommit(
request,
response -> {
try {
return OBJECT_MAPPER.readValue(response.body(), GithubCommit[].class)[0];
String result =
CharStreams.toString(new InputStreamReader(response.body(), Charsets.UTF_8));
return OBJECT_MAPPER.readValue(result, GithubCommit[].class)[0];
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public GitlabUser getUser(String authenticationToken)
request,
inputStream -> {
try {
return OBJECT_MAPPER.readValue(inputStream, GitlabUser.class);
String result =
CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
return OBJECT_MAPPER.readValue(result, GitlabUser.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -100,7 +102,9 @@ public GitlabOauthTokenInfo getTokenInfo(String authenticationToken)
request,
inputStream -> {
try {
return OBJECT_MAPPER.readValue(inputStream, GitlabOauthTokenInfo.class);
String result =
CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
return OBJECT_MAPPER.readValue(result, GitlabOauthTokenInfo.class);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down

0 comments on commit c5963e0

Please sign in to comment.