tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp WarpResponse.java WarpOutputStream.java WarpInputStream.java WarpRequestHandler.java WarpRequest.java WarpHost.java WarpHandler.java WarpEngine.java WarpDebug.java WarpContext.java WarpConstants.java WarpConnector.java WarpConnectionHandler.java
Date Fri, 08 Dec 2000 15:33:50 GMT
pier        00/12/08 07:33:49

  Modified:    catalina/src/share/org/apache/catalina/connector/warp
                        WarpRequestHandler.java WarpRequest.java
                        WarpHost.java WarpHandler.java WarpEngine.java
                        WarpDebug.java WarpContext.java WarpConstants.java
                        WarpConnector.java WarpConnectionHandler.java
  Added:       catalina/src/share/org/apache/catalina/connector/warp
                        WarpResponse.java WarpOutputStream.java
                        WarpInputStream.java
  Log:
  Done.
  
  Revision  Changes    Path
  1.5       +64 -15    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WarpRequestHandler.java	2000/12/08 02:57:02	1.4
  +++ WarpRequestHandler.java	2000/12/08 15:33:41	1.5
  @@ -64,9 +64,10 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">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.4 2000/12/08 02:57:02 pier Exp $
  + * @version CVS $Id: WarpRequestHandler.java,v 1.5 2000/12/08 15:33:41 pier Exp $
    */
   public class WarpRequestHandler extends WarpHandler {
  +
       /** The WarpReader associated with this WarpConnectionHandler. */
       private WarpReader reader=new WarpReader();
       /** The WarpPacket used to write data. */
  @@ -74,6 +75,11 @@
       /** Wether we had an error in the request header. */
       private boolean headererr=false;
   
  +    /** The WarpRequest object associated with this request handler. */
  +    protected WarpRequest request=null;
  +    /** The WarpRequest object associated with this request handler. */
  +    protected WarpResponse response=null;    
  +
       /**
        * Process a WARP packet.
        * <br>
  @@ -91,47 +97,90 @@
        *         false if this was the last packet.
        */
       public boolean process(int type, byte buffer[]) {
  +        WarpConnector connector=this.getConnector();
  +        WarpEngine engine=(WarpEngine)connector.getContainer();
  +        String arg1=null;
  +        String arg2=null;
  +        int valu=-1;
  +
           this.reader.reset(buffer);
           this.packet.reset();
           try {
               switch (type) {
                   // The Request method
                   case WarpConstants.TYP_REQINIT_MET:
  -                    if (DEBUG) this.debug("REQINIT_MET "+reader.readString());
  +                    arg1=reader.readString();
  +                    if (DEBUG) this.debug("Request Method "+arg1);
  +                    this.request.setMethod(arg1);
                       break;
  +
                   // The Request URI
                   case WarpConstants.TYP_REQINIT_URI:
  -                    if (DEBUG) this.debug("REQINIT_URI "+reader.readString());
  +                    arg1=reader.readString();
  +                    if (DEBUG) this.debug("Request URI "+arg1);
  +                    this.request.setRequestURI(arg1);
                       break;
  +
                   // The Request query arguments
                   case WarpConstants.TYP_REQINIT_ARG:
  -                    if (DEBUG) this.debug("REQINIT_ARG "+reader.readString());
  +                    arg1=reader.readString();
  +                    if (DEBUG) this.debug("Request Query Argument "+arg1);
  +                    this.request.setQueryString(arg1);
                       break;
  +
                   // The Request protocol
                   case WarpConstants.TYP_REQINIT_PRO:
  -                    if (DEBUG) this.debug("REQINIT_PRO "+reader.readString());
  +                    arg1=reader.readString();
  +                    if (DEBUG) this.debug("Request Protocol "+arg1);
  +                    this.request.setProtocol(arg1);
                       break;
  +
                   // A request header
                   case WarpConstants.TYP_REQINIT_HDR:
  -                    if (DEBUG) this.debug("REQINIT_HDR "+reader.readString()+
  -                                          ": "+reader.readString());
  +                    arg1=reader.readString();
  +                    arg2=reader.readString();
  +                    if (DEBUG) this.debug("Request Header "+arg1+": "+arg2);
  +                    this.request.addHeader(arg1,arg2);
                       break;
  +
                   // A request variable
                   case WarpConstants.TYP_REQINIT_VAR:
  -                    if (DEBUG) this.debug("REQINIT_VAR "+reader.readShort()+
  -                                          "="+reader.readString());
  +                    valu=reader.readShort();
  +                    arg1=reader.readString();
  +                    if (DEBUG) this.debug("Request Variable ["+valu+"]="+arg1);
                       break;
  +
                   // The request header is finished, run the servlet (whohoo!)
                   case WarpConstants.TYP_REQINIT_RUN:
  -                    if (DEBUG) this.debug("REQINIT_RUN");
  +                    if (DEBUG) this.debug("Invoking request");
                       // Check if we can accept (or not) this request
                       this.packet.reset();
  -                    if (this.headererr) {
  -                        this.send(WarpConstants.TYP_REQINIT_ERR,this.packet);
  -                        return(false);
  -                    }
                       this.send(WarpConstants.TYP_REQINIT_ACK,this.packet);
  -                    break;
  +                    WarpInputStream win=new WarpInputStream(this);
  +                    WarpOutputStream wout=new WarpOutputStream(this,response);
  +                    this.request.setStream(win);
  +                    this.response.setStream(wout);
  +                    this.response.setRequest(this.request);
  +                    try {
  +                        engine.invoke(this.request, this.response);
  +                    } catch (Exception e) {
  +                        this.log(e);
  +                    }
  +                    try {
  +                        this.response.flushBuffer();
  +                        this.response.finishResponse();
  +                        wout.flush();
  +                        wout.close();
  +                    } catch (Exception e) {
  +                        if (DEBUG) this.debug(e);
  +                    }
  +                    this.packet.reset();
  +                    this.packet.writeString("End of request");
  +                    this.send(WarpConstants.TYP_REQUEST_ACK,this.packet);
  +                    if (DEBUG) this.debug("End of request");
  +                    return(false);
  +
  +                // Other packet types
                   default:
                       this.log("Wrong packet type "+type);
                       return(true);
  
  
  
  1.2       +53 -3     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpRequest.java
  
  Index: WarpRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpRequest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WarpRequest.java	2000/12/07 21:12:55	1.1
  +++ WarpRequest.java	2000/12/08 15:33:41	1.2
  @@ -64,7 +64,7 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">Pier Fumagalli</a>
    * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
    *         Apache Software Foundation.
  - * @version CVS $Id: WarpRequest.java,v 1.1 2000/12/07 21:12:55 pier Exp $
  + * @version CVS $Id: WarpRequest.java,v 1.2 2000/12/08 15:33:41 pier Exp $
    */
   public class WarpRequest extends HttpRequestBase {
   
  @@ -75,12 +75,47 @@
   
       // -------------------------------------------------------- LOCAL VARIABLES
   
  -    /** The Warp Host ID of this Host. */
  +    /** The Warp Host ID of this request. */
       private int hostid=-1;
  +    /** The Warp Application ID of this request. */
  +    private int applid=-1;
  +    /** The Warp Request ID of this request. */
  +    private int id=-1;
  +    /** The WarpRequestHandler associated with this request. */
  +    private WarpRequestHandler handler=null;
   
       // ----------------------------------------------------------- BEAN METHODS
   
       /**
  +     * Return the WarpRequestHandler associated with this request.
  +     */
  +    protected WarpRequestHandler getWarpRequestHandler() {
  +        return(this.handler);
  +    }
  +
  +    /**
  +     * Set the WarpRequestHandler associated with this request.
  +     */
  +    protected void setWarpRequestHandler(WarpRequestHandler handler) {
  +        this.handler=handler;
  +    }
  +
  +    /**
  +     * Return the Host ID associated with this WarpRequest instance.
  +     */
  +    protected int getRequestID() {
  +        return(this.id);
  +    }
  +
  +    /**
  +     * Set the Host ID associated with this WarpRequest instance.
  +     */
  +    protected void setRequestID(int id) {
  +        if (DEBUG) this.debug("Setting RequestID to "+id);
  +        this.id=id;
  +    }
  +
  +    /**
        * Return the Host ID associated with this WarpRequest instance.
        */
       protected int getRequestedHostID() {
  @@ -88,11 +123,26 @@
       }
   
       /**
  -     * Set the Host ID associated with this WarpRequest instance.
  +     * Set the Application ID associated with this WarpRequest instance.
        */
       protected void setRequestedHostID(int id) {
           if (DEBUG) this.debug("Setting request HostID to "+id);
           this.hostid=id;
  +    }
  +
  +    /**
  +     * Return the Application ID associated with this WarpRequest instance.
  +     */
  +    protected int getRequestedApplicationID() {
  +        return(this.applid);
  +    }
  +
  +    /**
  +     * Set the Host ID associated with this WarpRequest instance.
  +     */
  +    protected void setRequestedApplicationID(int id) {
  +        if (DEBUG) this.debug("Setting request ApplicationID to "+id);
  +        this.applid=id;
       }
   
       // ------------------------------------------------------ DEBUGGING METHODS
  
  
  
  1.3       +33 -3     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpHost.java
  
  Index: WarpHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpHost.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WarpHost.java	2000/12/08 09:39:54	1.2
  +++ WarpHost.java	2000/12/08 15:33:42	1.3
  @@ -56,6 +56,9 @@
    * ========================================================================= */
   package org.apache.catalina.connector.warp;
   
  +import javax.servlet.ServletException;
  +import org.apache.catalina.Request;
  +import org.apache.catalina.Response;
   import java.io.IOException;
   import java.net.URL;
   import org.apache.catalina.Container;
  @@ -70,7 +73,7 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">Pier Fumagalli</a>
    * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
    *         Apache Software Foundation.
  - * @version CVS $Id: WarpHost.java,v 1.2 2000/12/08 09:39:54 pier Exp $
  + * @version CVS $Id: WarpHost.java,v 1.3 2000/12/08 15:33:42 pier Exp $
    */
   public class WarpHost extends StandardHost {
   
  @@ -88,8 +91,6 @@
       /** The ID to use for the next dynamically configured application. */
       private int applid=0;
   
  -    // --------------------------------------------------------- PUBLIC METHODS
  -
       /**
        * Create a new instance of a WarpHost.
        */
  @@ -99,6 +100,35 @@
           conf.setContextClass(cc);
           this.setContextClass(cc);
           this.addLifecycleListener(conf);
  +        this.setDebug(9);
  +    }
  +
  +    // --------------------------------------------------------- PUBLIC METHODS
  +
  +    public void invoke(Request req, Response res)
  +    throws ServletException, IOException {
  +        if (DEBUG) this.debug("Invoked");
  +        super.invoke(req,res);
  +    }
  +
  +    public Container map(Request request, boolean update) {
  +        if (DEBUG) this.debug("Trying to map request to context");
  +        if (request instanceof WarpRequest) {
  +            WarpRequest r=(WarpRequest)request;
  +
  +    	    Container children[]=this.findChildren();
  +    	    for (int x=0; x<children.length; x++) {
  +    	        if (children[x] instanceof WarpContext) {
  +    	            WarpContext c=(WarpContext)children[x];
  +    	            if (r.getRequestedApplicationID()==c.getApplicationID()) {
  +    	                ((WarpRequest)request).setContextPath(c.getPath());
  +    	                return(children[x]);
  +    	            }
  +                }
  +            }
  +        }
  +        if (DEBUG) this.debug("Trying to map request to context (std)");
  +        return(super.map(request,update));
       }
   
       /**
  
  
  
  1.7       +2 -2      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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WarpHandler.java	2000/12/08 09:40:27	1.6
  +++ WarpHandler.java	2000/12/08 15:33:42	1.7
  @@ -69,14 +69,14 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">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.6 2000/12/08 09:40:27 pier Exp $
  + * @version CVS $Id: WarpHandler.java,v 1.7 2000/12/08 15:33:42 pier Exp $
    */
   public abstract class WarpHandler implements Lifecycle, Runnable {
   
       // -------------------------------------------------------------- CONSTANTS
   
       /** Our debug flag status (Used to compile out debugging information). */
  -    protected static final boolean DEBUG=WarpDebug.DEBUG;
  +    protected static final boolean DEBUG=true; //WarpDebug.DEBUG;
   
       // -------------------------------------------------------- LOCAL VARIABLES
   
  
  
  
  1.6       +38 -1     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpEngine.java
  
  Index: WarpEngine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpEngine.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WarpEngine.java	2000/12/08 09:40:55	1.5
  +++ WarpEngine.java	2000/12/08 15:33:43	1.6
  @@ -75,7 +75,7 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">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.5 2000/12/08 09:40:55 pier Exp $
  + * @version CVS $Id: WarpEngine.java,v 1.6 2000/12/08 15:33:43 pier Exp $
    */
   public class WarpEngine extends StandardEngine {
   
  @@ -102,10 +102,47 @@
        */
       public WarpEngine() {
           super();
  +        super.addDefaultMapper(this.mapper);
           if (DEBUG) this.debug("New instance created");
  +        this.setDebug(9);
       }
   
       // --------------------------------------------------------- PUBLIC METHODS
  +
  +    public void invoke(Request req, Response res)
  +    throws ServletException, IOException {
  +        if (DEBUG) this.debug("Invoked");
  +        super.invoke(req,res);
  +    }
  +
  +    public Container map(Request request, boolean update) {
  +        if (DEBUG) this.debug("Trying to map request to host");
  +        if (request instanceof WarpRequest) {
  +            WarpRequest r=(WarpRequest)request;
  +
  +    	    Container children[]=this.findChildren();
  +    	    for (int x=0; x<children.length; x++) {
  +    	        if (children[x] instanceof WarpHost) {
  +    	            WarpHost host=(WarpHost)children[x];
  +    	            if (r.getRequestedHostID()==host.getHostID()) {
  +    	                return(children[x]);
  +    	            }
  +                }
  +            }
  +        }
  +        if (DEBUG) this.debug("Trying to map request to host (std)");
  +        return(super.map(request,update));
  +    }
  +
  +    /**
  +     * Add a default Mapper implementation if none have been configured
  +     * explicitly.
  +     *
  +     * @param mapperClass Java class name of the default Mapper
  +     */
  +    protected void addDefaultMapper(String mapper) {
  +        super.addDefaultMapper(this.mapper);
  +    }
   
       /**
        * Return descriptive information about this implementation.
  
  
  
  1.6       +2 -2      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WarpDebug.java	2000/12/08 09:41:34	1.5
  +++ WarpDebug.java	2000/12/08 15:33:43	1.6
  @@ -61,14 +61,14 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">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.5 2000/12/08 09:41:34 pier Exp $
  + * @version CVS $Id: WarpDebug.java,v 1.6 2000/12/08 15:33:43 pier Exp $
    */
   public class WarpDebug {
   
       // -------------------------------------------------------------- CONSTANTS
   
       /** Our debug flag status (Used to compile out debugging information). */
  -    public static final boolean DEBUG=false;
  +    public static final boolean DEBUG=true;
   
       // -------------------------------------------------------- LOCAL VARIABLES
   
  
  
  
  1.2       +25 -1     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpContext.java
  
  Index: WarpContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WarpContext.java	2000/12/08 09:42:03	1.1
  +++ WarpContext.java	2000/12/08 15:33:43	1.2
  @@ -56,15 +56,20 @@
    * ========================================================================= */
   package org.apache.catalina.connector.warp;
   
  +import java.io.IOException;
  +import javax.servlet.ServletException;
  +import org.apache.catalina.Request;
  +import org.apache.catalina.Response;
   import org.apache.catalina.Container;
   import org.apache.catalina.core.StandardContext;
  +import org.apache.catalina.LifecycleException;
   
   /**
    *
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">Pier Fumagalli</a>
    * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
    *         Apache Software Foundation.
  - * @version CVS $Id: WarpContext.java,v 1.1 2000/12/08 09:42:03 pier Exp $
  + * @version CVS $Id: WarpContext.java,v 1.2 2000/12/08 15:33:43 pier Exp $
    */
   public class WarpContext extends StandardContext {
   
  @@ -83,8 +88,17 @@
       public WarpContext() {
           super();
           if (DEBUG) this.debug("New instance created");
  +        this.setUseNaming(false);
  +        this.setAvailable(true);
  +        this.setDebug(9);
       }
   
  +    public void invoke(Request req, Response res)
  +    throws ServletException, IOException {
  +        if (DEBUG) this.debug("Invoked (available="+this.getAvailable()+")");
  +        super.invoke(req,res);
  +    }
  +
       // ----------------------------------------------------------- BEAN METHODS
   
       /**
  @@ -101,6 +115,16 @@
           if (DEBUG) this.debug("Setting ApplicationID for context in path \""+
                                 super.getName()+"\" to "+id);
           this.id=id;
  +    }
  +
  +    public void start() throws LifecycleException {
  +        if (DEBUG) this.debug("Starting");
  +        super.start();
  +    }
  +
  +    public void stop() throws LifecycleException {
  +        if (DEBUG) this.debug("Stopping");
  +        super.stop();
       }
   
       // ------------------------------------------------------ DEBUGGING METHODS
  
  
  
  1.6       +8 -1      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WarpConstants.java	2000/12/08 02:57:04	1.5
  +++ WarpConstants.java	2000/12/08 15:33:43	1.6
  @@ -62,7 +62,7 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">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.5 2000/12/08 02:57:04 pier Exp $
  + * @version CVS $Id: WarpConstants.java,v 1.6 2000/12/08 15:33:43 pier Exp $
    */
   public class WarpConstants {
   
  @@ -98,4 +98,11 @@
       public static final int TYP_REQINIT_RUN = 0x0001D;
       public static final int TYP_REQINIT_ERR = 0x0001E;
       public static final int TYP_REQINIT_ACK = 0x0001F;
  +    
  +    public static final int TYP_REQUEST_STA = 0x00020;
  +    public static final int TYP_REQUEST_HDR = 0x00021;
  +    public static final int TYP_REQUEST_CMT = 0x00022;
  +    public static final int TYP_REQUEST_DAT = 0x00023;
  +    public static final int TYP_REQUEST_ERR = 0x0002E;
  +    public static final int TYP_REQUEST_ACK = 0x0002F;
   }
  
  
  
  1.6       +2 -2      jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConnector.java
  
  Index: WarpConnector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConnector.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WarpConnector.java	2000/12/08 09:42:49	1.5
  +++ WarpConnector.java	2000/12/08 15:33:44	1.6
  @@ -78,7 +78,7 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">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.5 2000/12/08 09:42:49 pier Exp $
  + * @version CVS $Id: WarpConnector.java,v 1.6 2000/12/08 15:33:44 pier Exp $
    */
   public class WarpConnector implements Connector, Lifecycle, Runnable {
   
  @@ -166,7 +166,7 @@
        * of a Response from the responsible Container.
        */
       public Response createResponse() {
  -        HttpResponseBase response = new HttpResponseBase();
  +        WarpResponse response=new WarpResponse();
           response.setConnector(this);
           return (response);
       }
  
  
  
  1.8       +34 -21    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WarpConnectionHandler.java	2000/12/08 09:44:04	1.7
  +++ WarpConnectionHandler.java	2000/12/08 15:33:44	1.8
  @@ -64,7 +64,7 @@
    * @author <a href="mailto:pier.fumagalli@eng.sun.com">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.7 2000/12/08 09:44:04 pier Exp $
  + * @version CVS $Id: WarpConnectionHandler.java,v 1.8 2000/12/08 15:33:44 pier Exp $
    */
   public class WarpConnectionHandler extends WarpHandler {
       /** The WarpReader associated with this WarpConnectionHandler. */
  @@ -91,14 +91,15 @@
        *         false if this was the last packet.
        */
       public boolean process(int type, byte buffer[]) {
  -        WarpEngine engine=(WarpEngine)this.getConnector().getContainer();
  +        WarpConnector connector=this.getConnector();
  +        WarpEngine engine=(WarpEngine)connector.getContainer();
   
           this.reader.reset(buffer);
           this.packet.reset();
           try {
               switch (type) {
                   case WarpConstants.TYP_CONINIT_HST: {
  -                    String name=reader.readString()+":"+reader.readShort();
  +                    String name=reader.readString()+"."+reader.readShort();
                       
                       // Retrieve this host id
                       int hid=engine.setupChild(name).getHostID();
  @@ -126,12 +127,7 @@
                       }
   
                       // Retrieve this application (based on the path)
  -                    WarpContext cont=(WarpContext)host.findChild(path);
  -                    // Check if we can find it by application name
  -                    if (cont==null)
  -                        cont=(WarpContext)host.findChild('/'+name);
  -
  -                    // We definitely didn't find the application
  +                    WarpContext cont=(WarpContext)host.findChild('/'+name);
                       if (cont==null) {
                           this.log("Application "+name+" with path "+path+
                                    " not found");
  @@ -142,10 +138,11 @@
   
                       // Ok, we found the right application
                       int aid=cont.getApplicationID();
  -                    cont.setPath(path);
  +                    cont.setPath('/'+name);
                       cont.setDisplayName(name);
                       if (DEBUG) this.debug("Application "+name+" mapped in "+
                                             host.getName()+path+" has ID "+aid);
  +
                       // Send the APPLICATION ID back to the WARP client
                       this.packet.reset();
                       this.packet.writeShort(aid);
  @@ -154,28 +151,44 @@
                   }
   
                   case WarpConstants.TYP_CONINIT_REQ: {
  +                    // Get the Host and Application IDs
  +                    int hid=reader.readShort();
  +                    int aid=reader.readShort();
  +                    if (DEBUG) this.debug("Request for HID="+hid+" AID="+aid);
  +
                       // Create a new WarpRequestHandler and register it with
                       // an unique RID.
  -                    int r=this.request;
  +                    int rid=this.request;
                       WarpConnection c=this.getConnection();
                       WarpRequestHandler h=new WarpRequestHandler();
  -                    // Iterate until a valid RID is found
  -                    c.registerHandler(h,r);
  -                    this.request=r+1;
  +
  +                    // TODO: Iterate until a valid RID is found
  +                    c.registerHandler(h,rid);
  +                    this.request=rid+1;
                       h.setConnection(c);
  -                    h.setRequestID(r);
  +                    h.setRequestID(rid);
  +                    
  +                    // Send the RID back to the WARP client
  +                    this.packet.reset();
  +                    this.packet.writeShort(rid);
  +                    this.send(WarpConstants.TYP_CONINIT_RID,this.packet);
  +                    
  +                    // Create new Request and Response objects.
  +                    h.request=(WarpRequest)connector.createRequest();
  +                    h.response=(WarpResponse)connector.createResponse();
  +                    h.request.setRequestID(rid);
  +                    h.request.setRequestedHostID(hid);
  +                    h.request.setRequestedApplicationID(aid);
  +                    h.request.setWarpRequestHandler(h);
  +                    h.response.setWarpRequestHandler(h);
  +
  +                    // Start the request handler
                       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
  -                    this.packet.reset();
  -                    this.packet.writeShort(r);
  -                    this.send(WarpConstants.TYP_CONINIT_RID,this.packet);
                       break;
                   }
   
  
  
  
  1.1                  jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpResponse.java
  
  Index: WarpResponse.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 <apache@apache.org>.                        *
   *                                                                           *
   * 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.connector.HttpResponseBase;
  import java.io.IOException;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Locale;
  import java.util.TimeZone;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import javax.servlet.http.HttpUtils;
  import org.apache.catalina.HttpResponse;
  import org.apache.catalina.Globals;
  import org.apache.catalina.Logger;
  import org.apache.catalina.util.CookieTools;
  import org.apache.catalina.util.RequestUtil;
  
  /**
   *
   *
   * @author <a href="mailto:pier.fumagalli@eng.sun.com">Pier Fumagalli</a>
   * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
   *         Apache Software Foundation.
   * @version CVS $Id: WarpResponse.java,v 1.1 2000/12/08 15:33:41 pier Exp $
   */
  public class WarpResponse extends HttpResponseBase {
  
      // -------------------------------------------------------------- CONSTANTS
  
      /** Our debug flag status (Used to compile out debugging information). */
      private static final boolean DEBUG=WarpDebug.DEBUG;
  
      /** The WarpRequestHandler associated with this response. */
      private WarpRequestHandler handler=null;
  
      /** The WarpPacket used to write data. */
      private WarpPacket packet=new WarpPacket();
      
      private boolean committed=false;
  
      /**
       * Return the WarpRequestHandler associated with this response.
       */
      protected WarpRequestHandler getWarpRequestHandler() {
          return(this.handler);
      }
  
      /**
       * Set the WarpRequestHandler associated with this response.
       */
      protected void setWarpRequestHandler(WarpRequestHandler handler) {
          this.handler=handler;
      }
  
      public boolean isCommitted() {
          return(this.committed);
      }
  
      protected void sendHeaders() throws IOException {
          if (DEBUG) this.debug("Sending status and headers");
  
          if (isCommitted()) return;
  
          this.packet.reset();
          String prot=request.getRequest().getProtocol();
          this.packet.writeString(prot);
          this.packet.writeShort(status);
          if (message != null) this.packet.writeString(message);
          else this.packet.writeString("");
          this.handler.send(WarpConstants.TYP_REQUEST_STA,this.packet);
  
          if (DEBUG)
              this.debug(prot+" "+status+((message==null)?(""):(" "+message)));
  
          // Send the content-length and content-type headers (if any)
          if (getContentType() != null) {
              this.packet.reset();
              this.packet.writeString("Content-Type");
              this.packet.writeString(getContentType());
              this.handler.send(WarpConstants.TYP_REQUEST_HDR,this.packet);
              if (DEBUG) this.debug("Content-Type: "+getContentType());
          }
          
          if (getContentLength() >= 0) {
              this.packet.reset();
              this.packet.writeString("Content-Length");
              this.packet.writeString(Integer.toString(getContentLength()));
              this.handler.send(WarpConstants.TYP_REQUEST_HDR,this.packet);
              if (DEBUG) this.debug("Content-Type: "+getContentType());
          }
      
          // Send all specified headers (if any)
          synchronized (headers) {
              Iterator names = headers.keySet().iterator();
              while (names.hasNext()) {
                  String name = (String) names.next();
                  ArrayList values = (ArrayList) headers.get(name);
                  Iterator items = values.iterator();
                  while (items.hasNext()) {
                      String value = (String) items.next();
                      this.packet.reset();
                      this.packet.writeString(name);
                      this.packet.writeString(value);
                      this.handler.send(WarpConstants.TYP_REQUEST_HDR,this.packet);
                      if (DEBUG) this.debug(name+": "+value);
                  }
              }
          }
  
          // Add the session ID cookie if necessary
          HttpServletRequest hreq=(HttpServletRequest)request.getRequest();
          HttpSession session=hreq.getSession(false);
  
          if ((session!=null) && session.isNew() && getContext().getCookies()) {
  
              Cookie cookie=new Cookie(Globals.SESSION_COOKIE_NAME,session.getId());
              cookie.setMaxAge(-1);
              String contextPath = null;
              
              if (context != null) contextPath = context.getPath();
              
              if ((contextPath != null) && (contextPath.length() > 0)) {
                  cookie.setPath(contextPath);
              } else {
                  cookie.setPath("/");
              }
              
              if (hreq.isSecure()) cookie.setSecure(true);
              addCookie(cookie);
          }
  
          // Send all specified cookies (if any)
          synchronized (cookies) {
              Iterator items = cookies.iterator();
              while (items.hasNext()) {
                  Cookie cookie = (Cookie) items.next();
                  String name=CookieTools.getCookieHeaderName(cookie);
                  String value=CookieTools.getCookieHeaderValue(cookie);
                  this.packet.reset();
                  this.packet.writeString(name);
                  this.packet.writeString(value);
                  this.handler.send(WarpConstants.TYP_REQUEST_HDR,this.packet);
                  if (DEBUG) this.debug(name+": "+value);
              }
          }
  
          // Commit the headers
          this.packet.reset();
          this.handler.send(WarpConstants.TYP_REQUEST_CMT,this.packet);
          this.committed = true;
      }
  
      // ------------------------------------------------------ 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/WarpOutputStream.java
  
  Index: WarpOutputStream.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 <apache@apache.org>.                        *
   *                                                                           *
   * 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.OutputStream;
  import java.io.IOException;
  
  /**
   *
   * @author <a href="mailto:pier.fumagalli@eng.sun.com">Pier Fumagalli</a>
   * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
   *         Apache Software Foundation.
   * @version CVS $Id: WarpOutputStream.java,v 1.1 2000/12/08 15:33:42 pier Exp $
   */
  public class WarpOutputStream extends OutputStream {
      private WarpRequestHandler handler=null;
      private WarpResponse response=null;
  
      private byte buffer[]=new byte[4096];
      private int pos=0;
      private boolean closed=false;
  
      // -------------------------------------------------------------- CONSTANTS
  
      /** Our debug flag status (Used to compile out debugging information). */
      private static final boolean DEBUG=WarpDebug.DEBUG;
  
      private WarpOutputStream() {
          super();
      }
      
      public WarpOutputStream(WarpRequestHandler handler, WarpResponse response) {
          super();
          this.handler=handler;
          this.response=response;
      }
      
      public void write(int k)
      throws IOException {
          if (closed) throw new IOException();
          buffer[pos++]=(byte)k;
          if (pos==4096) this.flush();
      }
      
      public void flush()
      throws IOException {
          if (closed) throw new IOException();
          if (DEBUG) this.debug("Flushing "+pos+" bytes");
          this.response.sendHeaders();
          this.handler.send(WarpConstants.TYP_REQUEST_DAT,buffer,0,pos);
          pos=0;
      }
      
      public void close()
      throws IOException {
          if (closed) throw new IOException();
          this.flush();
          closed=true;
          if (DEBUG) this.debug("Closed");
      }
  
      // ------------------------------------------------------ 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/WarpInputStream.java
  
  Index: WarpInputStream.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 <apache@apache.org>.                        *
   *                                                                           *
   * 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.InputStream;
  import java.io.IOException;
  
  /**
   *
   * @author <a href="mailto:pier.fumagalli@eng.sun.com">Pier Fumagalli</a>
   * @author Copyright &copy; 1999, 2000 <a href="http://www.apache.org">The
   *         Apache Software Foundation.
   * @version CVS $Id: WarpInputStream.java,v 1.1 2000/12/08 15:33:42 pier Exp $
   */
  public class WarpInputStream extends InputStream {
      private WarpRequestHandler handler=null;
      
      private WarpInputStream() {
          super();
      }
      
      public WarpInputStream(WarpRequestHandler handler) {
          super();
          this.handler=handler;
      }
      
      public int read()
      throws IOException {
          return(-1);
      }
  }
  
  
  

Mime
View raw message