http://java.net/jira/browse/JAVASERVERFACES-2895 Resource caching
Leverage fix from JAVASERVERFACES-2725 and JAVASERVERFACES-2734.
SECTION: Modified Files
----------------------------
M jsf-ri/src/main/java/com/sun/faces/application/ApplicationAssociate.java
- Add an ivar that stores the time this object was instantiated.
M jsf-ri/src/main/java/com/sun/faces/application/resource/ResourceHelper.java
- Use Util.getLastModified() instead of doing it myself.
M jsf-ri/src/main/java/com/sun/faces/application/resource/ResourceImpl.java
- In userAgentNeedsUpdate(), if the lastModified comes back as 0, use
the startup time of the server to determine if the resource needs
update.
SECTION: Diffs
----------------------------
Index: jsf-ri/src/main/java/com/sun/faces/application/ApplicationAssociate.java
===================================================================
--- jsf-ri/src/main/java/com/sun/faces/application/ApplicationAssociate.java (revision 12090)
+++ jsf-ri/src/main/java/com/sun/faces/application/ApplicationAssociate.java (working copy)
@@ -187,6 +187,8 @@
private PropertyEditorHelper propertyEditorHelper;
private NamedEventManager namedEventManager;
+
+ private long timeOfInstantiation;
public ApplicationAssociate(ApplicationImpl appImpl) {
app = appImpl;
@@ -236,6 +238,7 @@
resourceManager = new ResourceManager(appMap, resourceCache);
namedEventManager = new NamedEventManager();
applicationStateInfo = new ApplicationStateInfo();
+ timeOfInstantiation = System.currentTimeMillis();
}
public static ApplicationAssociate getInstance(ExternalContext
@@ -247,6 +250,10 @@
return ((ApplicationAssociate)
applicationMap.get(ASSOCIATE_KEY));
}
+
+ public long getTimeOfInstantiation() {
+ return timeOfInstantiation;
+ }
public static ApplicationAssociate getInstance(ServletContext context) {
if (context == null) {
Index: jsf-ri/src/main/java/com/sun/faces/application/resource/ResourceHelper.java
===================================================================
--- jsf-ri/src/main/java/com/sun/faces/application/resource/ResourceHelper.java (revision 12090)
+++ jsf-ri/src/main/java/com/sun/faces/application/resource/ResourceHelper.java (working copy)
@@ -301,30 +301,8 @@
if (url == null) {
return 0;
}
- long ret;
- InputStream input = null;
- try {
- URLConnection con = url.openConnection();
- con.setUseCaches(false);
- con.connect();
- input = con.getInputStream();
- ret = con.getLastModified();
- } catch (IOException ioe) {
- ret = 0;
- } finally {
- if (input != null) {
- try {
- input.close();
- } catch (IOException ioe) {
- if (LOGGER.isLoggable(Level.FINEST)) {
- LOGGER.log(Level.FINEST, "Closing stream", ioe);
- }
- }
- }
- }
+ return Util.getLastModified(url);
- return ((ret >= 0) ? ret : 0);
-
}
Index: jsf-ri/src/main/java/com/sun/faces/application/resource/ResourceImpl.java
===================================================================
--- jsf-ri/src/main/java/com/sun/faces/application/resource/ResourceImpl.java (revision 12090)
+++ jsf-ri/src/main/java/com/sun/faces/application/resource/ResourceImpl.java (working copy)
@@ -352,7 +352,12 @@
initResourceInfo();
long lastModifiedOfResource = resourceInfo.getLastModified(context);
long lastModifiedHeader = getIfModifiedHeader(context.getExternalContext());
- return lastModifiedOfResource > lastModifiedHeader;
+ if (0 == lastModifiedOfResource) {
+ long startupTime = ApplicationAssociate.getInstance(context.getExternalContext()).getTimeOfInstantiation();
+ return startupTime > lastModifiedHeader;
+ } else {
+ return lastModifiedOfResource > lastModifiedHeader;
+ }
}
return true;
--