Alternative fix for bug 48795. Add a new property to control if the next request...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 11 Mar 2010 20:28:34 +0000 (20:28 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 11 Mar 2010 20:28:34 +0000 (20:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@922010 13f79535-47bb-0310-9956-ffa450edef68

conf/web.xml
java/org/apache/jasper/EmbeddedServletOptions.java
java/org/apache/jasper/JspC.java
java/org/apache/jasper/JspCompilationContext.java
java/org/apache/jasper/Options.java
java/org/apache/jasper/resources/LocalStrings.properties

index 3db15fd..a61ab24 100644 (file)
   <!--                       to be checked on every access.                 -->
   <!--                       Used in development mode only. [4]             -->
   <!--                                                                      -->
+  <!--   recompileOnFail     If a JSP compilation fails should the          -->
+  <!--                       modificationTestInterval be ignored and the    -->
+  <!--                       next access trigger a re-compilation attempt?  -->
+  <!--                       Used in development mode only and is disabled  -->
+  <!--                       by default as compilation may be expensive and -->
+  <!--                       could lead to excessive resource usage.        -->
+  <!--                       [false]                                        -->
+  <!--                                                                      -->
   <!--   scratchdir          What scratch directory should we use when      -->
   <!--                       compiling JSP pages?  [default work directory  -->
   <!--                       for the current web application]               -->
index 8284a8c..3fdb065 100644 (file)
@@ -170,6 +170,11 @@ public final class EmbeddedServletOptions implements Options {
     private int modificationTestInterval = 4;
     
     /**
+     * Is re-compilation attempted immediately after a failure?
+     */
+    private boolean recompileOnFail = false;
+    
+    /**
      * Is generation of X-Powered-By response header enabled/disabled?
      */
     private boolean xpoweredBy;
@@ -238,6 +243,13 @@ public final class EmbeddedServletOptions implements Options {
     }
     
     /**
+     * Re-compile on failure.
+     */
+    public boolean getRecompileOnFail() {
+        return recompileOnFail;
+    }
+    
+    /**
      * Is Jasper being used in development mode?
      */
     public boolean getDevelopment() {
@@ -477,6 +489,18 @@ public final class EmbeddedServletOptions implements Options {
             }
         }
         
+        String recompileOnFail = config.getInitParameter("recompileOnFail"); 
+        if (recompileOnFail != null) {
+            if (recompileOnFail.equalsIgnoreCase("true")) {
+                this.recompileOnFail = true;
+            } else if (recompileOnFail.equalsIgnoreCase("false")) {
+                this.recompileOnFail = false;
+            } else {
+                if (log.isWarnEnabled()) {
+                    log.warn(Localizer.getMessage("jsp.warning.recompileOnFail"));
+                }
+            }
+        }
         String development = config.getInitParameter("development");
         if (development != null) {
             if (development.equalsIgnoreCase("true")) {
index d524df5..afca8cf 100644 (file)
@@ -520,6 +520,16 @@ public class JspC implements Options {
         return 0;
     }
 
+
+    /**
+     * In JspC this always returns <code>false</code>.
+     * {@inheritDoc}
+     */
+    public boolean getRecompileOnFail() {
+        return false;
+    }
+    
+    
     /**
      * In JspC this always returns <code>false</code>.
      * {@inheritDoc}
index a3a8a4a..31fcf4a 100644 (file)
@@ -595,6 +595,10 @@ public class JspCompilationContext {
             } catch (JasperException ex) {
                 // Cache compilation exception
                 jsw.setCompilationException(ex);
+                if (options.getDevelopment() && options.getRecompileOnFail()) {
+                    // Force a recompilation attempt on next access
+                    jsw.setLastModificationTest(-1);
+                }
                 throw ex;
             } catch (Exception ex) {
                 JasperException je = new JasperException(
index aa0c1c0..fcf011c 100644 (file)
@@ -197,6 +197,12 @@ public interface Options {
      */
     public int getModificationTestInterval();
     
+
+    /**
+     * Re-compile on failure.
+     */
+    public boolean getRecompileOnFail();
+    
     /**
      * Is caching enabled (used for precompilation).
      */
index 0ca8b0f..409da71 100644 (file)
@@ -168,6 +168,7 @@ jsp.warning.mappedFile=Warning: Invalid value for the initParam mappedFile. Will
 jsp.warning.classDebugInfo=Warning: Invalid value for the initParam classdebuginfo. Will use the default value of \"false\"
 jsp.warning.checkInterval=Warning: Invalid value for the initParam checkInterval. Will use the default value of \"300\" seconds
 jsp.warning.modificationTestInterval=Warning: Invalid value for the initParam modificationTestInterval. Will use the default value of \"4\" seconds
+jsp.warning.recompileOnFail=Warning: Invalid value for the initParam recompileOnFail. Will use the default value of \"false\"
 jsp.warning.development=Warning: Invalid value for the initParam development. Will use the default value of \"true\"
 jsp.warning.fork=Warning: Invalid value for the initParam fork. Will use the default value of \"true\"
 jsp.warning.reloading=Warning: Invalid value for the initParam reloading. Will use the default value of \"true\"