pier 01/07/18 16:12:49 Modified: webapp/java WarpConfigurationHandler.java WarpConnection.java WarpConnector.java Added: webapp/java WarpLogger.java Log: Improved logging/debugging output of private components within the WARP connector. Revision Changes Path 1.6 +8 -4 jakarta-tomcat-connectors/webapp/java/WarpConfigurationHandler.java Index: WarpConfigurationHandler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/java/WarpConfigurationHandler.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WarpConfigurationHandler.java 2001/07/15 08:40:58 1.5 +++ WarpConfigurationHandler.java 2001/07/18 23:12:49 1.6 @@ -64,12 +64,18 @@ public class WarpConfigurationHandler { + /* ==================================================================== */ + /* Constructor */ + /* ==================================================================== */ + public WarpConfigurationHandler() { super(); } public boolean handle(WarpConnection connection) throws IOException { + WarpLogger logger=new WarpLogger(this); + logger.setContainer(connection.getConnector().getContainer()); WarpPacket packet=new WarpPacket(); // Prepare the Welcome packet @@ -86,11 +92,9 @@ String path=packet.readString(); if (Constants.DEBUG) - connection.getConnector().debug(this,"Deploying application \""+appl+ - "\" under \"http://"+host+":"+port+path); + logger.debug("Deploying application \""+appl+"\" under \"http://"+ + host+":"+port+path); return(true); - //while (true) { - // connection.recv(packet); } } 1.14 +12 -12 jakarta-tomcat-connectors/webapp/java/WarpConnection.java Index: WarpConnection.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/java/WarpConnection.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WarpConnection.java 2001/07/15 08:40:58 1.13 +++ WarpConnection.java 2001/07/18 23:12:49 1.14 @@ -82,6 +82,8 @@ private boolean started=false; /** The local thread. */ private Thread thread=null; + /** Our logger. */ + private WarpLogger logger=null; /* -------------------------------------------------------------------- */ /* Bean variables */ @@ -100,6 +102,7 @@ */ public WarpConnection() { super(); + this.logger=new WarpLogger(this); } /* ==================================================================== */ @@ -125,6 +128,7 @@ */ public void setConnector(WarpConnector connector) { this.connector=connector; + this.logger.setContainer(connector.getContainer()); } /** @@ -166,7 +170,7 @@ this.socket.close(); this.getConnector().removeLifecycleListener(this); } catch (IOException e) { - this.getConnector().log(this,"Cannot close socket",e); + logger.log("Cannot close socket",e); } } } @@ -175,8 +179,7 @@ * Process data from the socket. */ public void run() { - if (Constants.DEBUG) - this.getConnector().debug(this,"Connection starting"); + if (Constants.DEBUG) logger.debug("Connection starting"); try { this.input=this.socket.getInputStream(); @@ -185,11 +188,10 @@ this.stop(); } catch (IOException e) { - this.getConnector().log(this,"Exception on socket",e); + logger.log("Exception on socket",e); } - if (Constants.DEBUG) - this.getConnector().debug(this,"Connection terminated"); + if (Constants.DEBUG) logger.debug("Connection terminated"); } /* ==================================================================== */ @@ -202,9 +204,8 @@ public void send(WarpPacket packet) throws IOException { if (Constants.DEBUG) { - this.getConnector().debug(this,">> TYPE="+packet.getType()+ - " LENGTH="+packet.size); - this.getConnector().debug(this,">> "+packet.dump()); + logger.debug(">> TYPE="+packet.getType()+" LENGTH="+packet.size); + logger.debug(">> "+packet.dump()); } this.output.write(packet.getType()&0x0ff); @@ -244,9 +245,8 @@ } if (Constants.DEBUG) { - this.getConnector().debug(this,"<< TYPE="+packet.getType()+ - " LENGTH="+packet.size); - this.getConnector().debug(this,"<< "+packet.dump()); + logger.debug("<< TYPE="+packet.getType()+" LENGTH="+packet.size); + logger.debug("<< "+packet.dump()); } } } 1.14 +23 -120 jakarta-tomcat-connectors/webapp/java/WarpConnector.java Index: WarpConnector.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/java/WarpConnector.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WarpConnector.java 2001/07/13 03:05:24 1.13 +++ WarpConnector.java 2001/07/18 23:12:49 1.14 @@ -87,6 +87,8 @@ private Thread thread=null; /** The server socket. */ private ServerSocket server=null; + /** Our <code>WarpLogger</code>. */ + private WarpLogger logger=null; /* -------------------------------------------------------------------- */ /* Bean variables */ @@ -129,7 +131,8 @@ */ public WarpConnector() { super(); - if (Constants.DEBUG) this.debug(this,"Instance created"); + this.logger=new WarpLogger(this); + if (Constants.DEBUG) logger.debug("Instance created"); } /* ==================================================================== */ @@ -152,10 +155,11 @@ */ public void setContainer(Container container) { this.container=container; + this.logger.setContainer(container); if (Constants.DEBUG) { - if (container==null) this.debug(this,"Setting null container"); - else this.debug(this,"Setting container "+container.getClass()); + if (container==null) logger.debug("Setting null container"); + else logger.debug("Setting container "+container.getClass()); } } @@ -174,8 +178,7 @@ public void setEnableLookups(boolean enableLookups) { this.enableLookups=enableLookups; - if (Constants.DEBUG) - this.debug(this,"Setting lookup to "+enableLookups); + if (Constants.DEBUG) logger.debug("Setting lookup to "+enableLookups); } /** @@ -185,7 +188,7 @@ public ServerSocketFactory getFactory() { if (this.factory==null) { synchronized(this) { - if (Constants.DEBUG) this.debug(this,"Creating factory"); + if (Constants.DEBUG) logger.debug("Creating factory"); this.factory=new DefaultServerSocketFactory(); } } @@ -203,7 +206,7 @@ this.factory=factory; if (Constants.DEBUG) - this.debug(this,"Setting factory "+factory.getClass().getName()); + logger.debug("Setting factory "+factory.getClass().getName()); } /** @@ -226,7 +229,7 @@ this.redirectPort=redirectPort; if (Constants.DEBUG) - this.debug(this,"Setting redirection port to "+redirectPort); + logger.debug("Setting redirection port to "+redirectPort); } /** @@ -247,7 +250,7 @@ if (scheme==null) throw new NullPointerException(); this.scheme=scheme; - if (Constants.DEBUG) this.debug(this,"Setting scheme to "+scheme); + if (Constants.DEBUG) logger.debug("Setting scheme to "+scheme); } /** @@ -267,7 +270,7 @@ public void setSecure(boolean secure) { this.secure=secure; - if (Constants.DEBUG) this.debug(this,"Setting secure to "+secure); + if (Constants.DEBUG) logger.debug("Setting secure to "+secure); } /** @@ -290,7 +293,7 @@ if (info==null) throw new NullPointerException(); this.info=info; - if (Constants.DEBUG) this.debug(this,"Setting info to "+info); + if (Constants.DEBUG) logger.debug("Setting info to "+info); } /** @@ -308,7 +311,7 @@ public void setAddress(String address) { this.address=address; - if (Constants.DEBUG) this.debug(this,"Setting address to "+address); + if (Constants.DEBUG) logger.debug("Setting address to "+address); } /** @@ -328,7 +331,7 @@ throw new IllegalArgumentException("Invalid port "+redirectPort); this.port=port; - if (Constants.DEBUG) this.debug(this,"Setting port to "+port); + if (Constants.DEBUG) logger.debug("Setting port to "+port); } /** @@ -347,7 +350,7 @@ public void setAcceptCount(int count) { this.acceptCount = count; - if (Constants.DEBUG) this.debug(this,"Setting acceptCount to "+count); + if (Constants.DEBUG) logger.debug("Setting acceptCount to "+count); } @@ -402,7 +405,7 @@ if (this.server!=null) try { this.server.close(); } catch (IOException e) { - this.log(this,"Cannot close ServerSocket",e); + logger.log("Cannot close ServerSocket",e); } } @@ -450,12 +453,12 @@ this.server=fact.createSocket(port,accc,addr); } } catch (IOException e) { - this.log(this,"Error creating server socket",e); + logger.log("Error creating server socket",e); } // Can't get a hold of a server socket if (this.server==null) { - this.log(this,"Unable to create server socket"); + logger.log("Unable to create server socket"); return; } @@ -467,8 +470,8 @@ InetAddress laddr=sock.getLocalAddress(); int rport=sock.getPort(); int lport=sock.getLocalPort(); - this.log(this,"Connection from "+raddr+":"+rport+" to "+ - laddr+":"+lport); + logger.log("Connection from "+raddr+":"+rport+" to "+laddr+ + ":"+lport); WarpConnection conn=new WarpConnection(); conn.setConnector(this); conn.setSocket(sock); @@ -476,107 +479,7 @@ conn.start(); } } catch (IOException e) { - this.log(this,"Error accepting requests",e); + logger.log("Error accepting requests",e); } } - - /* ==================================================================== */ - /* Logging and debugging methods */ - /* ==================================================================== */ - - /** Log to the container logger with the specified level or to stderr */ - private void log(Object src, String msg, Exception exc, int lev) { - Container cont=this.getContainer(); - if (cont==null) { - dump(src,msg,exc); - return; - } - - Logger logg=cont.getLogger(); - if (logg==null) { - dump(src,msg,exc); - return; - } - - String cls="["+src.getClass().getName()+"] "; - if (msg==null) msg=cls; - else msg=cls.concat(msg); - - if (exc==null) logg.log(msg,lev); - else logg.log(msg,exc,lev); - } - - /** Invoked when we can't get a hold on the logger, dump to stderr */ - private void dump(Object src, String message, Exception exception) { - String cls="["+src.getClass().getName()+"] "; - - if (message!=null) { - System.err.print(cls); - System.err.println(message); - } - if (exception!=null) { - System.err.print(cls); - exception.printStackTrace(System.err); - } - } - - /** - * If Constants.DEBUG was set true at compilation time, dump a debug - * message to Standard Error. - * - * @param message The message to dump. - */ - protected void debug(Object src, String message) { - if (Constants.DEBUG) this.log(src,message,null,Logger.DEBUG); - } - - /** - * If Constants.DEBUG was set true at compilation time, dump an exception - * stack trace to Standard Error. - * - * @param exception The exception to dump. - */ - protected void debug(Object src, Exception exception) { - if (Constants.DEBUG) this.log(src,null,exception,Logger.DEBUG); - } - - /** - * If Constants.DEBUG was set true at compilation time, dump a debug - * message and a related exception stack trace to Standard Error. - * - * @param exception The exception to dump. - * @param message The message to dump. - */ - protected void debug(Object src, String message, Exception exception) { - if (Constants.DEBUG) this.log(src,message,exception,Logger.DEBUG); - } - - /** - * Log a message. - * - * @param message The message to log. - */ - protected void log(Object src, String message) { - this.log(src,message,null,Logger.ERROR); - } - - /** - * Log an exception. - * - * @param exception The exception to log. - */ - protected void log(Object src, Exception exception) { - this.log(src,null,exception,Logger.ERROR); - } - - /** - * Log an exception and related message. - * - * @param exception The exception to log. - * @param message The message to log. - */ - protected void log(Object src, String message, Exception exception) { - this.log(src,message,exception,Logger.ERROR); - } - } 1.1 jakarta-tomcat-connectors/webapp/java/WarpLogger.java Index: WarpLogger.java =================================================================== /* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999-2001 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation <http://www.apache.org/>." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact <[EMAIL PROTECTED]>. * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see <http://www.apache.org/>. * * * * ========================================================================= */ package org.apache.catalina.connector.warp; import org.apache.catalina.Container; import org.apache.catalina.Logger; public class WarpLogger { /* ==================================================================== */ /* Variables */ /* ==================================================================== */ /* -------------------------------------------------------------------- */ /* Bean variables */ /** The <code>Container</code> instance processing requests. */ private Container container=null; /** The source of log messages for this logger. */ private Object source=null; /* ==================================================================== */ /* Constructor */ /* ==================================================================== */ /** Deny empty construction. */ private WarpLogger() { super(); } /** * Construct a new instance of a <code>WarpConnector</code>. */ public WarpLogger(Object source) { super(); this.source=source; } /* ==================================================================== */ /* Bean methods */ /* ==================================================================== */ /** * Return the <code>Container</code> instance which will process all * requests received by this <code>Connector</code>. */ public Container getContainer() { return(this.container); } /** * Set the <code>Container</code> instance which will process all requests * received by this <code>Connector</code>. * * @param container The new Container to use */ public void setContainer(Container container) { this.container=container; } /* ==================================================================== */ /* Logging and debugging methods */ /* ==================================================================== */ /** Log to the container logger with the specified level or to stderr */ private void log(String msg, Exception exc, int lev) { if (this.container==null) { dump(msg,exc); return; } Logger logg=this.container.getLogger(); if (logg==null) { dump(msg,exc); return; } String cls="["+this.source.getClass().getName()+"] "; if (msg==null) msg=cls; else msg=cls.concat(msg); if (exc==null) logg.log(msg,lev); else logg.log(msg,exc,lev); } /** Invoked when we can't get a hold on the logger, dump to stderr */ private void dump(String message, Exception exception) { String cls="["+this.source.getClass().getName()+"] "; if (message!=null) { System.err.print(cls); System.err.println(message); } if (exception!=null) { System.err.print(cls); exception.printStackTrace(System.err); } } /** * If Constants.DEBUG was set true at compilation time, dump a debug * message to Standard Error. * * @param message The message to dump. */ protected void debug(String message) { if (Constants.DEBUG) this.log(message,null,Logger.DEBUG); } /** * If Constants.DEBUG was set true at compilation time, dump an exception * stack trace to Standard Error. * * @param exception The exception to dump. */ protected void debug(Exception exception) { if (Constants.DEBUG) this.log(null,exception,Logger.DEBUG); } /** * If Constants.DEBUG was set true at compilation time, dump a debug * message and a related exception stack trace to Standard Error. * * @param exception The exception to dump. * @param message The message to dump. */ protected void debug(String message, Exception exception) { if (Constants.DEBUG) this.log(message,exception,Logger.DEBUG); } /** * Log a message. * * @param message The message to log. */ protected void log(String message) { this.log(message,null,Logger.ERROR); } /** * Log an exception. * * @param exception The exception to log. */ protected void log(Exception exception) { this.log(null,exception,Logger.ERROR); } /** * Log an exception and related message. * * @param exception The exception to log. * @param message The message to log. */ protected void log(String message, Exception exception) { this.log(message,exception,Logger.ERROR); } }