You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2008/06/14 18:04:50 UTC

svn commit: r667825 - in /tomcat/sandbox/tomcat-lite/webapps: ROOT/ ROOT/WEB-INF/ addons-jasper/ addons-jasper/WEB-INF/ addons-jasper/WEB-INF/src/ addons-jasper/WEB-INF/src/org/ addons-jasper/WEB-INF/src/org/apache/ addons-jasper/WEB-INF/src/org/apache...

Author: costin
Date: Sat Jun 14 09:04:49 2008
New Revision: 667825

URL: http://svn.apache.org/viewvc?rev=667825&view=rev
Log:
Jasper integration is still intended as an add-on webapp, but the new build file just bundles it, to
make things easier. I may just move it to the main tree, too much trouble.

The integration class is pretty cool I think - tomcat-lite doesn't have any dependency on jasper except 
the interface class, which can actually be used for any template language. The only downside is that you
would do <jsp-file>foo.non_jsp_template</jsp-file>.  Precompiled jsps don't need this class.

Also, jsp recompilation not supported right now, and 6 JSP tests ( in watchdog ) fail


Added:
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/servlets/
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/servlets/jsp/
    tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/servlets/jsp/JasperCompilerTemplateClassMapper.java   (with props)
Modified:
    tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml
    tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html

Modified: tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml?rev=667825&r1=667824&r2=667825&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml (original)
+++ tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/web.xml Sat Jun 14 09:04:49 2008
@@ -7,7 +7,6 @@
    <servlet><servlet-name>_tc_users</servlet-name><servlet-class>org.apache.tomcat.servlets.sec.DigestAuthenticator</servlet-class>
      <init-param><param-name>u.test</param-name><param-value>pass</param-value></init-param>
    </servlet> 
-   <servlet-mapping><servlet-name>jspCompiler</servlet-name><url-pattern>/_jspc</url-pattern></servlet-mapping>
    <servlet-mapping><servlet-name>dav</servlet-name><url-pattern>/dav/*</url-pattern></servlet-mapping>
 
 </web-app>

Modified: tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html?rev=667825&r1=667824&r2=667825&view=diff
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html (original)
+++ tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html Sat Jun 14 09:04:49 2008
@@ -1,46 +1,4 @@
 <h1>Tomcat-Lite</h1>
 
-<h2>TODO</h2>
 
 
-<h2>Internal attributes</h2>
-
--
-
-<h2>Internal Webapps</h2>
-
-Webapps with names starting with __x_ will be treated in special ways. 
-The benefit of using webapps instead of special directories and layout is 
-that you can use the same tools to configure and deploy as with regular 
-webapps.
-They are loaded first, and have additional properties:
-
-__x_classpath* - it's WEB-INF/classes, lib will be added to the container 
-classpath. 
-In particular - you may want to place a copy of jasper.jar to 
-enable jsp compilation, without it tomcat-lite only supports precompiled jsps
-This replaces the old tomcat server/lib, common/lib, etc. Tomcat-lite supports
-only a simple classloader hierarchy ( arbitrary restriction - it would be easy
- to add more with a simple module, but for now we care more about 
- single-jar than lots of apps with conflicting libraries ). 
-
-__x_protocol* - the connectors. A load-on-startup servlet will start
-accepting http connections. The code is dependent on tomcat-lite internals, but
-can be configured and deployed using regular webapp tools.
-
-__x_deploy - internal tools to control deploy, reload and configuration. If it 
-is missing, reloading is disabled and web.xml is frozen - all configs are loaded
-from tomcatLite.ser. In a production server or tiny server you don't need
-web.xml parsing, reload and most of the deploy functions ( if you use lb 
-or are ok with a complete server restart ).
-
-__x_engine - engine specific servlets/filters - controls the dispatching, 
-servlet manager, security settings, etc. All the configuration in tomcat-lite
-is done using web.xml and servlets/filters - this replaces most of 
-the conf/ settings in tomcat.
-
-
-
-<h2>Internal servlets</h2>
-
-- 
\ No newline at end of file

Added: tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/servlets/jsp/JasperCompilerTemplateClassMapper.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/servlets/jsp/JasperCompilerTemplateClassMapper.java?rev=667825&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/servlets/jsp/JasperCompilerTemplateClassMapper.java (added)
+++ tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/servlets/jsp/JasperCompilerTemplateClassMapper.java Sat Jun 14 09:04:49 2008
@@ -0,0 +1,173 @@
+/*
+ * 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.tomcat.servlets.jsp;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.naming.NamingException;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.InstanceManager;
+import org.apache.jasper.EmbeddedServletOptions;
+import org.apache.jasper.JasperException;
+import org.apache.jasper.JspC;
+import org.apache.jasper.Options;
+import org.apache.jasper.compiler.JspRuntimeContext;
+import org.apache.jasper.servlet.JspServletWrapper;
+
+/** 
+ * The actual compiler. Maps and compile a jsp-file to a class.
+ */
+public class JasperCompilerTemplateClassMapper 
+        extends SimpleTemplateClassMapper {
+    
+    public void init(ServletConfig config) {
+        this.config = config;
+        ServletContext context = config.getServletContext();
+        context.setAttribute(InstanceManager.class.getName(), 
+                new InstanceManager() {
+
+                    public void destroyInstance(Object arg0)
+                            throws IllegalAccessException,
+                            InvocationTargetException {
+                    }
+
+                    public Object newInstance(String arg0)
+                            throws IllegalAccessException,
+                            InvocationTargetException, NamingException,
+                            InstantiationException, ClassNotFoundException {
+                        return newInstance(arg0, 
+                                this.getClass().getClassLoader());
+                    }
+
+                    public void newInstance(Object o)
+                            throws IllegalAccessException,
+                            InvocationTargetException, NamingException {
+                    }
+
+                    public Object newInstance(String className,
+                                              ClassLoader classLoader)
+                            throws IllegalAccessException,
+                            InvocationTargetException, NamingException,
+                            InstantiationException, ClassNotFoundException {
+                        Class clazz = classLoader.loadClass(className);
+                        return clazz.newInstance();
+                    }
+            
+        });
+        //      Initialize the JSP Runtime Context
+        options = new EmbeddedServletOptions(config, context);
+        
+        rctxt = new JspRuntimeContext(context, options);
+        String basePath = context.getRealPath("/");
+        File f = new File(basePath + "/WEB-INF/classes");
+        f.mkdirs();
+        //fileS.initParams.put("scratchdir",  f.getAbsolutePath());
+        // if load-on-startup: allow other servlets to find us
+
+        
+    }
+    
+    private Options options;
+    private JspRuntimeContext rctxt;
+    private ServletConfig config;
+
+    public boolean needsReload(String jspFile, Servlet s) {
+        JspServletWrapper wrapper =
+            (JspServletWrapper) rctxt.getWrapper(jspFile);
+        // TODO: extract outdate info, compilation date, etc
+        return false;
+    }
+    
+    protected Servlet compileAndInitPage(ServletContext ctx, 
+                                         String jspUri, 
+                                         ServletConfig cfg) 
+    throws ServletException {
+        try {
+            if (config == null) {
+                init(cfg);
+            }
+            JspServletWrapper wrapper =
+                (JspServletWrapper) rctxt.getWrapper(jspUri);
+            if (wrapper == null) {
+                synchronized(this) {
+                    wrapper = (JspServletWrapper) rctxt.getWrapper(jspUri);
+                    if (wrapper == null) {
+                        // Check if the requested JSP page exists, to avoid
+                        // creating unnecessary directories and files.
+                        if (null == ctx.getResource(jspUri)) {
+                            return null;
+                        }
+                        //boolean isErrorPage = exception != null;
+                        wrapper = new JspServletWrapper(cfg, options, jspUri,
+                                false, rctxt);
+                        rctxt.addWrapper(jspUri,wrapper);
+                    }
+                }
+            }
+
+            wrapper.getJspEngineContext().compile();
+            return wrapper.getServlet();
+        } catch (IOException ex) {
+            throw new ServletException(ex);
+        }
+    }
+
+    /**
+     *  
+     * Do the compilation - without JspServletWrapper
+     * 
+     * Options: 
+     *  - jasper.jar in classpath, we do Class.forName for main()
+     *  - TODO: exec jasper.sh ( or any other script set in params ) 
+     *  - TODO: redirect to a different servlet
+     * 
+     * Not used right - see previous method for a safer approach
+     * 
+     * @param ctx
+     * @param jspPath
+     */
+   public void compileJspDirect(ServletContext ctx, String jspPath) {
+        //ServletContextImpl ctx = (ServletContextImpl)sctx;
+        // Params to pass to jspc:
+        // classpath 
+        // webapp base dir
+        String baseDir = ctx.getRealPath("/");
+        // jsp path ( rel. base dir )
+
+        JspC jspc = new JspC();
+        jspc.setUriroot(baseDir);
+        jspc.setTrimSpaces(false);
+        jspc.setPoolingEnabled(true);
+        jspc.setErrorOnUseBeanInvalidClassAttribute(false);
+        jspc.setClassDebugInfo(true);
+        jspc.setCaching(true);
+        jspc.setSmapDumped(true);
+
+        try {
+            jspc.execute();
+        } catch (JasperException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+}
\ No newline at end of file

Propchange: tomcat/sandbox/tomcat-lite/webapps/addons-jasper/WEB-INF/src/org/apache/tomcat/servlets/jsp/JasperCompilerTemplateClassMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org