From 560ae38c7a7033f7d8b02d5aefa6f7a86814edb2 Mon Sep 17 00:00:00 2001 From: remm Date: Sat, 2 Sep 2006 09:28:35 +0000 Subject: [PATCH] - Separate processing of exceptions from the servlet (so that IOE doesn't cause problems anymore: bug 38713). - Only Compiler will attempt to remove the files (before the compilation), otherwise multiple things can happen in parallel. - Code cleanup (I suppose I'll have to do a big cleanup soon ...). git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@439565 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/jasper/JspCompilationContext.java | 11 ++-- java/org/apache/jasper/compiler/Compiler.java | 4 +- .../apache/jasper/servlet/JspServletWrapper.java | 69 +++++++++++++++------- 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/java/org/apache/jasper/JspCompilationContext.java b/java/org/apache/jasper/JspCompilationContext.java index 344d29fbb..97687a292 100644 --- a/java/org/apache/jasper/JspCompilationContext.java +++ b/java/org/apache/jasper/JspCompilationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 1999,2004 The Apache Software Foundation. + * Copyright 1999,2004-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,6 @@ public class JspCompilationContext { private String classPath; private String baseURI; - private String baseOutputDir; private String outputDir; private ServletContext context; private URLClassLoader loader; @@ -538,10 +537,8 @@ public class JspCompilationContext { // ==================== Removal ==================== public void incrementRemoved() { - if (removed > 1) { - jspCompiler.removeGeneratedFiles(); - if( rctxt != null ) - rctxt.removeWrapper(jspUri); + if (removed == 0 && rctxt != null) { + rctxt.removeWrapper(jspUri); } removed++; } @@ -559,6 +556,7 @@ public class JspCompilationContext { createCompiler(); if (isPackagedTagFile || jspCompiler.isOutDated()) { try { + jspCompiler.removeGeneratedFiles(); jspLoader = null; jspCompiler.compile(); jsw.setReload(true); @@ -568,7 +566,6 @@ public class JspCompilationContext { jsw.setCompilationException(ex); throw ex; } catch (Exception ex) { - ex.printStackTrace(); JasperException je = new JasperException( Localizer.getMessage("jsp.error.unable.compile"), ex); diff --git a/java/org/apache/jasper/compiler/Compiler.java b/java/org/apache/jasper/compiler/Compiler.java index f2d43bf94..5e697d28e 100644 --- a/java/org/apache/jasper/compiler/Compiler.java +++ b/java/org/apache/jasper/compiler/Compiler.java @@ -1,5 +1,5 @@ /* - * Copyright 1999,2004-2005 The Apache Software Foundation. + * Copyright 1999,2004-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -373,7 +373,6 @@ public abstract class Compiler { jspRealLastModified = uc.getLastModified(); uc.getInputStream().close(); } catch (Exception e) { - e.printStackTrace(); return true; } @@ -430,7 +429,6 @@ public abstract class Compiler { return true; } } catch (Exception e) { - e.printStackTrace(); return true; } } diff --git a/java/org/apache/jasper/servlet/JspServletWrapper.java b/java/org/apache/jasper/servlet/JspServletWrapper.java index 6b5e5580e..2d67bb157 100644 --- a/java/org/apache/jasper/servlet/JspServletWrapper.java +++ b/java/org/apache/jasper/servlet/JspServletWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 1999,2004-2005 The Apache Software Foundation. + * Copyright 1999,2004-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -288,6 +288,7 @@ public class JspServletWrapper { HttpServletResponse response, boolean precompile) throws ServletException, IOException, FileNotFoundException { + try { if (ctxt.isRemoved()) { @@ -328,6 +329,53 @@ public class JspServletWrapper { return; } + } catch (FileNotFoundException ex) { + ctxt.incrementRemoved(); + 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 by the + // servlet engine. + throw new ServletException(ex); + } else { + try { + response.sendError(HttpServletResponse.SC_NOT_FOUND, + ex.getMessage()); + } catch (IllegalStateException ise) { + log.error(Localizer.getMessage("jsp.error.file.not.found", + ex.getMessage()), + ex); + } + } + } catch (ServletException ex) { + if (options.getDevelopment()) { + throw handleJspException(ex); + } else { + throw ex; + } + } catch (IOException ex) { + if (options.getDevelopment()) { + throw handleJspException(ex); + } else { + throw ex; + } + } catch (IllegalStateException ex) { + if (options.getDevelopment()) { + throw handleJspException(ex); + } else { + throw ex; + } + } catch (Exception ex) { + if (options.getDevelopment()) { + throw handleJspException(ex); + } else { + throw new JasperException(ex); + } + } + + try { + /* * (3) Service request */ @@ -360,25 +408,6 @@ public class JspServletWrapper { (HttpServletResponse.SC_SERVICE_UNAVAILABLE, ex.getMessage()); } - } catch (FileNotFoundException ex) { - ctxt.incrementRemoved(); - 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 by the - // servlet engine. - throw new ServletException(ex); - } else { - try { - response.sendError(HttpServletResponse.SC_NOT_FOUND, - ex.getMessage()); - } catch (IllegalStateException ise) { - log.error(Localizer.getMessage("jsp.error.file.not.found", - ex.getMessage()), - ex); - } - } } catch (ServletException ex) { if(options.getDevelopment()) { throw handleJspException(ex); -- 2.11.0