Author: markt
Date: Fri Aug  8 07:08:21 2008
New Revision: 683969

URL: http://svn.apache.org/viewvc?rev=683969&view=rev
Log:
When a JSP file is deleted, return a 404 for the next request rather than 
serving the next request as if the file still existed and then returning 404s 
for the second and subsequent requests.

Modified:
    tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java
    tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java
    tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java
    tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java

Modified: tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java?rev=683969&r1=683968&r2=683969&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java (original)
+++ tomcat/trunk/java/org/apache/jasper/JspCompilationContext.java Fri Aug  8 
07:08:21 2008
@@ -569,7 +569,7 @@
     }
 
     public boolean isRemoved() {
-        if (removed > 1 ) {
+        if (removed > 0 ) {
             return true;
         }
         return false;
@@ -580,6 +580,9 @@
     public void compile() throws JasperException, FileNotFoundException {
         createCompiler();
         if (jspCompiler.isOutDated()) {
+            if (isRemoved()) {
+                throw new FileNotFoundException(jspUri);
+            }
             try {
                 jspCompiler.removeGeneratedFiles();
                 jspLoader = null;

Modified: tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java?rev=683969&r1=683968&r2=683969&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java Fri Aug  8 
07:08:21 2008
@@ -382,7 +382,7 @@
             URL jspUrl = ctxt.getResource(jsp);
             if (jspUrl == null) {
                 ctxt.incrementRemoved();
-                return false;
+                return true;
             }
             URLConnection uc = jspUrl.openConnection();
             if (uc instanceof JarURLConnection) {

Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java?rev=683969&r1=683968&r2=683969&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java (original)
+++ tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java Fri Aug  8 
07:08:21 2008
@@ -17,6 +17,7 @@
 
 package org.apache.jasper.servlet;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.util.Enumeration;
@@ -297,38 +298,15 @@
                                 Throwable exception, boolean precompile)
         throws ServletException, IOException {
 
-        JspServletWrapper wrapper =
-            (JspServletWrapper) rctxt.getWrapper(jspUri);
+        JspServletWrapper wrapper = rctxt.getWrapper(jspUri);
         if (wrapper == null) {
             synchronized(this) {
-                wrapper = (JspServletWrapper) rctxt.getWrapper(jspUri);
+                wrapper = rctxt.getWrapper(jspUri);
                 if (wrapper == null) {
                     // Check if the requested JSP page exists, to avoid
                     // creating unnecessary directories and files.
                     if (null == context.getResource(jspUri)) {
-                        String includeRequestUri = (String)
-                        request.getAttribute(
-                                "javax.servlet.include.request_uri");
-                        if (includeRequestUri != null) {
-                            // This file was included. Throw an exception as
-                            // a response.sendError() will be ignored
-                            String msg = Localizer.getMessage(
-                                    "jsp.error.file.not.found",jspUri);
-                            // Strictly, filtering this is an application
-                            // responsibility but just in case...
-                            throw new ServletException(
-                                    SecurityUtil.filter(msg));
-                        } else {
-                            try {
-                                response.sendError(
-                                        HttpServletResponse.SC_NOT_FOUND,
-                                        request.getRequestURI());
-                            } catch (IllegalStateException ise) {
-                                log.error(Localizer.getMessage(
-                                        "jsp.error.file.not.found",
-                                        jspUri));
-                            }
-                        }
+                        handleMissingResource(request, response, jspUri);
                         return;
                     }
                     boolean isErrorPage = exception != null;
@@ -339,8 +317,40 @@
             }
         }
 
-        wrapper.service(request, response, precompile);
+        try {
+            wrapper.service(request, response, precompile);
+        } catch (FileNotFoundException fnfe) {
+            handleMissingResource(request, response, jspUri);
+        }
+
+    }
+
 
+    private void handleMissingResource(HttpServletRequest request,
+            HttpServletResponse response, String jspUri)
+            throws ServletException, IOException {
+
+        String includeRequestUri =
+            (String)request.getAttribute("javax.servlet.include.request_uri");
+
+        if (includeRequestUri != null) {
+            // This file was included. Throw an exception as
+            // a response.sendError() will be ignored
+            String msg =
+                Localizer.getMessage("jsp.error.file.not.found",jspUri);
+            // Strictly, filtering this is an application
+            // responsibility but just in case...
+            throw new ServletException(SecurityUtil.filter(msg));
+        } else {
+            try {
+                response.sendError(HttpServletResponse.SC_NOT_FOUND,
+                        request.getRequestURI());
+            } catch (IllegalStateException ise) {
+                log.error(Localizer.getMessage("jsp.error.file.not.found",
+                        jspUri));
+            }
+        }
+        return;
     }
 
 

Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java?rev=683969&r1=683968&r2=683969&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java 
(original)
+++ tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java Fri Aug  
8 07:08:21 2008
@@ -334,6 +334,9 @@
             } else {
                 throw ex;
             }
+        } catch (FileNotFoundException fnfe) {
+            // File has been removed. Let caller handle this.
+            throw fnfe;
         } catch (IOException ex) {
             if (options.getDevelopment()) {
                 throw handleJspException(ex);



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to