pier        00/12/07 09:25:33

  Modified:    catalina/src/share/org/apache/catalina/connector/warp
                        WarpConnection.java WarpConnectionHandler.java
                        WarpConstants.java WarpDebug.java WarpHandler.java
                        WarpRequestHandler.java
  Added:       catalina/src/share/org/apache/catalina/connector/warp
                        WarpConnector.java WarpEngine.java
                        WarpEngineMapper.java WarpEngineValve.java
  Log:
  Catalina/Warp integration stage 1:
  - Added all required Catalina Engine classes (those are nedeed to auto
    configure Catalina from what's specified in the web server configuration)
  - Modified all Warp classes to follow Catalina's Lifecycle design pattern
  
  Revision  Changes    Path
  1.3       +132 -46   
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConnection.java
  
  Index: WarpConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConnection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WarpConnection.java       2000/11/30 21:59:29     1.2
  +++ WarpConnection.java       2000/12/07 17:25:31     1.3
  @@ -58,33 +58,61 @@
   
   import java.io.*;
   import java.net.*;
  +import org.apache.catalina.Lifecycle;
  +import org.apache.catalina.LifecycleEvent;
  +import org.apache.catalina.LifecycleException;
  +import org.apache.catalina.LifecycleListener;
  +import org.apache.catalina.util.LifecycleSupport;
   
   /**
    *
  - *
    * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
    * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
    *         Apache Software Foundation.
  - * @version CVS $Id: WarpConnection.java,v 1.2 2000/11/30 21:59:29 pier Exp $
  + * @version CVS $Id: WarpConnection.java,v 1.3 2000/12/07 17:25:31 pier Exp $
    */
  -public class WarpConnection implements Runnable {
  +public class WarpConnection implements Lifecycle, Runnable {
  +
  +    // -------------------------------------------------------------- CONSTANTS
   
  -    /** The DEBUG flag, to compile out debugging informations. */
  -    private static final boolean DEBUG = WarpConstants.DEBUG;
  +    /** Our debug flag status (Used to compile out debugging information). */
  +    private static final boolean DEBUG=WarpDebug.DEBUG;
   
  -    private WarpHandlerTable table;
  -    private Socket socket;
  -    private String name;
  +    // -------------------------------------------------------- LOCAL VARIABLES
  +
  +    /** The lifecycle event support for this component. */
  +    private LifecycleSupport lifecycle=null;
  +    /** The WarpHandlerTable contains the list of all current handlers. */
  +    private WarpHandlerTable table=null;
  +    /** The name of this connection. */
  +    private String name=null;
  +    /** Wether we started or not. */
  +    private boolean started=false;
       
  +    // -------------------------------------------------------- BEAN PROPERTIES
  +
  +    /** The socket used in this connection. */
  +    private Socket socket=null;
  +    /** The connector wich created this connection. */
  +    private WarpConnector connector=null;
  +    
  +    // ------------------------------------------------------------ CONSTRUCTOR
  +    
  +    /**
  +     * Create a new WarpConnection instance.
  +     */
       public WarpConnection() {
           super();
  +        this.lifecycle=new LifecycleSupport(this);
           this.table=new WarpHandlerTable();
  -        this.socket=null;
  -        this.name=null;
  +        if (DEBUG) this.debug("New instance created");
       }
   
  +    // --------------------------------------------------------- PUBLIC METHODS
  +
       /**
  -     *
  +     * Run the thread waiting on the socket, reading packets from the client
  +     * and dispatching them to the appropriate handler.
        */
       public void run() {
           WarpHandler han=null;
  @@ -98,14 +126,14 @@
           byte buf[]=null;
   
           // Log the connection opening
  -        this.log("Connection opened");
  +        if (DEBUG) this.debug("Connection started");
   
           try {
               // Open the socket InputStream
               in=this.socket.getInputStream();
               
               // Read packets
  -            while(true) {
  +            while(this.started) {
                   // RID number
                   b1=in.read();
                   b2=in.read();
  @@ -126,14 +154,14 @@
                   b1=in.read();
                   b2=in.read();
                   if ((b1 | b2)==-1) {
  -                    this.log("Premature LENGTH end");
  +                    this.log("Premature LEN end");
                       break;
                   }
                   len=(((b1 & 0x0ff) << 8) | (b2 & 0x0ff));
                   // Packet payload
                   buf=new byte[len];
                   if ((ret=in.read(buf,0,len))!=len) {
  -                    this.log("Premature PAYLOAD end ("+ret+" of "+len+")");
  +                    this.log("Premature packet end"+" ("+ret+" of "+len+")");
                       break;
                   }
   
  @@ -154,11 +182,15 @@
                   han.processData(typ,buf);
               }
           } catch (IOException e) {
  -            this.log(e);
  +            if (this.started) e.printStackTrace(System.err);
           }
   
           // Close this connection before terminating the thread
  -        this.close();
  +        try {
  +            this.stop();
  +        } catch (LifecycleException e) {
  +            this.log(e);
  +        }
           if (DEBUG) this.debug("Thread exited");
       }
   
  @@ -167,26 +199,30 @@
        *
        * @param sock The socket used by this connection to transfer data.
        */
  -    public void init(Socket sock) {
  +    public void start()
  +    throws LifecycleException {
           // Paranoia checks.
  -        if (sock==null) throw new NullPointerException("Null Socket");
  -        this.socket=sock;
  +        if (this.socket==null)
  +            throw new LifecycleException("Null socket");
  +        if (this.connector==null)
  +            throw new LifecycleException("Null connector");
           
           // Register the WarpConnectionHandler for RID=0 (connection)
           WarpHandler h=new WarpConnectionHandler();
  -        h.init(this,0);
  +        h.setConnection(this);
  +        h.setRequestID(0);
  +        h.start();
           // Paranoia check
           if(this.registerHandler(h,0)!=true) {
  -            System.err.println("Something happened creating the connection");
  -            this.close();
  -            return;
  +            this.stop();
  +            throw new LifecycleException("Cannot register connection handler");
           }
           // Set the thread and connection name and start the thread
  -        this.name=sock.getInetAddress().getHostAddress()+":"+sock.getPort();
  +        this.name=this.socket.getInetAddress().getHostAddress();
  +        this.name=this.name+":"+this.socket.getPort();
           new Thread(this,name).start();
       }
   
  -
       /**
        * Send a WARP packet.
        */
  @@ -215,11 +251,10 @@
   
       /**
        * Close this connection.
  -     * <br>
  -     * The socket associated with this connection is closed, all handlers are
  -     * stopped and the thread reading from the socket is interrupted.
        */
  -    public void close() {
  +    public void stop()
  +    throws LifecycleException {
  +        this.started=false;
           // Stop all handlers
           WarpHandler handlers[]=this.table.handlers();
           for (int x=0; x<handlers.length; x++) handlers[x].stop();
  @@ -228,6 +263,7 @@
               this.socket.close();
           } catch (IOException e) {
               this.log(e);
  +            throw new LifecycleException("Closing connection "+this.name,e);
           }
           
           this.socket=null;
  @@ -258,34 +294,84 @@
           return(this.table.remove(rid));
       }
   
  +    // ----------------------------------------------------------- BEAN METHODS
  +
       /**
  -     * Log a message.
  -     *
  -     * @param msg The error message to log.
  +     * Return the socket associated with this connection.
  +     */
  +    protected WarpConnector getConnector() {
  +        return(this.connector);
  +    }
  +
  +    /**
  +     * Set the socket used by this connection.
  +     */
  +    protected void setConnector(WarpConnector connector) {
  +        if (DEBUG) this.debug("Setting connector");
  +        this.connector=connector;
  +    }
  +
  +    /**
  +     * Return the socket associated with this connection.
        */
  +    protected Socket getSocket() {
  +        return(this.socket);
  +    }
  +
  +    /**
  +     * Set the socket used by this connection.
  +     */
  +    protected void setSocket(Socket socket) {
  +        if (DEBUG) this.debug("Setting socket");
  +        this.socket=socket;
  +    }
  +
  +    // ------------------------------------------------------ LIFECYCLE METHODS
  +
  +    /**
  +     * Add a lifecycle event listener to this component.
  +     */
  +    public void addLifecycleListener(LifecycleListener listener) {
  +        this.lifecycle.addLifecycleListener(listener);
  +    }
  +
  +    /**
  +     * Remove a lifecycle event listener from this component.
  +     */
  +    public void removeLifecycleListener(LifecycleListener listener) {
  +        lifecycle.removeLifecycleListener(listener);
  +    }
  +
  +    // ------------------------------------------ LOGGING AND DEBUGGING METHODS
  +
  +    /**
  +     * Dump a log message.
  +     */
       public void log(String msg) {
  -        System.out.println("[WarpConnection("+this.name+")] "+msg);
  -        System.out.flush();
  +        if (this.connector!=null) this.connector.log(msg);
  +        else WarpDebug.debug(this,msg);
       }
   
       /**
  -     * Log an exception.
  -     *
  -     * @param e The exception to log.
  +     * Dump information for an Exception.
        */
  -    public void log(Exception e) {
  -        System.out.print("[WarpConnection("+this.name+")] ");
  -        e.printStackTrace(System.out);
  -        System.out.flush();
  +    public void log(Exception exc) {
  +        if (this.connector!=null) this.connector.log(exc);
  +        else WarpDebug.debug(this,exc);
       }
   
       /**
  -     * Dump some debugging information.
  -     *
  -     * @param msg The error message to log.
  +     * Dump a debug message.
  +     */
  +    private void debug(String msg) {
  +        if (DEBUG) WarpDebug.debug(this,msg);
  +    }
  +
  +    /**
  +     * Dump information for an Exception.
        */
  -    public void debug(String msg) {
  -        if(DEBUG) this.log(msg);
  +    private void debug(Exception exc) {
  +        if (DEBUG) WarpDebug.debug(this,exc);
       }
   }
       
  
  
  
  1.4       +8 -1      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConnectionHandler.java
  
  Index: WarpConnectionHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConnectionHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WarpConnectionHandler.java        2000/11/30 21:59:30     1.3
  +++ WarpConnectionHandler.java        2000/12/07 17:25:31     1.4
  @@ -64,7 +64,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
    * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
    *         Apache Software Foundation.
  - * @version CVS $Id: WarpConnectionHandler.java,v 1.3 2000/11/30 21:59:30 pier Exp 
$
  + * @version CVS $Id: WarpConnectionHandler.java,v 1.4 2000/12/07 17:25:31 pier Exp 
$
    */
   public class WarpConnectionHandler extends WarpHandler {
       /** The WarpReader associated with this WarpConnectionHandler. */
  @@ -124,7 +124,14 @@
                       // Iterate until a valid RID is found
                       c.registerHandler(h,r);
                       this.request=r+1;
  -                    h.init(c,r);
  +                    h.setConnection(c);
  +                    h.setRequestID(r);
  +                    try {
  +                        h.start();
  +                    } catch (Exception e) {
  +                        this.log(e);
  +                        h.stop();
  +                    }
                       if (DEBUG) this.debug("CONINIT_REQ "+reader.readShort()+
                                             ":"+reader.readShort()+"="+r);
                       // Send the RID back to the WARP client
  
  
  
  1.3       +3 -2      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConstants.java
  
  Index: WarpConstants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConstants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WarpConstants.java        2000/11/30 21:59:30     1.2
  +++ WarpConstants.java        2000/12/07 17:25:31     1.3
  @@ -62,11 +62,12 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
    * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
    *         Apache Software Foundation.
  - * @version CVS $Id: WarpConstants.java,v 1.2 2000/11/30 21:59:30 pier Exp $
  + * @version CVS $Id: WarpConstants.java,v 1.3 2000/12/07 17:25:31 pier Exp $
    */
   public class WarpConstants {
  -    /* The DEBUG flag. (If false debug information will not be compiled in). */
  -    public static final boolean DEBUG = true;
  +
  +    /* The VERSION of this implementation. */
  +    public static final String VERSION = "0.5";
   
       /* The RID associated with the connection controller handler (0x00000). */
       public static final int RID_CONNECTION = 0x00000;
  
  
  
  1.2       +127 -85   
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpDebug.java
  
  Index: WarpDebug.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpDebug.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WarpDebug.java    2000/11/30 16:34:30     1.1
  +++ WarpDebug.java    2000/12/07 17:25:31     1.2
  @@ -1,85 +1,127 @@
  -/* ========================================================================= *
  - *                                                                           *
  - *                 The Apache Software License,  Version 1.1                 *
  - *                                                                           *
  - *         Copyright (c) 1999, 2000  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;
  -
  -/**
  - *
  - *
  - * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
  - * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
  - *         Apache Software Foundation.
  - * @version CVS $Id: WarpDebug.java,v 1.1 2000/11/30 16:34:30 pier Exp $
  - */
  -import java.io.*;
  -import java.net.*;
  -
  -public class WarpDebug {
  -
  -    public static void main(String argv[]) {
  -        try {
  -            ServerSocket k=new ServerSocket(8008);
  -            while (true) {
  -                Socket s=k.accept();
  -                new WarpConnection().init(s);
  -            }                
  -        } catch (Exception e) {
  -            e.printStackTrace();
  -        }
  -        System.out.println("Terminated");
  -        System.exit(0);
  -    }
  -}
  +/* ========================================================================= *
  + *                                                                           *
  + *                 The Apache Software License,  Version 1.1                 *
  + *                                                                           *
  + *         Copyright (c) 1999, 2000  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;
  +
  +/**
  + *
  + * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
  + * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
  + *         Apache Software Foundation.
  + * @version CVS $Id: WarpDebug.java,v 1.2 2000/12/07 17:25:31 pier Exp $
  + */
  +public class WarpDebug {
  +
  +    // -------------------------------------------------------------- CONSTANTS
  +
  +    /** Our debug flag status (Used to compile out debugging information). */
  +    public static final boolean DEBUG=true;
  +
  +    // -------------------------------------------------------- LOCAL VARIABLES
  +
  +    /** The lifecycle event support for this component. */
  +    private static Object synchronizer=new Object();
  +
  +    // ------------------------------------------------------------ CONSTRUCTOR
  +    
  +    /**
  +     * Deny construction.
  +     */
  +    private WarpDebug() {
  +        super();
  +    }
  +    
  +    // --------------------------------------------------------- PUBLIC METHODS
  +
  +    /**
  +     * Dump a debug message to standard error.
  +     * <br>
  +     * The body of this method will be conditionally compiled depending on the
  +     * value of the WarpConstants.DEBUG boolean flag.
  +     *
  +     * @param src The object source of this debug message.
  +     * @param msg The debug message to dump.
  +     */
  +    protected static void debug(Object src, String msg) {
  +        synchronized(synchronizer) {
  +            String c=((src==null)?("null source"):(src.getClass().getName()));
  +            System.err.println("["+c+"]");
  +            if (msg==null) return;
  +            System.err.println("    "+msg);
  +        }
  +    }
  +
  +    /**
  +     * Dump debugging information for an Exception to standard error.
  +     * <br>
  +     * The body of this method will be conditionally compiled depending on the
  +     * value of the WarpConstants.DEBUG boolean flag.
  +     *
  +     * @param src The object source of this debug message.
  +     * @param exc The Exception to dump.
  +     */
  +    protected static void debug(Object src, Exception exc) {
  +        synchronized(synchronizer) {
  +            String c=((src==null)?("null source"):(src.getClass().getName()));
  +            System.err.println("["+c+"] Exception:");
  +            if (exc==null) System.err.println("    Null Exception");
  +            else {
  +                System.err.print("    ");
  +                exc.printStackTrace(System.err);
  +            }
  +        }
  +    }
  +}
  
  
  
  1.3       +123 -58   
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpHandler.java
  
  Index: WarpHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WarpHandler.java  2000/11/30 21:59:31     1.2
  +++ WarpHandler.java  2000/12/07 17:25:32     1.3
  @@ -57,6 +57,11 @@
   package org.apache.catalina.connector.warp;
   
   import java.io.IOException;
  +import org.apache.catalina.Lifecycle;
  +import org.apache.catalina.LifecycleEvent;
  +import org.apache.catalina.LifecycleException;
  +import org.apache.catalina.LifecycleListener;
  +import org.apache.catalina.util.LifecycleSupport;
   
   /**
    *
  @@ -64,69 +69,52 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
    * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
    *         Apache Software Foundation.
  - * @version CVS $Id: WarpHandler.java,v 1.2 2000/11/30 21:59:31 pier Exp $
  + * @version CVS $Id: WarpHandler.java,v 1.3 2000/12/07 17:25:32 pier Exp $
    */
  -public abstract class WarpHandler implements Runnable {
  +public abstract class WarpHandler implements Lifecycle, Runnable {
   
  -    /**
  -     * The DEBUG flag, used to compile out debugging informations.
  -     * <br>
  -     * Sub classes of WarpHandler can write statements like
  -     * &quot;if (DEBUG) this.debug(...);&quot; to compile in or out all
  -     * debugging information calls.
  -     */
  -    protected static final boolean DEBUG = WarpConstants.DEBUG;
  +    // -------------------------------------------------------------- CONSTANTS
   
  -    /** The WarpConnection under which this handler is registered. */
  -    private WarpConnection connection;
  +    /** Our debug flag status (Used to compile out debugging information). */
  +    protected static final boolean DEBUG=WarpDebug.DEBUG;
   
  -    /** The WARP RID associated with this WarpHandler. */
  -    private int rid;
   
  +    // -------------------------------------------------------- LOCAL VARIABLES
  +
  +    /** The lifecycle event support for this component. */
  +    private LifecycleSupport lifecycle=null;
       /** The WARP packet type. */
  -    private int type;
  -    
  +    private int type=-1;
       /** The WARP packet payload. */
  -    private byte buffer[];
  -
  +    private byte buffer[]=null;
       /** Wether type and buffer have already been processed by notifyData(). */
  -    private boolean processed;
  -
  +    private boolean processed=false;
       /** Wether the stop() method was called. */
  -    private boolean stopped;
  -    
  +    private boolean stopped=false;
       /** The name of this handler. */
  -    private String name;
  +    private String name=null;
  +
  +    // -------------------------------------------------------- BEAN PROPERTIES
   
  +    /** The WarpConnection under which this handler is registered. */
  +    private WarpConnection connection=null;
  +    /** The WARP RID associated with this WarpHandler. */
  +    private int rid=-1;
  +
  +
  +    // ------------------------------------------------------------ CONSTRUCTOR
  +    
  +
       /**
        * Construct a new instance of a WarpHandler.
        */
       public WarpHandler() {
           super();
  +        this.lifecycle=new LifecycleSupport(this);
  +        if (DEBUG) this.debug("New instance created");
       }
   
  -    /**
  -     * Initialize this handler instance.
  -     * <br>
  -     * This method will initialize this handler and starts the despooling
  -     * thread that will handle the data to the processData() method.
  -     * <br>
  -     * NOTE: To receive data notification this WarpConnection must be
  -     * registered in the WarpConnection. Only un-registration (when the thread
  -     * exits) is performed.
  -     *
  -     * @param connection The WarpConnection associated with this handler.
  -     * @param rid The WARP request ID associated with this handler.
  -     */
  -    protected final void init(WarpConnection connection, int rid) {
  -        this.connection=connection;
  -        this.rid=rid;
  -        this.processed=true;
  -        this.stopped=false;
  -        String n=this.getClass().getName();
  -        this.name=n.substring(n.lastIndexOf('.')+1)+"[RID="+rid+"]";
  -        new Thread(this,this.name).start();
  -    }
  +    // --------------------------------------------------------- PUBLIC METHODS
   
       /**
        * Process WARP packets.
  @@ -193,16 +181,41 @@
       }
   
       /**
  +     * Initialize this handler instance.
  +     * <br>
  +     * This method will initialize this handler and starts the despooling
  +     * thread that will handle the data to the processData() method.
  +     * <br>
  +     * NOTE: To receive data notification this WarpConnection must be
  +     * registered in the WarpConnection. Only un-registration (when the thread
  +     * exits) is performed.
  +     */
  +    public final void start()
  +    throws LifecycleException {
  +        if (this.connection==null) 
  +            throw new LifecycleException("Null connection");
  +        if (this.rid<0)
  +            throw new LifecycleException("Invalid handler request ID");
  +
  +        this.processed=true;
  +        this.stopped=false;
  +        String n=this.getClass().getName();
  +        this.name=n.substring(n.lastIndexOf('.')+1)+"[RID="+rid+"]";
  +        new Thread(this,this.name).start();
  +    }
  +
  +    /**
        * Stop this handler.
        * <br>
        * The thread associated with this handler is stopped and this instance is
        * unregistered from the WarpConnection.
        */
  -    protected final synchronized void stop() {
  +    public final synchronized void stop() {
           // Set the stopped flag and notify all threads
           if (DEBUG) this.debug("Stopping");
           this.stopped=true;
           this.notifyAll();
  +        this.connection.removeHandler(this.rid);
           if (DEBUG) this.debug("Stopped");
       }
   
  @@ -232,6 +245,8 @@
           this.notifyAll();
       }
   
  +    // -------------------------------------------- PACKET TRANSMISSION METHODS
  +
       /**
        * Send a WARP packet.
        * <br>
  @@ -280,6 +295,8 @@
           this.send(type, buffer, 0, buffer.length);
       }
   
  +    // ------------------------------------------------------- ABSTRACT METHODS
  +
       /**
        * Process a WARP packet.
        * <br>
  @@ -298,23 +315,65 @@
        */
       public abstract boolean process(int type, byte buffer[]);
   
  +    // ------------------------------------------------------ LIFECYCLE METHODS
  +
  +    /**
  +     * Add a lifecycle event listener to this component.
  +     */
  +    public void addLifecycleListener(LifecycleListener listener) {
  +        this.lifecycle.addLifecycleListener(listener);
  +    }
  +
  +    /**
  +     * Remove a lifecycle event listener from this component.
  +     */
  +    public void removeLifecycleListener(LifecycleListener listener) {
  +        lifecycle.removeLifecycleListener(listener);
  +    }
  +
  +    // ----------------------------------------------------------- BEAN METHODS
  +
       /**
        * Return the WarpConnection associated with this handler.
  -     *
  -     * @return The WarpConnection associated with this handler or null if the
  -     *         init() method was never called.
        */
       protected WarpConnection getConnection() {
           return(this.connection);
       }
   
       /**
  +     * Set the WarpConnection associated with this handler.
  +     */
  +    protected void setConnection(WarpConnection connection) {
  +        if (DEBUG) this.debug("Setting connection");
  +        this.connection=connection;
  +    }
  +
  +    /**
  +     * Return the Request ID associated with this handler.
  +     */
  +    protected int getRequestID() {
  +        return(this.rid);
  +    }
  +
  +    /**
  +     * Set the Request ID associated with this handler.
  +     */
  +    protected void setRequestID(int rid) {
  +        if (DEBUG) this.debug("Setting Request ID "+rid);
  +        this.rid=rid;
  +    }
  +
  +    // ------------------------------------------ LOGGING AND DEBUGGING METHODS
  +
  +    /**
        * Log a message.
        *
        * @param msg The error message to log.
        */
  -    public void log(String msg) {
  -        this.getConnection().log("{"+this.name+"} "+msg);
  +    protected void log(String msg) {
  +        WarpConnection connection=this.getConnection();
  +        if (connection!=null) connection.log("{"+this.name+"} "+msg);
  +        else WarpDebug.debug(this,msg);
       }
   
       /**
  @@ -322,18 +381,24 @@
        *
        * @param e The exception to log.
        */
  -    public void log(Exception e) {
  -        this.log("Caught exception");
  -        this.getConnection().log(e);
  +    protected void log(Exception exc) {
  +        WarpConnection connection=this.getConnection();
  +        if (connection!=null) connection.log(exc);
  +        else WarpDebug.debug(this,exc);
       }
   
       /**
  -     * Dump some debugging information.
  -     *
  -     * @param msg The error message to log.
  +     * Dump a debug message.
  +     */
  +    protected void debug(String msg) {
  +        if (DEBUG) WarpDebug.debug(this,msg);
  +    }
  +
  +    /**
  +     * Dump information for an Exception.
        */
  -    public void debug(String msg) {
  -        this.getConnection().debug("{"+this.name+"} "+msg);
  +    protected void debug(Exception exc) {
  +        if (DEBUG) WarpDebug.debug(this,exc);
       }
   }
   
  
  
  
  1.2       +1 -1      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpRequestHandler.java
  
  Index: WarpRequestHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpRequestHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WarpRequestHandler.java   2000/11/30 21:59:32     1.1
  +++ WarpRequestHandler.java   2000/12/07 17:25:32     1.2
  @@ -64,7 +64,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
    * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
    *         Apache Software Foundation.
  - * @version CVS $Id: WarpRequestHandler.java,v 1.1 2000/11/30 21:59:32 pier Exp $
  + * @version CVS $Id: WarpRequestHandler.java,v 1.2 2000/12/07 17:25:32 pier Exp $
    */
   public class WarpRequestHandler extends WarpHandler {
       /** The WarpReader associated with this WarpConnectionHandler. */
  @@ -124,7 +124,7 @@
                   // The request header is finished, run the servlet (whohoo!)
                   case WarpConstants.TYP_REQINIT_RUN:
                       if (DEBUG) this.debug("REQINIT_RUN");
  -                    // Send the HOST ID back to the WARP client
  +                    // Check if we can accept (or not) this request
                       this.packet.reset();
                       if (this.headererr) {
                           this.send(WarpConstants.TYP_REQINIT_ERR,this.packet);
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConnector.java
  
  Index: WarpConnector.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  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 java.io.*;
  import java.net.*;
  import org.apache.catalina.Container;
  import org.apache.catalina.Connector;
  import org.apache.catalina.Request;
  import org.apache.catalina.Response;
  import org.apache.catalina.net.DefaultServerSocketFactory;
  import org.apache.catalina.net.ServerSocketFactory;
  import org.apache.catalina.Lifecycle;
  import org.apache.catalina.LifecycleEvent;
  import org.apache.catalina.LifecycleException;
  import org.apache.catalina.LifecycleListener;
  import org.apache.catalina.util.LifecycleSupport;
  import org.apache.catalina.connector.HttpRequestBase;
  import org.apache.catalina.connector.HttpResponseBase;
  
  /**
   *
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
   * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
   *         Apache Software Foundation.
   * @version CVS $Id: WarpConnector.java,v 1.1 2000/12/07 17:25:31 pier Exp $
   */
  public class WarpConnector implements Connector, Lifecycle, Runnable {
  
      // -------------------------------------------------------------- CONSTANTS
  
      /** Our debug flag status (Used to compile out debugging information). */
      private static final boolean DEBUG=WarpDebug.DEBUG;
      /** The descriptive information related to this implementation. */
      private static final String info="WarpConnector/"+WarpConstants.VERSION;
  
      // -------------------------------------------------------- LOCAL VARIABLES
  
      /** The lifecycle event support for this component. */
      private LifecycleSupport lifecycle=null;
      /** The server socket factory for this connector. */
      private ServerSocket socket=null;
      /** Wether the start() method was called or not. */
      private boolean started=false;
      /** The accept count for the server socket. */
      private int count = 10;
  
      // -------------------------------------------------------- BEAN PROPERTIES
  
      /** Wether requests received through this connector are secure. */
      private boolean secure=false;
      /** The scheme to be set on requests received through this connector. */
      private String scheme="http";
      /** The Container used to process requests received by this Connector. */
      private Container container=null;
      /** The server socket factory for this connector. */
      private ServerSocketFactory factory=null;
      /** The server socket port. */
      private int port=8008;
      /** The number of concurrent connections we can handle. */
      private int acceptcount=10;
      /** The root path for web applications. */
      private String appbase="";
  
      // ------------------------------------------------------------ CONSTRUCTOR
      
      public WarpConnector() {
          super();
          this.lifecycle=new LifecycleSupport(this);
          if (DEBUG) this.debug("New instance created");
      }
  
      // --------------------------------------------------------- PUBLIC METHODS
  
      /** 
       * Run the acceptor thread, the thread that will wait on the server socket
       * and create new connections.
       */
      public void run() {
          if (DEBUG) this.debug("Acceptor thread started");
          try {
              while (this.started) {
                  Socket s=this.socket.accept();
                  WarpConnection c=new WarpConnection();
                  c.setSocket(s);
                  c.setConnector(this);
                  try {
                      c.start();
                  } catch (LifecycleException e) {
                      this.log(e);
                      continue;
                  }
              }
              this.socket.close();
          } catch (IOException e) {
              if (this.started) e.printStackTrace(System.err);
          }
          if (DEBUG) this.debug("Acceptor thread exited");
      }
  
      /**
       * Create and return a Request object suitable for receiving the contents
       * of a Request from the responsible Container.
       */
      public Request createRequest() {
          HttpRequestBase request = new HttpRequestBase();
          request.setConnector(this);
          return (request);
      }
  
      /**
       * Create and return a Response object suitable for receiving the contents
       * of a Response from the responsible Container.
       */
      public Response createResponse() {
          HttpResponseBase response = new HttpResponseBase();
          response.setConnector(this);
          return (response);
      }
  
      /**
       * Begin processing requests via this Connector.
       */
      public void start() throws LifecycleException {
          if (DEBUG) this.debug("Starting");
          // Validate and update our current state
          if (started)
              throw new LifecycleException("Connector already started");
      
          // We're starting
          lifecycle.fireLifecycleEvent(START_EVENT, null);
          this.started=true;
  
          // Establish a server socket on the specified port
          try {
              this.socket=getFactory().createSocket(this.port,this.count);
          } catch (Exception e) {
              throw new LifecycleException("Error creating server socket", e);
          }
  
          // Start our background thread
          new Thread(this).start();
      }
  
      /**
       * Terminate processing requests via this Connector.
       */
      public void stop() throws LifecycleException {
          // Validate and update our current state
          if (!started)
              throw new LifecycleException("Cannot stop (never started)");
  
          // We're stopping
          lifecycle.fireLifecycleEvent(STOP_EVENT, null);
          started = false;
          
          // Close the server socket
          try {
              this.socket.close();
          } catch (IOException e) {
              throw new LifecycleException("Error closing server socket", e);
          }
      }
  
      // ---------------------------------------- CONNECTOR AND LIFECYCLE METHODS
  
      /**
       * Add a lifecycle event listener to this component.
       */
      public void addLifecycleListener(LifecycleListener listener) {
          this.lifecycle.addLifecycleListener(listener);
      }
  
      /**
       * Remove a lifecycle event listener from this component.
       */
      public void removeLifecycleListener(LifecycleListener listener) {
          lifecycle.removeLifecycleListener(listener);
      }
  
      /**
       * Return descriptive information about this implementation.
       */
      public String getInfo() {
          return (info);
      }
  
      // ----------------------------------------------------------- BEAN METHODS
  
      /**
       * Return the secure connection flag that will be assigned to requests
       * received through this connector. Default value is "false".
       * <br>
       * NOTE: For protocols such as WARP this is pointless, as we will only know
       * at request time wether the received request is secure or not. Security
       * is handled by an HTTP stack outside this JVM, and this can be (like with
       * Apache) handling both HTTP and HTTPS requests.
       */
      public boolean getSecure() {
          return(this.secure);
      }
  
      /**
       * Set the secure connection flag that will be assigned to requests
       * received through this connector.
       * <br>
       * NOTE: For protocols such as WARP this is pointless, as we will only know
       * at request time wether the received request is secure or not. Security
       * is handled by an HTTP stack outside this JVM, and this can be (like with
       * Apache) handling both HTTP and HTTPS requests.
       */
      public void setSecure(boolean secure) {
          if (DEBUG) this.debug("Setting secure to "+secure);
          this.secure=secure;
      }
  
      /**
       * Return the scheme that will be assigned to requests received through
       * this connector.  Default value is "http".
       * <br>
       * NOTE: As noted in the getSecure() and setSecure() methods, for WARP
       * we don't know the scheme of the request until the request is received.
       */
      public String getScheme() {
          return(this.scheme);
      }
  
      /**
       * Set the scheme that will be assigned to requests received through
       * this connector.
       * <br>
       * NOTE: As noted in the getSecure() and setSecure() methods, for WARP
       * we don't know the scheme of the request until the request is received.
       */
      public void setScheme(String scheme) {
          if (DEBUG) this.debug("Setting scheme to "+scheme);
          this.scheme=scheme;
      }
  
      /**
       * Return the Container used for processing requests received by this
       * Connector.
       */
      public Container getContainer() {
          return(this.container);
      }
  
      /**
       * Set the Container used for processing requests received by this
       * Connector.
       */
      public void setContainer(Container container) {
          if (DEBUG) {
              if (container==null) this.debug("Setting null container");
              else this.debug("Setting container "+container.getInfo());
          }
          this.container=container;
      }
  
      /**
       * Return the server socket factory used by this Connector.
       */
      public ServerSocketFactory getFactory() {
          synchronized (this) {
              if (this.factory==null) {
                  if (DEBUG) this.debug("Creating ServerSocketFactory");
  
                  this.factory=new DefaultServerSocketFactory();
              }
          }
          return (this.factory);
      }
  
      /**
       * Set the server socket factory used by this Container.
       */
      public void setFactory(ServerSocketFactory factory) {
          if (factory==null) return;
          synchronized (this) {
              if (DEBUG) this.debug("Setting ServerSocketFactory");
              this.factory=factory;
          }
      }
  
      /**
       * Return the port number on which we listen for HTTP requests.
       */
      public int getPort() {
        return(this.port);
      }
  
  
      /**
       * Set the port number on which we listen for HTTP requests.
       */
      public void setPort(int port) {
          if (DEBUG) this.debug("Setting port to "+port);
        this.port=port;
      }
  
      /**
       * Return the accept count for this Connector.
       */
      public int getAcceptCount() {
        return (this.acceptcount);
      }
  
      /**
       * Set the accept count for this Connector.
       *
       * @param acceptcount The new accept count
       */
      public void setAcceptCount(int acceptcount) {
          if (DEBUG) this.debug("Setting accept count to "+acceptcount);
        this.acceptcount=acceptcount;
      }
  
      /**
       * Return the application root for this Connector. This can be an absolute
       * pathname, a relative pathname, or a URL.
       */
      public String getAppBase() {
        return (this.appbase);
      }
  
      /**
       * Set the application root for this Connector. This can be an absolute
       * pathname, a relative pathname, or a URL.
       */
      public void setAppBase(String appbase) {
          if (appbase==null) return;
          if (DEBUG) this.debug("Setting application root to "+appbase);
        String old=this.appbase;
        this.appbase=appbase;
      }
  
      // ------------------------------------------ LOGGING AND DEBUGGING METHODS
  
      /**
       * Dump a log message.
       */
      public void log(String msg) {
          // FIXME: Log thru catalina
          WarpDebug.debug(this,msg);
      }
  
      /**
       * Dump information for an Exception.
       */
      public void log(Exception exc) {
          // FIXME: Log thru catalina
          WarpDebug.debug(this,exc);
      }
  
      /**
       * Dump a debug message.
       */
      private void debug(String msg) {
          if (DEBUG) WarpDebug.debug(this,msg);
      }
  
      /**
       * Dump information for an Exception.
       */
      private void debug(Exception exc) {
          if (DEBUG) WarpDebug.debug(this,exc);
      }
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpEngine.java
  
  Index: WarpEngine.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  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 java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.catalina.Container;
  import org.apache.catalina.Engine;
  import org.apache.catalina.Globals;
  import org.apache.catalina.Host;
  import org.apache.catalina.LifecycleException;
  import org.apache.catalina.Request;
  import org.apache.catalina.Response;
  import org.apache.catalina.core.ContainerBase;
  
  /**
   *
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
   * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
   *         Apache Software Foundation.
   * @version CVS $Id: WarpEngine.java,v 1.1 2000/12/07 17:25:31 pier Exp $
   */
  public class WarpEngine extends ContainerBase implements Engine {
  
      // -------------------------------------------------------------- CONSTANTS
  
      /** Our debug flag status (Used to compile out debugging information). */
      private static final boolean DEBUG=WarpDebug.DEBUG;
      /** The descriptive information related to this implementation. */
      private static final String info="WarpEngine/"+WarpConstants.VERSION;
  
      // -------------------------------------------------------- LOCAL VARIABLES
  
      /** The Java class name of the default Mapper class for this Container. */
      private String mapper="org.apache.catalina.connector.warp.WarpEngineMapper";
  
      // ------------------------------------------------------------ CONSTRUCTOR
      
      /**
       * Create a new WarpEngine component with the default basic Valve.
       */
      public WarpEngine() {
          super();
          super.setBasic(new WarpEngineValve());
          if (DEBUG) this.debug("New instance created");
      }
  
      // --------------------------------------------------------- PUBLIC METHODS
  
      /**
       * Add a child Container, only if the proposed child is an implementation
       * of Host.
       */
      public void addChild(Container child) {
          if (DEBUG) this.debug("Adding child "+child.getInfo());
  
          if (!(child instanceof Host))
              throw new IllegalArgumentException("Child of Engine is not Host");
  
          super.addChild(child);
      }
  
      /**
       * Return descriptive information about this implementation.
       */
      public String getInfo() {
          return(this.info);
      }
  
      /**
       * Disallow any attempt to set a parent for this Container, since an
       * Engine is supposed to be at the top of the Container hierarchy.
       */
      public void setParent(Container container) {
          throw new IllegalArgumentException("Engine cannot have a parent");
      }
  
      /**
       * Start this Engine component.
       */
      public void start() throws LifecycleException {
          if (DEBUG) this.debug("Starting");
          // Standard container startup
          super.start();
      }
  
      /**
       * Start this Engine component.
       */
      public void stop() throws LifecycleException {
          if (DEBUG) this.debug("Stopping");
          // Standard container startup
          super.stop();
      }
  
      /**
       * Add a default Mapper implementation if none have been configured
       * explicitly.
       *
       * @param mapperClass Java class name of the default Mapper
       */
      public void addDefaultMapper(String mapper) {
          if (DEBUG) this.debug("Adding default mapper "+mapper);
          super.addDefaultMapper(this.mapper);
      }
  
      // ------------------------------------------------------ DEBUGGING METHODS
  
      /**
       * Dump a debug message.
       */
      private void debug(String msg) {
          if (DEBUG) WarpDebug.debug(this,msg);
      }
  
      /**
       * Dump information for an Exception.
       */
      private void debug(Exception exc) {
          if (DEBUG) WarpDebug.debug(this,exc);
      }
  }
  
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpEngineMapper.java
  
  Index: WarpEngineMapper.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  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.Engine;
  import org.apache.catalina.Host;
  import org.apache.catalina.Mapper;
  import org.apache.catalina.Request;
  
  
  /**
   *
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
   * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
   *         Apache Software Foundation.
   * @version CVS $Id: WarpEngineMapper.java,v 1.1 2000/12/07 17:25:31 pier Exp $
   */
  public class WarpEngineMapper implements Mapper {
  
      // -------------------------------------------------------------- CONSTANTS
  
      /** Our debug flag status (Used to compile out debugging information). */
      private static final boolean DEBUG=WarpDebug.DEBUG;
  
      // -------------------------------------------------------- BEAN PROPERTIES
  
      /** The Container with which this Mapper is associated. */
      private WarpEngine engine = null;
      /** The protocol with which this Mapper is associated. */
      private String protocol = null;
  
      // ------------------------------------------------------------ CONSTRUCTOR
  
      /**
       * Create a new WarpEngineMapper.
       */
      public WarpEngineMapper() {
          super();
          if (DEBUG) this.debug("New instance created");
      }
  
      // --------------------------------------------------------- PUBLIC METHODS
  
      /**
       * Return the child Container that should be used to process this Request,
       * based upon its characteristics.  If no such child Container can be
       * identified, return <code>null</code> instead.
       *
       * @param request Request being processed
       * @param update Update the Request to reflect the mapping selection?
       */
      public Container map(Request request, boolean update) {
          if (DEBUG) this.debug("Trying to map request to host");
  
          return(null);
      }
  
      // ----------------------------------------------------------- BEAN METHODS
  
      /**
       * Return the Container with which this Mapper is associated.
       */
      public Container getContainer() {
          return (this.engine);
      }
  
      /**
       * Set the Container with which this Mapper is associated.
       */
      public void setContainer(Container container) {
          if (DEBUG) {
              if (container==null) {
                  this.debug("Setting null container");
              } else {
                  String info=container.getInfo();
                  this.debug("Setting container "+info);
              }
          }
          this.engine=(WarpEngine)container;
      }
  
      /**
       * Return the protocol for which this Mapper is responsible.
       */
      public String getProtocol() {
          return (this.protocol);
      }
  
      /**
       * Set the protocol for which this Mapper is responsible.
       *
       * @param protocol The newly associated protocol
       */
      public void setProtocol(String protocol) {
          if (DEBUG) this.debug("Setting protocol "+protocol);
          this.protocol = protocol;
      }
  
      // ------------------------------------------------------ DEBUGGING METHODS
  
      /**
       * Dump a debug message.
       */
      private void debug(String msg) {
          if (DEBUG) WarpDebug.debug(this,msg);
      }
  
      /**
       * Dump information for an Exception.
       */
      private void debug(Exception exc) {
          if (DEBUG) WarpDebug.debug(this,exc);
      }
  }
  
  
  1.1                  
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpEngineValve.java
  
  Index: WarpEngineValve.java
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *         Copyright (c) 1999, 2000  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 java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.catalina.Container;
  import org.apache.catalina.Host;
  import org.apache.catalina.Request;
  import org.apache.catalina.Response;
  import org.apache.catalina.valves.ValveBase;
  
  /**
   *
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
   * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
   *         Apache Software Foundation.
   * @version CVS $Id: WarpEngineValve.java,v 1.1 2000/12/07 17:25:31 pier Exp $
   */
  public class WarpEngineValve extends ValveBase {
  
      // -------------------------------------------------------------- CONSTANTS
  
      /** Our debug flag status (Used to compile out debugging information). */
      private static final boolean DEBUG=WarpDebug.DEBUG;
      /** The descriptive information related to this implementation. */
      private static final String info="WarpEngineValve/"+WarpConstants.VERSION;
  
      // ------------------------------------------------------------ CONSTRUCTOR
  
      /**
       * Create a new WarpEngineValve.
       */
      public WarpEngineValve() {
          super();
          if (DEBUG) this.debug("New instance created");
      }
  
      // --------------------------------------------------------- PUBLIC METHODS
  
      /**
       * Return descriptive information about this Valve implementation.
       */
      public String getInfo() {
          return (info);
      }
  
      /**
       * Select the appropriate child Host to process this request,
       * based on the requested server name.  If no matching Host can
       * be found, return an appropriate HTTP error.
       *
       * @param request Request to be processed
       * @param update Update request to reflect this mapping?
       *
       * @exception IOException if an input/output error occurred
       * @exception ServletException if a servlet error occurred
       */
      public void invoke(Request request, Response response)
      throws IOException, ServletException {
          if (DEBUG) this.debug("Trying to invoke request");
  
          // Validate the request and response object types
          if (!(request.getRequest() instanceof HttpServletRequest) ||
              !(response.getResponse() instanceof HttpServletResponse)) {
              return;
          }
  
          // Select the Host to be used for this Request
          WarpEngine engine=(WarpEngine)getContainer();
          Host host=(Host)engine.map(request, true);
          if (host==null) {
              HttpServletResponse res=(HttpServletResponse)response.getResponse();
              res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                            "Host not configured");
              if (DEBUG) this.debug("Host not configured");
              return;
          }
  
          // Ask this Host to process this request
          host.invoke(request, response);
      }
  
      // ------------------------------------------------------ DEBUGGING METHODS
  
      /**
       * Dump a debug message.
       */
      private void debug(String msg) {
          if (DEBUG) WarpDebug.debug(this,msg);
      }
  
      /**
       * Dump information for an Exception.
       */
      private void debug(Exception exc) {
          if (DEBUG) WarpDebug.debug(this,exc);
      }
  }
  
  
  

Reply via email to