From 47e9360d62a2474e4cb04caaaaa0a1c32ab14e27 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 9 Aug 2016 10:43:50 +0200 Subject: [PATCH] MockClientHttpResponse closes body stream on close() Issue: SPR-14563 --- .../http/client/MockClientHttpResponse.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java b/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java index 64b229e558..5044215e1c 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.mock.http.client; import java.io.IOException; @@ -39,7 +40,7 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie */ public MockClientHttpResponse(byte[] body, HttpStatus statusCode) { super(body); - Assert.notNull(statusCode, "statisCode is required"); + Assert.notNull(statusCode, "HttpStatus is required"); this.status = statusCode; } @@ -48,10 +49,11 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie */ public MockClientHttpResponse(InputStream body, HttpStatus statusCode) { super(body); - Assert.notNull(statusCode, "statisCode is required"); + Assert.notNull(statusCode, "HttpStatus is required"); this.status = statusCode; } + @Override public HttpStatus getStatusCode() throws IOException { return this.status; @@ -69,6 +71,15 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie @Override public void close() { + try { + InputStream body = getBody(); + if (body != null) { + body.close(); + } + } + catch (IOException ex) { + // ignore + } } }