[spring-extensions] branch master updated: IDP-969 : Close response when resource does not exist.
Tom Zeller
tzeller at dragonacea.biz
Wed Apr 20 15:04:52 EDT 2016
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch master
in repository spring-extensions.
The following commit(s) were added to refs/heads/master by this push:
new aec5af1 IDP-969 : Close response when resource does not exist.
aec5af1 is described below
commit aec5af1a60b8d64ff9f5bfe375cd96e40334bdd4
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Wed Apr 20 14:04:27 2016 -0500
IDP-969 : Close response when resource does not exist.
---
.../shibboleth/ext/spring/resource/HTTPResource.java | 16 ++++++++++++++++
.../ext/spring/resource/HTTPResourceTest.java | 19 +++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java b/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java
index a72b39c..8425942 100644
--- a/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java
+++ b/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java
@@ -162,6 +162,7 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
String errMsg =
"Non-ok status code " + httpStatusCode + " returned from remote resource " + resourceURL;
log.error(errMsg);
+ closeResponse(response);
throw new IOException(errMsg);
}
@@ -414,4 +415,19 @@ public class HTTPResource extends AbstractIdentifiedInitializableComponent imple
}
}
+ /**
+ * Close the HTTP response.
+ *
+ * @param response the HTTP response
+ */
+ protected void closeResponse(@Nullable final HttpResponse response) {
+ try {
+ if (response != null && response instanceof CloseableHttpResponse) {
+ ((CloseableHttpResponse) response).close();
+ }
+ } catch (final IOException e) {
+ log.error("Error closing HTTP response from '{}'", resourceURL.toExternalForm(), e);
+ }
+ }
+
}
diff --git a/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java b/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java
index 3d30b22..7932c57 100644
--- a/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java
+++ b/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java
@@ -28,6 +28,7 @@ import net.shibboleth.utilities.java.support.httpclient.InMemoryCachingHttpClien
import org.apache.http.client.HttpClient;
import org.apache.http.client.cache.CacheResponseStatus;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.joda.time.DateTime;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;
@@ -176,4 +177,22 @@ public class HTTPResourceTest {
}
}
}
+
+ @Test(timeOut = 2000) public void testCloseResponse() {
+ // See IDP-969. This test will timeout if the response is not closed.
+ try (final PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager()) {
+ final HTTPResource notExistsResource = new HTTPResource(client, nonExistsURL);
+ int count = 0;
+ while (count <= connMgr.getDefaultMaxPerRoute()) {
+ count++;
+ try {
+ notExistsResource.getInputStream();
+ } catch (IOException e) {
+ // expected because resource does not exist
+ }
+ }
+ } catch (IOException e) {
+ Assert.fail("Bad URL", e);
+ }
+ }
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list