MockClientHttpResponse closes body stream on close()
Issue: SPR-14563
This commit is contained in:
		
							parent
							
								
									62e08a5ebe
								
							
						
					
					
						commit
						47e9360d62
					
				|  | @ -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"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with 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 |  * See the License for the specific language governing permissions and | ||||||
|  * limitations under the License. |  * limitations under the License. | ||||||
|  */ |  */ | ||||||
|  | 
 | ||||||
| package org.springframework.mock.http.client; | package org.springframework.mock.http.client; | ||||||
| 
 | 
 | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
|  | @ -39,7 +40,7 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie | ||||||
| 	 */ | 	 */ | ||||||
| 	public MockClientHttpResponse(byte[] body, HttpStatus statusCode) { | 	public MockClientHttpResponse(byte[] body, HttpStatus statusCode) { | ||||||
| 		super(body); | 		super(body); | ||||||
| 		Assert.notNull(statusCode, "statisCode is required"); | 		Assert.notNull(statusCode, "HttpStatus is required"); | ||||||
| 		this.status = statusCode; | 		this.status = statusCode; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -48,10 +49,11 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie | ||||||
| 	 */ | 	 */ | ||||||
| 	public MockClientHttpResponse(InputStream body, HttpStatus statusCode) { | 	public MockClientHttpResponse(InputStream body, HttpStatus statusCode) { | ||||||
| 		super(body); | 		super(body); | ||||||
| 		Assert.notNull(statusCode, "statisCode is required"); | 		Assert.notNull(statusCode, "HttpStatus is required"); | ||||||
| 		this.status = statusCode; | 		this.status = statusCode; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public HttpStatus getStatusCode() throws IOException { | 	public HttpStatus getStatusCode() throws IOException { | ||||||
| 		return this.status; | 		return this.status; | ||||||
|  | @ -69,6 +71,15 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void close() { | 	public void close() { | ||||||
|  | 		try { | ||||||
|  | 			InputStream body = getBody(); | ||||||
|  | 			if (body != null) { | ||||||
|  | 				body.close(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		catch (IOException ex) { | ||||||
|  | 			// ignore | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue