tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anil K. Vijendran" <Anil.Vijend...@eng.sun.com>
Subject Re: Patch for Jasper for current JServ
Date Tue, 02 Nov 1999 23:57:12 GMT
Hi Tom,

Good work there. I'm reminded of me trying to get JSP run on JServ long time back (JSWDK 1.0
EA2). It was such a mess.

I guess I'd like to be convinced why this is a useful thing. It is only a matter of a month
or so before
we can have a decent (by decent I mean release quality) servlet (2.2) engine and jsp engine
running
on apache. Also Servlet 2.0 is ways back and catching things like NoSuchMethodError only makes
the code cluttered and quite unmaintainable.

There's also some JSP standard actions that won't work without RequestDispatcher. Need some
fancy workarounds for those.

Thanks.

Tom Seago wrote:

> In the interest of using the Jasper engine with the current JServ code,
> I'v patched it to do reasonable things when it encounters
> NoSuchMethodErrors rather than just blowing up.  Generally this means it
> blows up in a predicatable/more friendly manner, but heh, that's
> something.  Actually there were a couple of items that made things
> unusable, but that's fixed.
>
> One caveat of this approach is that JServ wasn't dealing with
> getRealPath stuff well, so rather than modifying JServ, I added a
> "realpath" init parameter that can be used to specify the base of the
> directory hierarchy to locate the source for JSP pages (ie. the .jsp
> files not the .java files).  I know this isn't ideal but it will work
> for the next month or so until Jakarata is fully ready to go.
>
> On a BTW note - did you know that if you call loadClass(null) with the
> preV2 Blackdown JVM for Linux, it will dump core?  Fix is - don't do
> that :)
>
> If someone feels like CVS'ing this patch, that would be create.  All of
> the changes deal with exceptional cases (such as NoSuchMethodErrors) not
> the normal case.
>
>                                         (-: Tom ;-)
>
>   ------------------------------------------------------------------------
> diff -ubBwr jt.orig/src/share/org/apache/jasper/Options.java jakarta-tomcat/src/share/org/apache/jasper/Options.java
> --- jt.orig/src/share/org/apache/jasper/Options.java    Thu Oct 14 18:24:01 1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/Options.java     Sun Oct 31 15:41:46 1999
> @@ -117,6 +117,11 @@
>       */
>      public String classpath = null;
>
> +    /**
> +     * (TOM)Real path to the JSP pages in case the server can't/won't
> +     * provide it
> +     */
> +    public String realpath = "/";
>
>      /**
>       * Are we keeping generated code around?
> @@ -169,6 +174,14 @@
>      }
>
>      /**
> +     * (TOM)What is the default real path if the servletcontext
> +     * returned null?
> +     */
> +    public String getRealPath() {
> +       return realpath;
> +    }
> +
> +    /**
>       * Create an Options object using data available from
>       * ServletConfig and ServletContext.
>       */
> @@ -208,6 +221,11 @@
>          String classpath = config.getInitParameter("classpath");
>          if (classpath != null)
>              this.classpath = classpath;
> +
> +       // (TOM)
> +        String realpath = config.getInitParameter("realpath");
> +        if (realpath != null)
> +            this.realpath = realpath;
>
>          String verbosityLevel = config.getInitParameter("jspVerbosityLevel");
>
> diff -ubBwr jt.orig/src/share/org/apache/jasper/compiler/Compiler.java jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java
> --- jt.orig/src/share/org/apache/jasper/compiler/Compiler.java  Thu Oct 14 18:24:04 1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/compiler/Compiler.java   Sun Oct 31 15:41:46
1999
> @@ -98,14 +98,16 @@
>      public boolean compile()
>          throws FileNotFoundException, JasperException, Exception
>      {
> -        if (!isOutDated())
> -            return false;
>
>          String pkgName = mangler.getPackageName();
>          String className = mangler.getClassName();
>          String javaFileName = mangler.getJavaFileName();
>          String classFileName = mangler.getClassFileName();
>
> +        ctxt.setServletClassName(className);
> +        ctxt.setServletPackageName(pkgName);
> +        ctxt.setServletJavaFileName(javaFileName);
> +
>          Constants.message("jsp.message.package_name_is",
>                            new Object[] { pkgName },
>                            Constants.MED_VERBOSITY);
> @@ -119,7 +121,10 @@
>                            new Object[] { classFileName },
>                            Constants.MED_VERBOSITY);
>
> -        JspReader reader = JspReader.createJspReader(ctxt.getJspFile(), ctxt.getServletContext());
> +        if (!isOutDated())
> +            return false;
> +
> +        JspReader reader = JspReader.createJspReader(ctxt.getJspFile(), ctxt.getServletContext(),
ctxt.getOptions());
>
>          ServletWriter writer =
>              (new ServletWriter
> @@ -129,9 +134,6 @@
>
>          ctxt.setReader(reader);
>          ctxt.setWriter(writer);
> -        ctxt.setServletClassName(className);
> -        ctxt.setServletPackageName(pkgName);
> -        ctxt.setServletJavaFileName(javaFileName);
>
>          ParseEventListener listener = new JspParseEventListener(ctxt);
>
> diff -ubBwr jt.orig/src/share/org/apache/jasper/compiler/JspCompiler.java jakarta-tomcat/src/share/org/apache/jasper/compiler/JspCompiler.java
> --- jt.orig/src/share/org/apache/jasper/compiler/JspCompiler.java       Fri Oct  8 17:20:36
1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/compiler/JspCompiler.java        Sun Oct
31 15:41:46 1999
> @@ -68,6 +68,7 @@
>
>  import org.apache.jasper.JspEngineContext;
>  import org.apache.jasper.Constants;
> +import org.apache.jasper.Options;
>  import org.apache.jasper.JasperException;
>
>  /**
> @@ -259,10 +260,15 @@
>
>         File jspReal = null;
>
> -        if (ctx != null)
> -            jspReal = new File(ctx.getRealPath(jsp.getPath()));
> -        else
> -            jspReal = jsp;
> +       String rp = null;
> +        if (ctx != null) {
> +           rp = ctx.getRealPath(jsp.getPath());
> +       }
> +       if (rp==null) {
> +           // Try to use a constant
> +           rp = ctxt.getOptions().getRealPath()+jsp.getPath();
> +       }
> +       jspReal = new File(rp);
>
>          File classFile = new File(classFileName);
>
> @@ -276,20 +282,21 @@
>                  String classNameFromFile = ClassName.getClassName(classFileName);
>                 cfd = new ClassFileData(outDated, classFileName, className);
>                  cfd.incrementNumber();
> +           } else {
> +               // cn ( Class Name ) is extracted from class data.
> +               // If the file is not out-dated, it is not needed, and will
> +               // be computed only if someone ask for it.
> +               cfd = new ClassFileData(outDated, classFileName, null);
> +           }
>
>                  String cn = cfd.getClassName();
>                  int lastDot = cn.lastIndexOf('.');
>                  if (lastDot != -1)
>                      className = cn.substring(lastDot+1,
> -                                             classNameFromFile.length());
> +                                        cn.length());
>                  else
>                      className = cn;
> -           } else {
> -               // cn ( Class Name ) is extracted from class data.
> -               // If the file is not out-dated, it is not needed, and will
> -               // be computed only if someone ask for it.
> -               cfd = new ClassFileData(outDated, classFileName, null);
> -           }
> +
>          }
>      }
>  }
> diff -ubBwr jt.orig/src/share/org/apache/jasper/compiler/JspReader.java jakarta-tomcat/src/share/org/apache/jasper/compiler/JspReader.java
> --- jt.orig/src/share/org/apache/jasper/compiler/JspReader.java Fri Oct  8 17:20:36 1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/compiler/JspReader.java  Sun Oct 31 15:41:46
1999
> @@ -78,6 +78,7 @@
>
>
>  import org.apache.jasper.Constants;
> +import org.apache.jasper.Options;
>
>  /**
>   * JspReader is an input buffer for the JSP parser. It should allow
> @@ -99,6 +100,7 @@
>      int size = 0;
>
>      private ServletContext context;
> +    private Options options;
>
>      /**
>       * Keep track of parser before parsing an included file.
> @@ -187,13 +189,28 @@
>                 String fileName = file.toString();
>                 if (File.separatorChar == '\\')
>                     fileName = fileName.replace (File.separatorChar, '/');
> -                InputStream in = context.getResourceAsStream(fileName);
> -                if (in == null)
> +                InputStream in = null;
> +               // (TOM)Support 2.0 Servlet API which is sans getResourceAsStream
> +               try {
> +                   in = context.getResourceAsStream(fileName);
> +               } catch (NoSuchMethodError nsmer) {
> +                   // Try to find the real path for this thing
> +                   String rp = context.getRealPath(fileName);
> +                   if (rp==null) {
> +                       // Add our constant name
> +                       rp = options.getRealPath()+file.toString();
> +                   }
> +                   in = new FileInputStream(rp);
> +               }
> +                if (in == null) {
> +                   System.err.println("File not found '"+fileName+"'");
>                      throw new FileNotFoundException(fileName);
> +               }
>
>                  try {
>                      reader = new InputStreamReader(in);
>                  } catch (Exception ex) {
> +                   System.err.println("File not found '"+fileName+"': "+ex.getMessage());
>                      throw new FileNotFoundException(fileName + ": "+ ex.getMessage());
>                  }
>              }
> @@ -247,17 +264,18 @@
>         return true;
>      }
>
> -    protected JspReader(String file, ServletContext ctx)
> +    protected JspReader(String file, ServletContext ctx, Options options)
>         throws ParseException, FileNotFoundException
>      {
>          this.context = ctx;
> +       this.options = options;
>         pushFile(file, null);
>      }
>
> -    public static JspReader createJspReader(String file, ServletContext ctx)
> +    public static JspReader createJspReader(String file, ServletContext ctx, Options
options)
>         throws ParseException, FileNotFoundException
>      {
> -       return new JspReader(file, ctx);
> +       return new JspReader(file, ctx, options);
>      }
>
>      public boolean hasMoreInput() {
> diff -ubBwr jt.orig/src/share/org/apache/jasper/runtime/JspFactoryImpl.java jakarta-tomcat/src/share/org/apache/jasper/runtime/JspFactoryImpl.java
> --- jt.orig/src/share/org/apache/jasper/runtime/JspFactoryImpl.java     Fri Oct  8 17:20:39
1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/runtime/JspFactoryImpl.java      Sun Oct
31 15:41:46 1999
> @@ -88,7 +88,8 @@
>              return pc;
>          } catch (Exception ex) {
>              /* FIXME: need to do something reasonable here!! */
> -            ex.printStackTrace();
> +           System.err.println("DOUBLE PLUS UNGOOD: Exception during getPageContext");
> +            ex.printStackTrace(System.err);
>              return null;
>          }
>      }
> diff -ubBwr jt.orig/src/share/org/apache/jasper/runtime/JspLoader.java jakarta-tomcat/src/share/org/apache/jasper/runtime/JspLoader.java
> --- jt.orig/src/share/org/apache/jasper/runtime/JspLoader.java  Thu Oct 21 00:24:39 1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/runtime/JspLoader.java   Sun Oct 31 15:41:46
1999
> @@ -124,6 +124,10 @@
>      protected synchronized Class loadClass(String name, boolean resolve)
>         throws ClassNotFoundException
>      {
> +       if (name==null) {
> +           System.err.println("loadClass(...) called with null name");
> +           throw new ClassNotFoundException("loadClass(...) called with null name");
> +       }
>         // First, check if the class has already been loaded
>         Class c = findLoadedClass(name);
>         if (c == null) {
> diff -ubBwr jt.orig/src/share/org/apache/jasper/runtime/JspServlet.java jakarta-tomcat/src/share/org/apache/jasper/runtime/JspServlet.java
> --- jt.orig/src/share/org/apache/jasper/runtime/JspServlet.java Thu Oct 21 00:24:39 1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/runtime/JspServlet.java  Sun Oct 31 15:41:46
1999
> @@ -108,6 +108,7 @@
>                 destroy();
>                 theServlet = (HttpJspPage) servletClass.newInstance();
>             } catch (Exception ex) {
> +               ex.printStackTrace(System.err);
>                 throw new JasperException(ex);
>             }
>             theServlet.init(JspServlet.this.config);
> @@ -320,7 +321,8 @@
>              String jspUri;
>
>              if (includeUri == null)
> -               jspUri = request.getServletPath();
> +               //(TOM)         jspUri = request.getServletPath();
> +               jspUri = request.getRequestURI();
>              else
>                  jspUri = includeUri;
>
> diff -ubBwr jt.orig/src/share/org/apache/jasper/runtime/JspWriterImpl.java jakarta-tomcat/src/share/org/apache/jasper/runtime/JspWriterImpl.java
> --- jt.orig/src/share/org/apache/jasper/runtime/JspWriterImpl.java      Fri Oct  8 17:20:40
1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/runtime/JspWriterImpl.java       Sun Oct
31 15:41:46 1999
> @@ -192,7 +192,8 @@
>              if (out != null) {
>                  out.flush();
>                 // Also flush the response buffer.
> -               response.flushBuffer();
> +               try { response.flushBuffer(); }
> +               catch (NoSuchMethodError nsmer) { /* ignore */ }
>             }
>          }
>      }
> diff -ubBwr jt.orig/src/share/org/apache/jasper/runtime/PageContextImpl.java jakarta-tomcat/src/share/org/apache/jasper/runtime/PageContextImpl.java
> --- jt.orig/src/share/org/apache/jasper/runtime/PageContextImpl.java    Sun Oct 17 18:21:37
1999
> +++ jakarta-tomcat/src/share/org/apache/jasper/runtime/PageContextImpl.java     Sun Oct
31 17:25:20 1999
> @@ -108,7 +108,6 @@
>                             boolean autoFlush)
>          throws IOException, IllegalStateException, IllegalArgumentException
>      {
> -
>         // initialize state
>
>         this.servlet      = servlet;
> @@ -124,7 +123,7 @@
>         // setup session (if required)
>
>         if (request instanceof HttpServletRequest && needsSession)
> -           this.session = ((HttpServletRequest)request).getSession();
> +           this.session = ((HttpServletRequest)request).getSession(true);
>
>         if (needsSession && session == null)
>             throw new IllegalStateException("Page needs a session and none is available");
> @@ -329,15 +328,23 @@
>      public void include(String relativeUrlPath)
>          throws ServletException, IOException
>      {
> +       try {
>          String path = getAbsolutePathRelativeToContext(relativeUrlPath);
>          context.getRequestDispatcher(path).include(request, response);
> +       } catch (NoSuchMethodError nsme) {
> +           throw new ServletException(nsme.getMessage());
> +       }
>      }
>
>      public void forward(String relativeUrlPath)
>          throws ServletException, IOException
>      {
> +       try {
>          String path = getAbsolutePathRelativeToContext(relativeUrlPath);
>          context.getRequestDispatcher(path).forward(request, response);
> +       } catch (NoSuchMethodError nsme) {
> +           throw new ServletException(nsme.getMessage());
> +       }
>      }
>
>      Stack writerStack = new Stack();
> @@ -357,8 +364,13 @@
>      public void handlePageException(Exception e)
>      throws IOException, ServletException {
>
> +       try {
>         // set the request attribute with the exception.
>         request.setAttribute("javax.servlet.jsp.jspException", e);
> +       } catch (NoSuchMethodError nsme) {
> +           // Can't do redirection so use default behaviour
> +           throw new ServletException(e.toString());
> +       }
>
>         if (errorPageURL != null && !errorPageURL.equals("")) {
>             forward(errorPageURL);
>
>   ------------------------------------------------------------------------
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

--
Peace, Anil +<:-)



Mime
View raw message