geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r999682 - in /geronimo/external/trunk/tomcat-parent-7.0.0: catalina/src/main/java/org/apache/catalina/ catalina/src/main/java/org/apache/catalina/core/ catalina/src/main/java/org/apache/catalina/deploy/ catalina/src/main/java/org/apache/cat...
Date Tue, 21 Sep 2010 23:10:14 GMT
Author: djencks
Date: Tue Sep 21 23:10:14 2010
New Revision: 999682

URL: http://svn.apache.org/viewvc?rev=999682&view=rev
Log:
GERONIMO-5621 bug 49916 simplify how explicit jsp servlets work

Modified:
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Context.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Wrapper.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/ApplicationDispatcher.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardContext.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardWrapperValve.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/deploy/WebXml.java
    geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/ContextConfig.java
    geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/servlet/JspServlet.java

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Context.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Context.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Context.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Context.java
Tue Sep 21 23:10:14 2010
@@ -1220,5 +1220,7 @@ public interface Context extends Contain
      */
     public boolean getPaused();
 
+    boolean isServlet22();
+
 }
 

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Globals.java
Tue Sep 21 23:10:14 2010
@@ -119,16 +119,6 @@ public final class Globals {
     public static final String ERROR_MESSAGE_ATTR =
         "javax.servlet.error.message";
 
-
-    /**
-     * The request attribute under which we expose the value of the
-     * <code>&lt;jsp-file&gt;</code> value associated with this servlet,
-     * if any.
-     */
-    public static final String JSP_FILE_ATTR =
-        "org.apache.catalina.jsp_file";
-
-
     /**
      * The request attribute under which we store the key size being used for
      * this SSL connection (as an object of type java.lang.Integer).

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Wrapper.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Wrapper.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Wrapper.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/Wrapper.java
Tue Sep 21 23:10:14 2010
@@ -85,20 +85,6 @@ public interface Wrapper extends Contain
 
 
     /**
-     * Return the context-relative URI of the JSP file for this servlet.
-     */
-    public String getJspFile();
-
-
-    /**
-     * Set the context-relative URI of the JSP file for this servlet.
-     *
-     * @param jspFile JSP file URI
-     */
-    public void setJspFile(String jspFile);
-
-
-    /**
      * Return the load-on-startup order value (negative value means
      * load on first call).
      */

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/ApplicationDispatcher.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/ApplicationDispatcher.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/ApplicationDispatcher.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/ApplicationDispatcher.java
Tue Sep 21 23:10:14 2010
@@ -643,11 +643,6 @@ final class ApplicationDispatcher
         
         // Call the service() method for the allocated servlet instance
         try {
-            String jspFile = wrapper.getJspFile();
-            if (jspFile != null)
-                request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
-            else
-                request.removeAttribute(Globals.JSP_FILE_ATTR);
             support.fireInstanceEvent(InstanceEvent.BEFORE_DISPATCH_EVENT,
                                       servlet, request, response);
             // for includes/forwards
@@ -655,23 +650,19 @@ final class ApplicationDispatcher
                filterChain.doFilter(request, response);
              }
             // Servlet Service Method is called by the FilterChain
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
                                       servlet, request, response);
         } catch (ClientAbortException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
                                       servlet, request, response);
             ioException = e;
         } catch (IOException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
                                       servlet, request, response);
             wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
                              wrapper.getName()), e);
             ioException = e;
         } catch (UnavailableException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
                                       servlet, request, response);
             wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
@@ -679,7 +670,6 @@ final class ApplicationDispatcher
             servletException = e;
             wrapper.unavailable(e);
         } catch (ServletException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
                                       servlet, request, response);
             Throwable rootCause = StandardWrapper.getRootCause(e);
@@ -689,7 +679,6 @@ final class ApplicationDispatcher
             }
             servletException = e;
         } catch (RuntimeException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,
                                       servlet, request, response);
             wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardContext.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardContext.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardContext.java
Tue Sep 21 23:10:14 2010
@@ -2418,19 +2418,6 @@ public class StandardContext extends Con
             }
         }
 
-        String jspFile = wrapper.getJspFile();
-        if ((jspFile != null) && !jspFile.startsWith("/")) {
-            if (isServlet22()) {
-                if(log.isDebugEnabled())
-                    log.debug(sm.getString("standardContext.wrapper.warning",
-                                       jspFile));
-                wrapper.setJspFile("/" + jspFile);
-            } else {
-                throw new IllegalArgumentException
-                    (sm.getString("standardContext.wrapper.error", jspFile));
-            }
-        }
-
         super.addChild(child);
 
         if (isJspServlet && oldJspServlet != null) {
@@ -5076,7 +5063,7 @@ public class StandardContext extends Con
     /**
      * Are we processing a version 2.2 deployment descriptor?
      */
-    protected boolean isServlet22() {
+    public boolean isServlet22() {
 
         if (this.publicId == null)
             return (false);

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardWrapperValve.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardWrapperValve.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardWrapperValve.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/core/StandardWrapperValve.java
Tue Sep 21 23:10:14 2010
@@ -173,7 +173,6 @@ final class StandardWrapperValve
         try {
             response.sendAcknowledgement();
         } catch (IOException e) {
-        	request.removeAttribute(Globals.JSP_FILE_ATTR);
             container.getLogger().warn(sm.getString("standardWrapper.acknowledgeException",
                              wrapper.getName()), e);
             throwable = e;
@@ -206,11 +205,6 @@ final class StandardWrapperValve
         // Call the filter chain for this request
         // NOTE: This also calls the servlet's service() method
         try {
-            String jspFile = wrapper.getJspFile();
-            if (jspFile != null)
-            	request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
-            else
-            	request.removeAttribute(Globals.JSP_FILE_ATTR);
             if ((servlet != null) && (filterChain != null)) {
                 // Swallow output if needed
                 if (context.getSwallowOutput()) {
@@ -246,19 +240,15 @@ final class StandardWrapperValve
                 }
 
             }
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
         } catch (ClientAbortException e) {
-        	request.removeAttribute(Globals.JSP_FILE_ATTR);
             throwable = e;
             exception(request, response, e);
         } catch (IOException e) {
-        	request.removeAttribute(Globals.JSP_FILE_ATTR);
             container.getLogger().error(sm.getString("standardWrapper.serviceException",
                              wrapper.getName()), e);
             throwable = e;
             exception(request, response, e);
         } catch (UnavailableException e) {
-        	request.removeAttribute(Globals.JSP_FILE_ATTR);
             container.getLogger().error(sm.getString("standardWrapper.serviceException",
                              wrapper.getName()), e);
             //            throwable = e;
@@ -278,7 +268,6 @@ final class StandardWrapperValve
             // Do not save exception in 'throwable', because we
             // do not want to do exception(request, response, e) processing
         } catch (ServletException e) {
-        	request.removeAttribute(Globals.JSP_FILE_ATTR);
             Throwable rootCause = StandardWrapper.getRootCause(e);
             if (!(rootCause instanceof ClientAbortException)) {
                 container.getLogger().error(sm.getString("standardWrapper.serviceException",
@@ -287,7 +276,6 @@ final class StandardWrapperValve
             throwable = e;
             exception(request, response, e);
         } catch (Throwable e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             container.getLogger().error(sm.getString("standardWrapper.serviceException",
                              wrapper.getName()), e);
             throwable = e;
@@ -407,11 +395,6 @@ final class StandardWrapperValve
         // Call the filter chain for this request
         // NOTE: This also calls the servlet's event() method
         try {
-            String jspFile = wrapper.getJspFile();
-            if (jspFile != null)
-                request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
-            else
-                request.removeAttribute(Globals.JSP_FILE_ATTR);
             if ((servlet != null) && (filterChain != null)) {
 
                 // Swallow output if needed
@@ -430,25 +413,20 @@ final class StandardWrapperValve
                 }
 
             }
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
         } catch (ClientAbortException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             throwable = e;
             exception(request, response, e);
         } catch (IOException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             container.getLogger().error(sm.getString("standardWrapper.serviceException",
                              wrapper.getName()), e);
             throwable = e;
             exception(request, response, e);
         } catch (UnavailableException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             container.getLogger().error(sm.getString("standardWrapper.serviceException",
                              wrapper.getName()), e);
             // Do not save exception in 'throwable', because we
             // do not want to do exception(request, response, e) processing
         } catch (ServletException e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             Throwable rootCause = StandardWrapper.getRootCause(e);
             if (!(rootCause instanceof ClientAbortException)) {
                 container.getLogger().error(sm.getString("standardWrapper.serviceException",
@@ -457,7 +435,6 @@ final class StandardWrapperValve
             throwable = e;
             exception(request, response, e);
         } catch (Throwable e) {
-            request.removeAttribute(Globals.JSP_FILE_ATTR);
             container.getLogger().error(sm.getString("standardWrapper.serviceException",
                              wrapper.getName()), e);
             throwable = e;

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/deploy/WebXml.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/deploy/WebXml.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/deploy/WebXml.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/deploy/WebXml.java
Tue Sep 21 23:10:14 2010
@@ -1230,10 +1230,10 @@ public class WebXml {
             // Icons are ignored
             // Only set this if it is non-null else every servlet will get
             // marked as the JSP servlet
-            String jspFile = servlet.getJspFile();
-            if (jspFile != null) {
-                wrapper.setJspFile(jspFile);
-            }
+//            String jspFile = servlet.getJspFile();
+//            if (jspFile != null) {
+//                wrapper.setJspFile(jspFile);
+//            }
             if (servlet.getLoadOnStartup() != null) {
                 wrapper.setLoadOnStartup(servlet.getLoadOnStartup().intValue());
             }

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/ContextConfig.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/ContextConfig.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/ContextConfig.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/catalina/src/main/java/org/apache/catalina/startup/ContextConfig.java
Tue Sep 21 23:10:14 2010
@@ -1247,6 +1247,11 @@ public class ContextConfig
                 ok = webXml.merge(orderedFragments);
             }
 
+            // Step 6.5 Convert explicitly mentioned jsps to servlets
+            if (!false) {
+                convertJsps(webXml);
+            }
+
             // Step 7. Apply merged web.xml to Context
             if (ok) {
                 webXml.configureContext(context);
@@ -1285,10 +1290,41 @@ public class ContextConfig
             }
         } else {
             // Apply unmerged web.xml to Context
+            convertJsps(webXml);
             webXml.configureContext(context);
         }
     }
 
+    private void convertJsps(WebXml webXml) {
+        ServletDef jspServlet = webXml.getServlets().get("jsp");
+        for (ServletDef servletDef: webXml.getServlets().values()) {
+            if (servletDef.getJspFile() != null) {
+                convertJsp(servletDef, jspServlet);
+            }
+        }
+    }
+
+    private void convertJsp(ServletDef servletDef, ServletDef jspServletDef) {
+        servletDef.setServletClass(org.apache.catalina.core.Constants.JSP_SERVLET_CLASS);
+        String jspFile = servletDef.getJspFile();
+        servletDef.getParameterMap().put("jspFile", jspFile);
+        if ((jspFile != null) && !jspFile.startsWith("/")) {
+            if (context.isServlet22()) {
+                if(log.isDebugEnabled())
+                    log.debug(sm.getString("standardContext.wrapper.warning",
+                                       jspFile));
+                jspFile = "/" + jspFile;
+            } else {
+                throw new IllegalArgumentException
+                    (sm.getString("standardContext.wrapper.error", jspFile));
+            }
+        }
+        servletDef.setJspFile(null);
+        for (Map.Entry<String, String> initParam: jspServletDef.getParameterMap().entrySet())
{
+            servletDef.addInitParameter(initParam.getKey(), initParam.getValue());
+        }
+    }
+
     protected WebXml createWebXml() {
         return new WebXml();
     }

Modified: geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/servlet/JspServlet.java
URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/servlet/JspServlet.java?rev=999682&r1=999681&r2=999682&view=diff
==============================================================================
--- geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/servlet/JspServlet.java
(original)
+++ geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/servlet/JspServlet.java
Tue Sep 21 23:10:14 2010
@@ -20,6 +20,10 @@ package org.apache.jasper.servlet;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -64,6 +68,9 @@ public class JspServlet extends HttpServ
     private ServletConfig config;
     private Options options;
     private JspRuntimeContext rctxt;
+    //jspFIle for a jsp configured explicitly as a servlet, in environments where this configuration
is
+    //translated into an init-param for this servlet.
+    private String jspFile;
 
 
     /*
@@ -104,7 +111,36 @@ public class JspServlet extends HttpServ
             options = new EmbeddedServletOptions(config, context);
         }
         rctxt = new JspRuntimeContext(context, options);
-        
+        if (config.getInitParameter("jspFile") != null) {
+            jspFile = config.getInitParameter("jspFile");
+            try {
+                if (null == context.getResource(jspFile)) {
+                    throw new ServletException("missing jspFile");
+                }
+            } catch (MalformedURLException e) {
+                throw new ServletException("Can not locate jsp file", e);
+            }
+            try {
+                serviceJspFile(null, null, jspFile, null, true);
+                if (SecurityUtil.isPackageProtectionEnabled()){
+                   AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
+                        public Object run() throws IOException, ServletException {
+                            serviceJspFile(null, null, jspFile, null, true);
+                            return null;
+                        }
+                    });
+                } else {
+                    serviceJspFile(null, null, jspFile, null, true);
+                }
+            } catch (IOException e) {
+                throw new ServletException("Could not precompile jsp: " + jspFile, e);
+            } catch (PrivilegedActionException e) {
+                Throwable t = e.getCause();
+                if (t instanceof ServletException) throw (ServletException)t;
+                throw new ServletException("Could not precompile jsp: " + jspFile, e);
+            }
+        }
+
         if (log.isDebugEnabled()) {
             log.debug(Localizer.getMessage("jsp.message.scratch.dir.is",
                     options.getScratchDir().toString()));
@@ -213,14 +249,15 @@ public class JspServlet extends HttpServ
     public void service (HttpServletRequest request, 
     			 HttpServletResponse response)
                 throws ServletException, IOException {
+        //jspFile may be configured as an init-param for this servlet instance
+        String jspUri = jspFile;
 
-        String jspUri = null;
-
-        String jspFile = (String) request.getAttribute(Constants.JSP_FILE);
-        if (jspFile != null) {
-            // JSP is specified via <jsp-file> in <servlet> declaration
-            jspUri = jspFile;
-        } else {
+        if (jspUri == null) {
+            // JSP specified via <jsp-file> in <servlet> declaration and supplied
through
+            //custom servlet container code
+            jspUri = (String) request.getAttribute(Constants.JSP_FILE);
+        }
+        if (jspUri == null) {
             /*
              * Check to see if the requested JSP has been the target of a
              * RequestDispatcher.include()
@@ -228,7 +265,7 @@ public class JspServlet extends HttpServ
             jspUri = (String) request.getAttribute(Constants.INC_SERVLET_PATH);
             if (jspUri != null) {
                 /*
-		 * Requested JSP has been target of
+                 * Requested JSP has been target of
                  * RequestDispatcher.include(). Its path is assembled from the
                  * relevant javax.servlet.include.* request attributes
                  */



Mime
View raw message