Skip to content

Commit 176feea

Browse files
committed
Fix getRequestAsInputStream method that close prematurely the response before it was parsed by the caller.
1 parent e4d32d5 commit 176feea

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/client/AbstractBitbucketApi.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,24 +279,17 @@ protected InputStream getRequestAsInputStream(String path) throws IOException {
279279
// use default
280280
}
281281

282-
try (CloseableHttpResponse response = executeMethod(host, httpget)) {
283-
int statusCode = response.getStatusLine().getStatusCode();
284-
if (statusCode == HttpStatus.SC_NOT_FOUND) {
285-
EntityUtils.consume(response.getEntity());
286-
throw new FileNotFoundException("URL: " + path);
287-
}
288-
if (statusCode != HttpStatus.SC_OK) {
289-
String content = getResponseContent(response);
290-
throw buildResponseException(response, content);
291-
}
292-
return new ClosingConnectionInputStream(response, httpget, getConnectionManager());
293-
} catch (BitbucketRequestException | FileNotFoundException e) {
294-
throw e;
295-
} catch (IOException e) {
296-
throw new IOException("Communication error for url: " + path, e);
297-
} finally {
298-
release(httpget);
282+
CloseableHttpResponse response = executeMethod(host, httpget);
283+
int statusCode = response.getStatusLine().getStatusCode();
284+
if (statusCode == HttpStatus.SC_NOT_FOUND) {
285+
EntityUtils.consume(response.getEntity());
286+
throw new FileNotFoundException("URL: " + path);
287+
}
288+
if (statusCode != HttpStatus.SC_OK) {
289+
String content = getResponseContent(response);
290+
throw buildResponseException(response, content);
299291
}
292+
return new ClosingConnectionInputStream(response, httpget, getConnectionManager());
300293
}
301294

302295
protected int headRequestStatus(String path) throws IOException {

0 commit comments

Comments
 (0)