Skip to content

Commit ed2f495

Browse files
authored
Reset stream when logging debug information (jenkinsci#1197)
Fixes jenkinsci#1196
1 parent 3a399e7 commit ed2f495

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/com/dabsquared/gitlabjenkins/gitlab/api/impl/ResteasyGitLabClientBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,16 @@ private String getPrettyPrintResponseBody(ClientResponseContext responseContext)
208208
}
209209

210210
private String getResponseBody(ClientResponseContext context) {
211-
try (InputStream entityStream = context.getEntityStream()) {
212-
if (entityStream != null) {
211+
// Cannot use try-with-resources here because the stream needs to remain open for reading later. Instead, we reset it when done.
212+
try {
213+
InputStream entityStream = context.getEntityStream();
214+
if (entityStream != null && entityStream.markSupported()) {
213215
byte[] bytes = IOUtils.toByteArray(entityStream);
214-
context.setEntityStream(new ByteArrayInputStream(bytes));
216+
entityStream.reset();
215217
return new String(bytes);
216218
}
217219
} catch (IOException e) {
218220
LOGGER.log(Level.SEVERE, "Failure during reading the response body", e);
219-
context.setEntityStream(new ByteArrayInputStream(new byte[0]));
220221
}
221222
return "";
222223
}

0 commit comments

Comments
 (0)