You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by jw...@apache.org on 2012/04/20 00:13:29 UTC
svn commit: r1328130 - in /myfaces/trinidad/trunk/trinidad-api/src/main:
java/org/apache/myfaces/trinidad/resource/
java/org/apache/myfaces/trinidad/webapp/
xrts/org/apache/myfaces/trinidad/resource/
Author: jwaldman
Date: Thu Apr 19 22:13:28 2012
New Revision: 1328130
URL: http://svn.apache.org/viewvc?rev=1328130&view=rev
Log:
TRINIDAD-2257 When a resource fails to load, add an exception if the cached temp directory doesn't match the current temp directory
thanks to Mark Yvanovich for the patch
Added:
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TempDirectoryResourceLoader.java
Modified:
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/DirectoryResourceLoader.java
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/DirectoryResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/DirectoryResourceLoader.java?rev=1328130&r1=1328129&r2=1328130&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/DirectoryResourceLoader.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/DirectoryResourceLoader.java Thu Apr 19 22:13:28 2012
@@ -114,6 +114,11 @@ public class DirectoryResourceLoader ext
// preferred way as of JDK 6.0.
return (isContained && file.exists()) ? file.toURI().toURL() : null;
}
+
+ protected final String getDirectoryPath()
+ {
+ return _directoryPath;
+ }
private final File _directory;
private final String _directoryPath;
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java?rev=1328130&r1=1328129&r2=1328130&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java Thu Apr 19 22:13:28 2012
@@ -56,7 +56,6 @@ import javax.servlet.http.HttpServletRes
import org.apache.myfaces.trinidad.config.Configurator;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.resource.CachingResourceLoader;
-import org.apache.myfaces.trinidad.resource.DirectoryResourceLoader;
import org.apache.myfaces.trinidad.resource.ResourceLoader;
import org.apache.myfaces.trinidad.resource.ServletContextResourceLoader;
import org.apache.myfaces.trinidad.util.URLUtils;
@@ -309,10 +308,9 @@ public class ResourceServlet extends Htt
try
{
Constructor<?> decorator = clazz.getConstructor(_DECORATOR_SIGNATURE);
- ServletContext context = getServletContext();
- File tempdir = (File)
- context.getAttribute("javax.servlet.context.tempdir");
- ResourceLoader delegate = new DirectoryResourceLoader(tempdir);
+ // We are now calling a special temp directory version of DirectoryResourceLoader to
+ // assure that the servlet context's temp directory doesn't change on us.
+ ResourceLoader delegate = new TempDirectoryResourceLoader(getServletContext());
loader = (ResourceLoader)
decorator.newInstance(new Object[]{delegate});
}
Added: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TempDirectoryResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TempDirectoryResourceLoader.java?rev=1328130&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TempDirectoryResourceLoader.java (added)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/TempDirectoryResourceLoader.java Thu Apr 19 22:13:28 2012
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidad.webapp;
+
+import java.io.File;
+import java.io.IOException;
+
+import java.net.URL;
+
+import javax.faces.context.FacesContext;
+
+import javax.servlet.ServletContext;
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.resource.DirectoryResourceLoader;
+
+/**
+ * This is a package-private version of DirectoryResourceLoader that is used
+ * with temp directories. When a resource fails to load, we check the current
+ * temp directory against the one we've cached and if they are different, we
+ * throw an illegal state exception to indicate the temp directory location
+ * was illegally changed.
+ */
+class TempDirectoryResourceLoader extends DirectoryResourceLoader
+{
+ /**
+ * Constructs a new TempDirectoryResourceLoader.
+ *
+ * @param context the ServletContext object
+ */
+ public TempDirectoryResourceLoader(
+ ServletContext context)
+ {
+ super((File)context.getAttribute("javax.servlet.context.tempdir"));
+ }
+
+ @Override
+ protected URL findResource(
+ String path) throws IOException
+ {
+ URL resourceURL = super.findResource(path);
+
+ // On failure to find the resource, we want to log an error if the saved temp directory
+ // is different than the current temp directory.
+ if (resourceURL == null)
+ {
+ // Getting a fresh ServletContext object as we don't trust caching the one passed in to
+ // the constructor.
+ FacesContext fContext = FacesContext.getCurrentInstance();
+
+ // this is OK because we only create instances of this class from the ResourceServlet
+ ServletContext sContext = (ServletContext) fContext.getExternalContext().getContext();
+ File tempdir = (File) sContext.getAttribute("javax.servlet.context.tempdir");
+
+ // Get the current tempdir path
+ String newTempdDirPath = tempdir.getCanonicalPath();
+
+ // Retrieve the old (cached) tempdir path from DirectoryResourceLoader.
+ String oldTempDirPath = getDirectoryPath();
+
+ // If they aren't equal, throw exception as this indicates a serious problem.
+ if (!newTempdDirPath.equals(oldTempDirPath))
+ {
+ throw new IllegalStateException(_LOG.getMessage(
+ "TEMPDIR_CHANGED", new Object[] { newTempdDirPath, oldTempDirPath }));
+ }
+ }
+
+ return resourceURL;
+ }
+
+ private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(
+ TempDirectoryResourceLoader.class);
+}
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts?rev=1328130&r1=1328129&r2=1328130&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts Thu Apr 19 22:13:28 2012
@@ -522,6 +522,9 @@
<!-- INVALID_CONTEXT_CHANGE_FOUND -->
<resource key="INVALID_CONTEXT_CHANGE_FOUND">An unexpected component context change was found. This is due to components not correctly maintaining the context change stack. Expected change of type {0} for component {1} but received change {2}.</resource>
+<!-- TEMPDIR_CHANGED -->
+<resource key="TEMPDIR_CHANGED">Cached temp directory doesn't match the current. Current temp directory: "{0}" Cached temp directory: "{1}"</resource>
+
<!-- ILLEGAL_ENUM_VALUE -->
<resource key="ILLEGAL_ENUM_VALUE">No {0} enum constant for value "{1}".</resource>