cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util SystemLogHandler.java

2005-02-14 Thread markt
markt   2005/02/14 12:29:29

  Modified:jasper2/src/share/org/apache/jasper/util Tag:
tomcat_4_branch SystemLogHandler.java
  Log:
  Port fix for 33368 fromTC5. Fix leak in swallowOutput
   - Patch submitted by Rainer Jung.
  
  Revision  ChangesPath
  No   revision
  No   revision
  1.1.2.3   +8 -11 
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SystemLogHandler.java
  
  Index: SystemLogHandler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SystemLogHandler.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- SystemLogHandler.java 25 Aug 2004 20:56:15 -  1.1.2.2
  +++ SystemLogHandler.java 14 Feb 2005 20:29:29 -  1.1.2.3
  @@ -19,8 +19,6 @@
   import java.io.PrintStream;
   import java.io.IOException;
   
  -import java.util.Hashtable;
  -
   
   /**
* This helper class may be used to do sophisticated redirection of 
  @@ -55,13 +53,13 @@
   /**
* Thread <-> PrintStream associations.
*/
  -protected static Hashtable streams = new Hashtable();
  +protected static ThreadLocal streams = new ThreadLocal();
   
   
   /**
* Thread <-> ByteArrayOutputStream associations.
*/
  -protected static Hashtable data = new Hashtable();
  +protected static ThreadLocal data = new ThreadLocal();
   
   
   // - Public 
Methods
  @@ -72,9 +70,8 @@
*/
   public static void setThread() {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -PrintStream ps = new PrintStream(baos);
  -data.put(Thread.currentThread(), baos);
  -streams.put(Thread.currentThread(), ps);
  +data.set(baos);
  +streams.set(new PrintStream(baos));
   }
   
   
  @@ -83,12 +80,12 @@
*/
   public static String unsetThread() {
   ByteArrayOutputStream baos = 
  -(ByteArrayOutputStream) data.get(Thread.currentThread());
  +(ByteArrayOutputStream) data.get();
   if (baos == null) {
   return null;
   }
  -streams.remove(Thread.currentThread());
  -data.remove(Thread.currentThread());
  +streams.set(null);
  +data.set(null);
   return baos.toString();
   }
   
  @@ -100,7 +97,7 @@
* Find PrintStream to which the output must be written to.
*/
   protected PrintStream findStream() {
  -PrintStream ps = (PrintStream) streams.get(Thread.currentThread());
  +PrintStream ps = (PrintStream) streams.get();
   if (ps == null) {
   ps = out;
   }
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util SystemLogHandler.java

2005-02-08 Thread Remy Maucherat
Bill Barker wrote:
The stack is to accommodate the geniuses who have a Servlet in /appA that
includes one in /appB which in turn includes another in /appA.
In that case the servlet gets called directly by the request dispatcher, 
without going through StdWrapperValve.invoke. So there isn't any extra 
wrapping that I can see.

Using the call hierarchy feature in Eclipse, I see it could be stacked 
if loading the servlet as a result of a request dispatcher call. 
Swallowing output during servlet lifecycle operations is, IMO, not 
really worth adding all that complexity (although I don't care: I'm not 
using the feature).

Rémy
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util SystemLogHandler.java

2005-02-08 Thread Bill Barker

- Original Message -
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 08, 2005 4:21 AM
Subject: cvs commit:
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util
SystemLogHandler.java


> remm2005/02/08 04:21:18
>
>   Modified:util/java/org/apache/tomcat/util/log SystemLogHandler.java
>jasper2/src/share/org/apache/jasper/util
> SystemLogHandler.java
>   Log:
>   - 33368: fix leak in swallowOutput.
>   - Submitted by Rainer Jung.
>   - I still don't know the purpose of the stack which is used in one of
the swallow output.
>
The stack is to accommodate the geniuses who have a Servlet in /appA that
includes one in /appB which in turn includes another in /appA.




This message is intended only for the use of the person(s) listed above as the 
intended recipient(s), and may contain information that is PRIVILEGED and 
CONFIDENTIAL.  If you are not an intended recipient, you may not read, copy, or 
distribute this message or any attachment. If you received this communication 
in error, please notify us immediately by e-mail and then delete all copies of 
this message and any attachments.

In addition you should be aware that ordinary (unencrypted) e-mail sent through 
the Internet is not secure. Do not send confidential or sensitive information, 
such as social security numbers, account numbers, personal identification 
numbers and passwords, to us via ordinary (unencrypted) e-mail.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util SystemLogHandler.java

2005-02-08 Thread remm
remm2005/02/08 04:21:18

  Modified:util/java/org/apache/tomcat/util/log SystemLogHandler.java
   jasper2/src/share/org/apache/jasper/util
SystemLogHandler.java
  Log:
  - 33368: fix leak in swallowOutput.
  - Submitted by Rainer Jung.
  - I still don't know the purpose of the stack which is used in one of the 
swallow output.
  
  Revision  ChangesPath
  1.6   +14 -13
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/log/SystemLogHandler.java
  
  Index: SystemLogHandler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/log/SystemLogHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SystemLogHandler.java 2 Sep 2004 18:48:47 -   1.5
  +++ SystemLogHandler.java 8 Feb 2005 12:21:18 -   1.6
  @@ -18,7 +18,7 @@
   
   import java.io.IOException;
   import java.io.PrintStream;
  -import java.util.Hashtable;
  +import java.util.EmptyStackException;
   import java.util.Stack;
   
   /**
  @@ -58,7 +58,7 @@
   /**
* Thread <-> CaptureLog associations.
*/
  -protected static Hashtable logs = new Hashtable();
  +protected static ThreadLocal logs = new ThreadLocal();
   
   
   /**
  @@ -75,19 +75,20 @@
*/
   public static void startCapture() {
   CaptureLog log = null;
  -
  -// Synchronized for Bugzilla 31018
  -synchronized(reuse) {
  -log = reuse.isEmpty() ? new CaptureLog() : 
(CaptureLog)reuse.pop();
  +if (!reuse.isEmpty()) {
  +try {
  +log = (CaptureLog)reuse.pop();
  +} catch (EmptyStackException e) {
  +log = new CaptureLog();
  +}
  +} else {
  +log = new CaptureLog();
   }
  -
  -Thread thread = Thread.currentThread();
  -Stack stack = (Stack)logs.get(thread);
  +Stack stack = (Stack)logs.get();
   if (stack == null) {
   stack = new Stack();
  -logs.put(thread, stack);
  +logs.set(stack);
   }
  -
   stack.push(log);
   }
   
  @@ -96,7 +97,7 @@
* Stop capturing thread's output and return captured data as a String.
*/
   public static String stopCapture() {
  -Stack stack = (Stack)logs.get(Thread.currentThread());
  +Stack stack = (Stack)logs.get();
   if (stack == null || stack.isEmpty()) {
   return null;
   }
  @@ -118,7 +119,7 @@
* Find PrintStream to which the output must be written to.
*/
   protected PrintStream findStream() {
  -Stack stack = (Stack)logs.get(Thread.currentThread());
  +Stack stack = (Stack)logs.get();
   if (stack != null && !stack.isEmpty()) {
   CaptureLog log = (CaptureLog)stack.peek();
   if (log != null) {
  
  
  
  1.5   +8 -10 
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SystemLogHandler.java
  
  Index: SystemLogHandler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SystemLogHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SystemLogHandler.java 17 Mar 2004 19:23:05 -  1.4
  +++ SystemLogHandler.java 8 Feb 2005 12:21:18 -   1.5
  @@ -19,7 +19,6 @@
   import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.PrintStream;
  -import java.util.Hashtable;
   
   
   /**
  @@ -55,13 +54,13 @@
   /**
* Thread <-> PrintStream associations.
*/
  -protected static Hashtable streams = new Hashtable();
  +protected static ThreadLocal streams = new ThreadLocal();
   
   
   /**
* Thread <-> ByteArrayOutputStream associations.
*/
  -protected static Hashtable data = new Hashtable();
  +protected static ThreadLocal data = new ThreadLocal();
   
   
   // - Public 
Methods
  @@ -76,9 +75,8 @@
*/
   public static void setThread() {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -PrintStream ps = new PrintStream(baos);
  -data.put(Thread.currentThread(), baos);
  -streams.put(Thread.currentThread(), ps);
  +data.set(baos);
  +streams.set(new PrintStream(baos));
   }
   
   
  @@ -87,12 +85,12 @@
*/
   public static String unsetThread() {
   ByteArrayOutputStream baos = 
  -(ByteArrayOutputStream) data.get(Thread.currentThread());
  +(ByteArrayOutputStream) data.get();
   if (baos == null) {
   return null;
   }
  -streams.remove(Thread.currentThre

cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util SystemLogHandler.java

2003-10-28 Thread kinman
kinman  2003/10/28 11:18:54

  Modified:jasper2/src/share/org/apache/jasper/compiler Compiler.java
JspRuntimeContext.java
   jasper2/src/share/org/apache/jasper/util
SystemLogHandler.java
  Log:
  - Patch by [EMAIL PROTECTED]
  
Fix 24186: Jasper SystemLogHandler memory leak
  
  Revision  ChangesPath
  1.72  +0 -6  
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
  
  Index: Compiler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- Compiler.java 1 Oct 2003 22:44:02 -   1.71
  +++ Compiler.java 28 Oct 2003 19:18:53 -  1.72
  @@ -98,12 +98,6 @@
   // - Static
   
   
  -static {
  -
  -System.setErr(new SystemLogHandler(System.err));
  -
  -}
  -
   // Some javac are not thread safe; use a lock to serialize compilation, 
   static Object javacLock = new Object();
   
  
  
  
  1.17  +11 -5 
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspRuntimeContext.java
  
  Index: JspRuntimeContext.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspRuntimeContext.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JspRuntimeContext.java2 Sep 2003 21:39:58 -   1.16
  +++ JspRuntimeContext.java28 Oct 2003 19:18:53 -  1.17
  @@ -82,6 +82,7 @@
   import org.apache.jasper.Constants;
   import org.apache.jasper.JspCompilationContext;
   import org.apache.jasper.Options;
  +import org.apache.jasper.util.SystemLogHandler;
   import org.apache.jasper.runtime.JspFactoryImpl;
   import org.apache.jasper.security.SecurityClassLoad;
   import org.apache.jasper.servlet.JspServletWrapper;
  @@ -125,6 +126,8 @@
*/
   public JspRuntimeContext(ServletContext context, Options options) {
   
  +System.setErr(new SystemLogHandler(System.err));
  +
   this.context = context;
   this.options = options;
   
  @@ -271,7 +274,10 @@
   /**
* Process a "destory" event for this web application context.
*/
  -public void destroy() {
  +public void destroy() {
  +
  +if(System.err instanceof SystemLogHandler)
  +System.setErr(((SystemLogHandler)System.err).getWrapped());
   
   threadStop();
   
  
  
  
  1.3   +7 -3  
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SystemLogHandler.java
  
  Index: SystemLogHandler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SystemLogHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SystemLogHandler.java 2 Sep 2003 21:40:00 -   1.2
  +++ SystemLogHandler.java 28 Oct 2003 19:18:54 -  1.3
  @@ -79,7 +79,7 @@
*/
   public SystemLogHandler(PrintStream wrapped) {
   super(wrapped);
  -out = wrapped;
  +this.wrapped = wrapped;
   }
   
   
  @@ -89,7 +89,7 @@
   /**
* Wrapped PrintStream.
*/
  -protected PrintStream out = null;
  +protected PrintStream wrapped = null;
   
   
   /**
  @@ -107,6 +107,10 @@
   // - Public Methods
   
   
  +public PrintStream getWrapped() {
  +  return wrapped;
  +}
  +
   /**
* Start capturing thread's output.
*/
  @@ -142,7 +146,7 @@
   protected PrintStream findStream() {
   PrintStream ps = (PrintStream) streams.get(Thread.currentThread());
   if (ps == null) {
  -ps = out;
  +ps = wrapped;
   }
   return ps;
   }
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util SystemLogHandler.java

2002-05-22 Thread remm

remm02/05/22 23:53:23

  Modified:jasper2/src/share/org/apache/jasper/compiler Compiler.java
  Added:   jasper2/src/share/org/apache/jasper/util
SystemLogHandler.java
  Log:
  - Add the System.err capture class, as well as the new Ant based compiler.
  - Appears to be working, including compilation error reports, and fixes
problems with JSTL (at least on JDK 1.3 and 1.4; on JDK 1.2, some compiler
other than javac will have to be used).
  - Using something other than the Ant default Java compiler is not
implemented yet.
  - Known issue: will refuse to compile JSPs (even valid ones) if one JSP failed
to compile before, until it is corrected.
To fix this, the generated Java file should be moved to a separate
directory before compiling, as Jasper is unable to compile
individual files.
  
  Revision  ChangesPath
  1.5   +148 -61   
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java
  
  Index: Compiler.java
  ===
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Compiler.java 6 May 2002 04:33:15 -   1.4
  +++ Compiler.java 23 May 2002 06:53:23 -  1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
 1.4 2002/05/06 04:33:15 glenn Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/05/06 04:33:15 $
  + * $Header: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v
 1.5 2002/05/23 06:53:23 remm Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/23 06:53:23 $
*
* 
* 
  @@ -63,44 +63,93 @@
   import java.util.*;
   import java.io.*;
   import javax.servlet.jsp.tagext.TagInfo;
  +
   import org.xml.sax.Attributes;
  +
  +import org.apache.tools.ant.BuildEvent;
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.BuildListener;
  +import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.taskdefs.Javac;
  +import org.apache.tools.ant.types.Path;
  +
   import org.apache.jasper.JspCompilationContext;
   import org.apache.jasper.Constants;
   import org.apache.jasper.JasperException;
   import org.apache.jasper.logging.Logger;
  +import org.apache.jasper.util.SystemLogHandler;
   
   /**
  - * If you want to customize JSP compilation aspects, this class is
  - * something you should take a look at. 
  - * 
  - * Hope is that people can just extend Compiler and override things
  - * like isOutDated() but inherit things like compile(). This might
  - * change. 
  + * Main JSP compiler class. This class uses Ant for compiling.
*
* @author Anil K. Vijendran
* @author Mandar Raje
* @author Pierre Delisle
* @author Kin-man Chung
  + * @author Remy Maucherat
*/
   public class Compiler {
   
  -protected JavaCompiler javac;
  +
  +// - Static
  +
  +
  +protected static Project project;
  +protected static Javac javac;
  +protected static Path path;
  +protected static Path srcPath;
  +
  +protected static CompilerBuildListener listener;
  +
  +static {
  +
  +System.setErr(new SystemLogHandler(System.err));
  +
  +// Initializing project
  +project = new Project();
  +project.init();
  +
  +// Initializing javac task
  +javac = (Javac) project.createTask("javac");
  +
  +// Initializing paths
  +path = new Path(project);
  +srcPath = new Path(project);
  +
  +// Initializing listener
  +listener = new CompilerBuildListener();
  +project.addBuildListener(listener);
  +
  +}
  +
  +
  +// - Instance Variables
  +
  +
   protected Mangler mangler;
   protected JspCompilationContext ctxt;
   
   private ErrorDispatcher errDispatcher;
   private PageInfo pageInfo;
   
  +
  +//  Constructor
  +
  +
   public Compiler(JspCompilationContext ctxt) {
   this.ctxt = ctxt;
this.errDispatcher = new ErrorDispatcher();
   }
  -
  +
  +
  +// - Public Methods
  +
  +
   /** 
* Compile the jsp file from the current engine context
*/
   public void compile()
  - throws FileNotFoundException, JasperException, Exception {
  +throws FileNotFoundException, JasperException, Exception {
   
// Setup page info area
pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader()));
  @@ -158,57 +207,42 @