tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anil" <a...@wonderschools.com>
Subject I have got a query regarding PrintWriter,
Date Mon, 02 Apr 2001 10:00:42 GMT
I have been trying to intercept all the System.out and System.err request
given in the tomcat. Here is the excerpts of the Code.

I wrote a class WSPrintStream that extends PrintStream and overided the
commonly used println(..) statements.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>
/*
 * WSPrintStream.java
 *
 * Created on March 31, 2001, 1:13 PM
 */

package org.weume;

/**
 *
 * @author  anil oommen
 * @version
 */
public class WSPrintStream extends java.io.PrintStream {

    /** Holds value of property outputText. */
    private java.lang.String outputText;
    private java.lang.StringBuffer new_outputText;
    /** Utility field used by bound properties. */
    private java.beans.PropertyChangeSupport propertyChangeSupport =  new
java.beans.PropertyChangeSupport (this);




    /** Creates new WSPrintStream */
    public WSPrintStream(java.io.OutputStream out){
        super(out);
        outputText = new java.lang.String();
        new_outputText = new java.lang.StringBuffer();
    }


    public void print(boolean param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void print(char param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void print(char[] values) {
        new_outputText.append(values);
        updateOutputText();
    }

    public void print(double param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void print(float param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void print(int param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void print(java.lang.Object obj) {
        new_outputText.append(obj);
        updateOutputText();
    }

    public void print(java.lang.String str) {
        new_outputText.append(str);
        updateOutputText();
    }

    public void print(long param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void println() {
    }

    public void println(boolean param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void println(char param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void println(char[] values) {
        new_outputText.append(values);
        updateOutputText();
    }

    public void println(double param) {
        new_outputText.append(param);
        updateOutputText();

    }

    public void println(float param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void println(int param) {
        new_outputText.append(param);
        updateOutputText();
    }

    public void println(java.lang.Object obj) {
        new_outputText.append(obj);
        updateOutputText();
    }

    public void println(java.lang.String str) {
        new_outputText.append(str + "\n" );
        updateOutputText();
    }

    public void println(long param) {
        new_outputText.append(param);
        updateOutputText();
    }

    /** Add a PropertyChangeListener to the listener list.
     * @param l The listener to add.
 */
    public void addPropertyChangeListener(java.beans.PropertyChangeListener
l) {
        propertyChangeSupport.addPropertyChangeListener (l);
    }

    /** Removes a PropertyChangeListener from the listener list.
     * @param l The listener to remove.
 */
    public void
removePropertyChangeListener(java.beans.PropertyChangeListener l) {
        propertyChangeSupport.removePropertyChangeListener (l);
    }

    /** Getter for property outputText.
     * @return Value of property outputText.
 */
    public java.lang.String getOutputText() {
        return outputText;
    }

    /** Setter for property outputText.
     * @param outputText New value of property outputText.
 */
    public synchronized void updateOutputText() {
        String old_outputText = this.outputText;
        this.outputText = this.outputText + new_outputText.toString();
        this.new_outputText = new java.lang.StringBuffer();
        propertyChangeSupport.firePropertyChange ("outputText",
old_outputText, outputText);
    }

}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>


now before the execution of tomcat server I added this code

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       oldSystem_out = System.out;
        WSPrintStream wsp = new WSPrintStream(System.out);
       System.setOut(wsp);
       wsp.addPropertyChangeListener(this);

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Now I can catch all the println statements in the
>>>>>>>>public void propertyChange(java.beans.PropertyChangeEvent
evt){
when ever the System.out.println(....) is used in the System

But,,


This is a problem I  encountered

If I use
>>>>>>>>>>
java.io.PrintStream pw = new java.io.PrintStream(System.out);
pw.println("helo try reading this");
>>>>>>>

I am not able to catch the message from going to the default out put stream.
i.e my WSPrintStream does not get invoked.

It would be nice if somebody told me as to what I am doing wrong. And what
would be the best way to do it.
I have been trying to do GUI for TOMCAT and want to redirect all the Stream
output to my display without editing or modifying any of the tomcat original
source.


Thanx in Advance,

Anil Oommen
Technical Member,
Banyanlabs , Chennai India
anil@banyanlabs.com
anil@wonderschools.com









Mime
View raw message