Author: markt Date: Wed Jul 21 20:30:53 2010 New Revision: 966404 URL: http://svn.apache.org/viewvc?rev=966404&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49600 Return a consistent exception for 'Not Found' resources.
Modified: tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java tomcat/trunk/java/org/apache/naming/resources/ProxyDirContext.java tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java?rev=966404&r1=966403&r2=966404&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java (original) +++ tomcat/trunk/java/org/apache/naming/resources/BaseDirContext.java Wed Jul 21 20:30:53 2010 @@ -36,6 +36,7 @@ import javax.naming.Binding; import javax.naming.Context; import javax.naming.Name; import javax.naming.NameClassPair; +import javax.naming.NameNotFoundException; import javax.naming.NameParser; import javax.naming.NamingEnumeration; import javax.naming.NamingException; @@ -475,7 +476,8 @@ public abstract class BaseDirContext imp } // Really not found - throw new NamingException(sm.getString("resources.notFound", name)); + throw new NameNotFoundException( + sm.getString("resources.notFound", name)); } /** @@ -702,7 +704,8 @@ public abstract class BaseDirContext imp } // Really not found - throw new NamingException(sm.getString("resources.notFound", name)); + throw new NameNotFoundException( + sm.getString("resources.notFound", name)); } @@ -1058,7 +1061,8 @@ public abstract class BaseDirContext imp } // Really not found - throw new NamingException(sm.getString("resources.notFound", name)); + throw new NameNotFoundException( + sm.getString("resources.notFound", name)); } /** Modified: tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java?rev=966404&r1=966403&r2=966404&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java (original) +++ tomcat/trunk/java/org/apache/naming/resources/FileDirContext.java Wed Jul 21 20:30:53 2010 @@ -31,6 +31,7 @@ import java.util.Hashtable; import javax.naming.Binding; import javax.naming.NameAlreadyBoundException; import javax.naming.NameClassPair; +import javax.naming.NameNotFoundException; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.OperationNotSupportedException; @@ -237,8 +238,8 @@ public class FileDirContext extends Base File file = file(name); if (file == null) - throw new NamingException - (sm.getString("resources.notFound", name)); + throw new NameNotFoundException( + sm.getString("resources.notFound", name)); if (!file.delete()) throw new NamingException @@ -265,7 +266,7 @@ public class FileDirContext extends Base File file = file(oldName); if (file == null) - throw new NamingException + throw new NameNotFoundException (sm.getString("resources.notFound", oldName)); File newFile = new File(base, newName); @@ -295,7 +296,7 @@ public class FileDirContext extends Base File file = file(name); if (file == null) - throw new NamingException + throw new NameNotFoundException (sm.getString("resources.notFound", name)); return new NamingContextEnumeration(list(file).iterator()); Modified: tomcat/trunk/java/org/apache/naming/resources/ProxyDirContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/ProxyDirContext.java?rev=966404&r1=966403&r2=966404&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/naming/resources/ProxyDirContext.java (original) +++ tomcat/trunk/java/org/apache/naming/resources/ProxyDirContext.java Wed Jul 21 20:30:53 2010 @@ -56,6 +56,13 @@ public class ProxyDirContext implements public static final String HOST = "host"; + /** + * Immutable name not found exception. + */ + protected static final NameNotFoundException NOT_FOUND_EXCEPTION = + new ImmutableNameNotFoundException(); + + // ----------------------------------------------------------- Constructors @@ -134,7 +141,8 @@ public class ProxyDirContext implements /** * The string manager for this package. */ - protected static final StringManager sm = StringManager.getManager(Constants.Package); + protected static final StringManager sm = + StringManager.getManager(Constants.Package); /** @@ -187,13 +195,6 @@ public class ProxyDirContext implements /** - * Immutable name not found exception. - */ - protected NameNotFoundException notFoundException = - new ImmutableNameNotFoundException(); - - - /** * Non cacheable resources. */ protected String[] nonCacheable = { "/WEB-INF/lib/", "/WEB-INF/classes/" }; @@ -263,7 +264,7 @@ public class ProxyDirContext implements CacheEntry entry = cacheLookup(name.toString()); if (entry != null) { if (!entry.exists) { - throw notFoundException; + throw NOT_FOUND_EXCEPTION; } if (entry.resource != null) { // Check content caching. @@ -292,7 +293,7 @@ public class ProxyDirContext implements CacheEntry entry = cacheLookup(name); if (entry != null) { if (!entry.exists) { - throw notFoundException; + throw NOT_FOUND_EXCEPTION; } if (entry.resource != null) { return entry.resource; @@ -813,7 +814,7 @@ public class ProxyDirContext implements CacheEntry entry = cacheLookup(name.toString()); if (entry != null) { if (!entry.exists) { - throw notFoundException; + throw NOT_FOUND_EXCEPTION; } return entry.attributes; } @@ -837,7 +838,7 @@ public class ProxyDirContext implements CacheEntry entry = cacheLookup(name); if (entry != null) { if (!entry.exists) { - throw notFoundException; + throw NOT_FOUND_EXCEPTION; } return entry.attributes; } Modified: tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java?rev=966404&r1=966403&r2=966404&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java (original) +++ tomcat/trunk/java/org/apache/naming/resources/WARDirContext.java Wed Jul 21 20:30:53 2010 @@ -35,6 +35,7 @@ import javax.naming.CompositeName; import javax.naming.InvalidNameException; import javax.naming.Name; import javax.naming.NameClassPair; +import javax.naming.NameNotFoundException; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.OperationNotSupportedException; @@ -296,7 +297,7 @@ public class WARDirContext extends BaseD return new NamingContextEnumeration(list(entries).iterator()); Entry entry = treeLookup(name); if (entry == null) - throw new NamingException + throw new NameNotFoundException (sm.getString("resources.notFound", name)); return new NamingContextEnumeration(list(entry).iterator()); } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=966404&r1=966403&r2=966404&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Wed Jul 21 20:30:53 2010 @@ -178,6 +178,12 @@ default timeout configurable using the <code>asyncTimeout</code> attribute on the connector. (pero/markt) </fix> + <fix> + <bug>49600</bug>: Make exceptions returned by the + <code>ProxyDirContext</code> consistent for resources that weren't found + by checking the <code>DirContext</code> or the cache. Test case based on + a patch provided by Marc Guillemot. (markt) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org