Skip to content

Commit e2ba7c9

Browse files
committed
MockClientHttpResponse closes body stream on close()
Issue: SPR-14563 (cherry picked from commit 47e9360)
1 parent 6f5596a commit e2ba7c9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.mock.http.client;
1718

1819
import java.io.IOException;
@@ -39,7 +40,7 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie
3940
*/
4041
public MockClientHttpResponse(byte[] body, HttpStatus statusCode) {
4142
super(body);
42-
Assert.notNull(statusCode, "statisCode is required");
43+
Assert.notNull(statusCode, "HttpStatus is required");
4344
this.status = statusCode;
4445
}
4546

@@ -48,10 +49,11 @@ public MockClientHttpResponse(byte[] body, HttpStatus statusCode) {
4849
*/
4950
public MockClientHttpResponse(InputStream body, HttpStatus statusCode) {
5051
super(body);
51-
Assert.notNull(statusCode, "statisCode is required");
52+
Assert.notNull(statusCode, "HttpStatus is required");
5253
this.status = statusCode;
5354
}
5455

56+
5557
@Override
5658
public HttpStatus getStatusCode() throws IOException {
5759
return this.status;
@@ -69,6 +71,15 @@ public String getStatusText() throws IOException {
6971

7072
@Override
7173
public void close() {
74+
try {
75+
InputStream body = getBody();
76+
if (body != null) {
77+
body.close();
78+
}
79+
}
80+
catch (IOException ex) {
81+
// ignore
82+
}
7283
}
7384

7485
}

0 commit comments

Comments
 (0)