[utilities COMMIT] in /spring-extensions/trunk: pom.xml src/main/java/net/shibboleth/ext/spring/resource/HTTPResource...
noreply at shibboleth.net
noreply at shibboleth.net
Sat Oct 4 06:06:29 EDT 2014
Author: rdw
Date: Sat Oct 4 06:06:28 2014
New Revision: 666
URL: http://svn.shibboleth.net/view/utilities?rev=666&view=rev
Log:
JSE-7 Do not use a HEAD, always use a GET and assume that the user has deployed a caching client. Add tests to prove that caching does what we want and logging to allow users to tune their caches (for those with a taste for history I'll add that you can tune a cache, but you can't tune a fish)
Added:
spring-extensions/trunk/src/test/java/net/shibboleth/ext/spring/resource/TestHTTPResource.java (with props)
spring-extensions/trunk/src/test/resources/data/FileBackedHTTPBean.xml (with props)
spring-extensions/trunk/src/test/resources/data/MemBackedHTTPBean.xml (with props)
Modified:
spring-extensions/trunk/pom.xml
spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java
spring-extensions/trunk/src/test/java/net/shibboleth/ext/spring/resource/HTTPResourceTest.java
Modified: spring-extensions/trunk/pom.xml
URL: http://svn.shibboleth.net/view/utilities/spring-extensions/trunk/pom.xml?rev=666&r1=665&r2=666&view=diff
==============================================================================
--- spring-extensions/trunk/pom.xml (original)
+++ spring-extensions/trunk/pom.xml Sat Oct 4 06:06:28 2014
@@ -58,6 +58,13 @@
<artifactId>httpclient</artifactId>
<optional>true</optional>
</dependency>
+ <dependency>
+ <!-- Required if you're using anything in the httpclient package -->
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient-cache</artifactId>
+ <optional>true</optional>
+ </dependency>
+
<dependency>
<groupId>org.cryptacular</groupId>
<artifactId>cryptacular</artifactId>
Modified: spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java
URL: http://svn.shibboleth.net/view/utilities/spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java?rev=666&r1=665&r2=666&view=diff
==============================================================================
--- spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java (original)
+++ spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/HTTPResource.java Sat Oct 4 06:06:28 2014
@@ -38,10 +38,10 @@
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.cache.CacheResponseStatus;
+import org.apache.http.client.cache.HttpCacheContext;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.DateUtils;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.util.EntityUtils;
@@ -54,8 +54,7 @@
/**
* Resource for looking up HTTP URLs. Allows injection and therefore configuration of an Apache {@link HttpClient}. Code
- * based on OpenSAML <code>HTTPMetadataResolver</code> and
- * {@link org.springframework.core.io.UrlResource}.
+ * based on OpenSAML <code>HTTPMetadataResolver</code> and {@link org.springframework.core.io.UrlResource}.
*/
public class HTTPResource extends AbstractIdentifiedInitializableComponent implements Resource, BeanNameAware,
InitializingBean, net.shibboleth.utilities.java.support.resource.Resource {
@@ -104,26 +103,58 @@
}
/**
- * Build the {@link HttpClientContext} instance which will be used to invoke the {@link HttpClient} request.
- *
- * @return a new instance of {@link HttpClientContext}
- */
- protected HttpClientContext buildHttpClientContext() {
- HttpClientContext context = HttpClientContext.create();
+ * Build the {@link HttpCacheContext} instance which will be used to invoke the {@link HttpClient} request.
+ *
+ * @return a new instance of {@link HttpCacheContext}
+ */
+ protected HttpCacheContext buildHttpClientContext() {
+ HttpCacheContext context = HttpCacheContext.create();
if (credentialsProvider != null) {
context.setCredentialsProvider(credentialsProvider);
}
return context;
}
+ /**
+ * Print out to the log whether we hit the apache cache or not.
+ * http://hc.apache.org/httpcomponents-client-ga/tutorial/html/caching.html
+ * @param context the context of the request
+ */
+ protected void reportCachingStatus(HttpCacheContext context) {
+ CacheResponseStatus responseStatus = context.getCacheResponseStatus();
+ if (null == responseStatus) {
+ log.info("Non caching client provided");
+ return;
+ }
+ switch (responseStatus) {
+ case CACHE_HIT:
[... 227 lines stripped ...]
More information about the commits
mailing list