pier 00/11/30 13:59:40
Modified: catalina/src/share/org/apache/catalina/connector/warp
WarpConnection.java WarpConnectionHandler.java
WarpConstants.java WarpHandler.java
Added: catalina/src/share/org/apache/catalina/connector/warp
WarpRequestHandler.java
Log:
Bugfixes for multiplexing issues.
Improving request handling.
Changed packet type definitios.
Revision Changes Path
1.2 +6 -1
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WarpConnection.java 2000/11/30 16:34:30 1.1
+++ WarpConnection.java 2000/11/30 21:59:29 1.2
@@ -65,7 +65,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
* @author Copyright © 1999, 2000 <a href="http://www.apache.org">The
* Apache Software Foundation.
- * @version CVS $Id: WarpConnection.java,v 1.1 2000/11/30 16:34:30 pier Exp $
+ * @version CVS $Id: WarpConnection.java,v 1.2 2000/11/30 21:59:29 pier Exp $
*/
public class WarpConnection implements Runnable {
@@ -136,6 +136,9 @@
this.log("Premature PAYLOAD end ("+ret+" of "+len+")");
break;
}
+
+ if (DEBUG) this.debug("Received packet RID="+rid+" TYP="+typ);
+
// Check if we have the special RID 0x0ffff (disconnect)
if (rid==0x0ffff) {
this.log("Connection closing ("+new String(buf)+")");
@@ -207,6 +210,7 @@
out.write(buffer,offset,len);
out.flush();
}
+ if (DEBUG) this.debug("Sending packet RID="+rid+" TYP="+type);
}
/**
@@ -240,6 +244,7 @@
* false, otherwise return true.
*/
protected synchronized boolean registerHandler(WarpHandler han, int rid) {
+ if (DEBUG) this.debug("Registering handler for RID "+rid);
return(this.table.add(han, rid));
}
1.3 +27 -15
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WarpConnectionHandler.java 2000/11/30 19:55:59 1.2
+++ WarpConnectionHandler.java 2000/11/30 21:59:30 1.3
@@ -64,13 +64,15 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
* @author Copyright © 1999, 2000 <a href="http://www.apache.org">The
* Apache Software Foundation.
- * @version CVS $Id: WarpConnectionHandler.java,v 1.2 2000/11/30 19:55:59 pier Exp
$
+ * @version CVS $Id: WarpConnectionHandler.java,v 1.3 2000/11/30 21:59:30 pier Exp
$
*/
public class WarpConnectionHandler extends WarpHandler {
/** The WarpReader associated with this WarpConnectionHandler. */
private WarpReader reader=new WarpReader();
/** The WarpPacket used to write data. */
private WarpPacket packet=new WarpPacket();
+ /** The current request id. */
+ private int request=WarpConstants.RID_MIN;
/**
* Process a WARP packet.
@@ -93,38 +95,48 @@
this.packet.reset();
try {
switch (type) {
- case WarpConstants.TYP_HOST:
+ case WarpConstants.TYP_CONINIT_HST:
// Retrieve this host id
int hid=123;
- if (DEBUG) this.debug("HST "+reader.readString()+":"+
- reader.readShort()+"="+hid);
+ if (DEBUG) this.debug("CONINIT_HST "+reader.readString()+
+ ":"+reader.readShort()+"="+hid);
// Send the HOST ID back to the WARP client
this.packet.reset();
this.packet.writeShort(hid);
- this.send(WarpConstants.TYP_HOST_ID,this.packet);
+ this.send(WarpConstants.TYP_CONINIT_HID,this.packet);
break;
- case WarpConstants.TYP_APPLICATION:
+ case WarpConstants.TYP_CONINIT_APP:
// Retrieve this application id
int aid=321;
- if (DEBUG) this.debug("APP "+reader.readString()+":"+
- reader.readString()+"="+aid);
+ if (DEBUG) this.debug("CONINIT_APP "+reader.readString()+
+ ":"+reader.readString()+"="+aid);
// Send the APPLICATION ID back to the WARP client
this.packet.reset();
this.packet.writeShort(aid);
- this.send(WarpConstants.TYP_APPLICATION_ID,this.packet);
+ this.send(WarpConstants.TYP_CONINIT_AID,this.packet);
break;
- case WarpConstants.TYP_REQUEST:
- // Retrieve this request id
- int rid=999;
- if (DEBUG) this.debug("REQ "+reader.readShort()+":"+
- reader.readShort()+"="+rid);
+ case WarpConstants.TYP_CONINIT_REQ:
+ // Create a new WarpRequestHandler and register it with
+ // an unique RID.
+ int r=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;
+ h.init(c,r);
+ 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(rid);
- this.send(WarpConstants.TYP_REQUEST_ID,this.packet);
+ this.packet.writeShort(r);
+ this.send(WarpConstants.TYP_CONINIT_RID,this.packet);
break;
default:
this.log("Wrong packet type "+type+". Closing connection");
+ // Post an error message back to the WARP client
+ this.packet.reset();
+ this.send(WarpConstants.TYP_CONINIT_ERR,this.packet);
return(false);
}
return(true);
1.2 +19 -8
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WarpConstants.java 2000/11/30 16:34:30 1.1
+++ WarpConstants.java 2000/11/30 21:59:30 1.2
@@ -62,12 +62,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
* @author Copyright © 1999, 2000 <a href="http://www.apache.org">The
* Apache Software Foundation.
- * @version CVS $Id: WarpConstants.java,v 1.1 2000/11/30 16:34:30 pier Exp $
+ * @version CVS $Id: WarpConstants.java,v 1.2 2000/11/30 21:59:30 pier Exp $
*/
public class WarpConstants {
/* The DEBUG flag. (If false debug information will not be compiled in). */
public static final boolean DEBUG = true;
-
+
/* The RID associated with the connection controller handler (0x00000). */
public static final int RID_CONNECTION = 0x00000;
@@ -79,12 +79,23 @@
/* The RID maximum value (0x0fffe). */
public static final int RID_MAX = 0x0fffe;
+
+ public static final int TYP_CONINIT_HST = 0x00000;
+ public static final int TYP_CONINIT_HID = 0x00001;
+ public static final int TYP_CONINIT_APP = 0x00002;
+ public static final int TYP_CONINIT_AID = 0x00003;
+ public static final int TYP_CONINIT_REQ = 0x00004;
+ public static final int TYP_CONINIT_RID = 0x00005;
+ public static final int TYP_CONINIT_ERR = 0x0000F;
- public static final int TYP_HOST = 0x00000;
- public static final int TYP_HOST_ID = 0x00001;
- public static final int TYP_APPLICATION = 0x00002;
- public static final int TYP_APPLICATION_ID = 0x00003;
- public static final int TYP_REQUEST = 0x00004;
- public static final int TYP_REQUEST_ID = 0x00005;
+ public static final int TYP_REQINIT_MET = 0x00010;
+ public static final int TYP_REQINIT_URI = 0x00011;
+ public static final int TYP_REQINIT_ARG = 0x00012;
+ public static final int TYP_REQINIT_PRO = 0x00013;
+ public static final int TYP_REQINIT_HDR = 0x00014;
+ public static final int TYP_REQINIT_VAR = 0x00015;
+ public static final int TYP_REQINIT_RUN = 0x0001D;
+ public static final int TYP_REQINIT_ERR = 0x0001E;
+ public static final int TYP_REQINIT_ACK = 0x0001F;
}
1.2 +3 -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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WarpHandler.java 2000/11/30 16:34:31 1.1
+++ WarpHandler.java 2000/11/30 21:59:31 1.2
@@ -64,7 +64,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
* @author Copyright © 1999, 2000 <a href="http://www.apache.org">The
* Apache Software Foundation.
- * @version CVS $Id: WarpHandler.java,v 1.1 2000/11/30 16:34:31 pier Exp $
+ * @version CVS $Id: WarpHandler.java,v 1.2 2000/11/30 21:59:31 pier Exp $
*/
public abstract class WarpHandler implements Runnable {
@@ -123,7 +123,8 @@
this.rid=rid;
this.processed=true;
this.stopped=false;
- this.name=this.getClass().getName()+"[RID="+rid+"]";
+ String n=this.getClass().getName();
+ this.name=n.substring(n.lastIndexOf('.')+1)+"[RID="+rid+"]";
new Thread(this,this.name).start();
}
1.1
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpRequestHandler.java
Index: WarpRequestHandler.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;
/**
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>
* @author Copyright © 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 $
*/
public class WarpRequestHandler extends WarpHandler {
/** The WarpReader associated with this WarpConnectionHandler. */
private WarpReader reader=new WarpReader();
/** The WarpPacket used to write data. */
private WarpPacket packet=new WarpPacket();
/** Wether we had an error in the request header. */
private boolean headererr=false;
/**
* Process a WARP packet.
* <br>
* This method is the one which will actually perform the operation of
* analyzing the packet and doing whatever needs to be done.
* <br>
* This method will return true if another packet is expected for this
* RID, or it will return false if this was the last packet for this RID.
* When we return false this handler is unregistered, and the Thread
* started in the init() method is terminated.
*
* @param type The WARP packet type.
* @param buffer The WARP packet payload.
* @return If more packets are expected for this RID, true is returned,
* false if this was the last packet.
*/
public boolean process(int type, byte buffer[]) {
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());
break;
// The Request URI
case WarpConstants.TYP_REQINIT_URI:
if (DEBUG) this.debug("REQINIT_URI "+reader.readString());
break;
// The Request query arguments
case WarpConstants.TYP_REQINIT_ARG:
if (DEBUG) this.debug("REQINIT_ARG "+reader.readString());
break;
// The Request protocol
case WarpConstants.TYP_REQINIT_PRO:
if (DEBUG) this.debug("REQINIT_PRO "+reader.readString());
break;
// A request header
case WarpConstants.TYP_REQINIT_HDR:
if (DEBUG) this.debug("REQINIT_HDR "+reader.readString()+
": "+reader.readString());
break;
// A request variable
case WarpConstants.TYP_REQINIT_VAR:
if (DEBUG) this.debug("REQINIT_VAR "+reader.readShort()+
"="+reader.readString());
break;
// 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
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;
default:
this.log("Wrong packet type "+type);
return(true);
}
return(true);
} catch (IOException e) {
this.log(e);
return(false);
}
}
}