diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java b/org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java
index a09934359b..e1f796847a 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java
@@ -95,7 +95,7 @@ public abstract class AbstractFileResolvingResource extends AbstractResource {
else {
// Try a URL connection content-length header...
URLConnection con = url.openConnection();
- con.setUseCaches(false);
+ ResourceUtils.useCachesIfNecessary(con);
HttpURLConnection httpCon =
(con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
if (httpCon != null) {
@@ -157,7 +157,7 @@ public abstract class AbstractFileResolvingResource extends AbstractResource {
else {
// Try a URL connection content-length header...
URLConnection con = url.openConnection();
- con.setUseCaches(false);
+ ResourceUtils.useCachesIfNecessary(con);
if (con instanceof HttpURLConnection) {
((HttpURLConnection) con).setRequestMethod("HEAD");
}
@@ -175,7 +175,7 @@ public abstract class AbstractFileResolvingResource extends AbstractResource {
else {
// Try a URL connection last-modified header...
URLConnection con = url.openConnection();
- con.setUseCaches(false);
+ ResourceUtils.useCachesIfNecessary(con);
if (con instanceof HttpURLConnection) {
((HttpURLConnection) con).setRequestMethod("HEAD");
}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/UrlResource.java b/org.springframework.core/src/main/java/org/springframework/core/io/UrlResource.java
index a68e919c66..2f9f162d78 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/io/UrlResource.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/io/UrlResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -26,6 +26,7 @@ import java.net.URL;
import java.net.URLConnection;
import org.springframework.util.Assert;
+import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
/**
@@ -119,7 +120,7 @@ public class UrlResource extends AbstractFileResolvingResource {
*/
public InputStream getInputStream() throws IOException {
URLConnection con = this.url.openConnection();
- con.setUseCaches(false);
+ ResourceUtils.useCachesIfNecessary(con);
try {
return con.getInputStream();
}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
index 92716e491a..f9a3645a3e 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
@@ -433,7 +433,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
if (con instanceof JarURLConnection) {
// Should usually be the case for traditional JAR files.
JarURLConnection jarCon = (JarURLConnection) con;
- jarCon.setUseCaches(jarCon.getClass().getName().startsWith("JNLP"));
+ ResourceUtils.useCachesIfNecessary(jarCon);
jarFile = jarCon.getJarFile();
jarFileUrl = jarCon.getJarFileURL().toExternalForm();
JarEntry jarEntry = jarCon.getJarEntry();
diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java b/org.springframework.core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java
index f52c0f04f7..20b74d017a 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2006 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -26,6 +26,7 @@ import java.util.Properties;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
+import org.springframework.util.ResourceUtils;
/**
* Convenient utility methods for loading of java.util.Properties,
@@ -106,7 +107,7 @@ public abstract class PropertiesLoaderUtils {
InputStream is = null;
try {
URLConnection con = url.openConnection();
- con.setUseCaches(false);
+ ResourceUtils.useCachesIfNecessary(con);
is = con.getInputStream();
properties.load(is);
}
diff --git a/org.springframework.core/src/main/java/org/springframework/util/ResourceUtils.java b/org.springframework.core/src/main/java/org/springframework/util/ResourceUtils.java
index e309719029..b9dc3bd855 100644
--- a/org.springframework.core/src/main/java/org/springframework/util/ResourceUtils.java
+++ b/org.springframework.core/src/main/java/org/springframework/util/ResourceUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -22,6 +22,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.URLConnection;
/**
* Utility methods for resolving resource locations to files in the
@@ -328,4 +329,14 @@ public abstract class ResourceUtils {
return new URI(StringUtils.replace(location, " ", "%20"));
}
+ /**
+ * Set the {@link URLConnection#setUseCaches "useCaches"} flag on the
+ * given connection, preferring false but leaving the
+ * flag at true for JNLP based resources.
+ * @param con the URLConnection to set the flag on
+ */
+ public static void useCachesIfNecessary(URLConnection con) {
+ con.setUseCaches(con.getClass().getName().startsWith("JNLP"));
+ }
+
}