Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 34542 invoked by uid 500); 8 Dec 2000 02:57:10 -0000 Delivered-To: apmail-jakarta-tomcat-4.0-cvs@apache.org Received: (qmail 34539 invoked by uid 1023); 8 Dec 2000 02:57:10 -0000 Date: 8 Dec 2000 02:57:10 -0000 Message-ID: <20001208025710.34538.qmail@locus.apache.org> From: pier@locus.apache.org To: jakarta-tomcat-4.0-cvs@apache.org Subject: cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp WarpRequestHandler.java WarpReader.java WarpPacket.java WarpHandler.java WarpEngine.java WarpConstants.java WarpConnector.java WarpConnectionHandler.java pier 00/12/07 18:57:09 Modified: catalina/src/share/org/apache/catalina/connector/warp WarpRequestHandler.java WarpReader.java WarpPacket.java WarpHandler.java WarpEngine.java WarpConstants.java WarpConnector.java WarpConnectionHandler.java Log: Corrected (hopefully) the CR/LF LF/CR LF/LF issue. (Kinda gets hard when you're working on a Mac, a Solaris box and Win2K) Revision Changes Path 1.4 +145 -145 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WarpRequestHandler.java 2000/12/07 17:38:14 1.3 +++ WarpRequestHandler.java 2000/12/08 02:57:02 1.4 @@ -1,145 +1,145 @@ -/* ========================================================================= * - * * - * 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 ." * - * * - * 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 . * - * * - * 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 . * - * * - * ========================================================================= */ -package org.apache.catalina.connector.warp; - -import java.io.IOException; - -/** - * - * - * @author Pier Fumagalli - * @author Copyright © 1999, 2000 The - * Apache Software Foundation. - * @version CVS $Id: WarpRequestHandler.java,v 1.3 2000/12/07 17:38:14 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. - *
- * This method is the one which will actually perform the operation of - * analyzing the packet and doing whatever needs to be done. - *
- * 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"); - // 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; - default: - this.log("Wrong packet type "+type); - return(true); - } - return(true); - } catch (IOException e) { - this.log(e); - return(false); - } - } -} +/* ========================================================================= * + * * + * 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 ." * + * * + * 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 . * + * * + * 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 . * + * * + * ========================================================================= */ +package org.apache.catalina.connector.warp; + +import java.io.IOException; + +/** + * + * + * @author
Pier Fumagalli + * @author Copyright © 1999, 2000 The + * Apache Software Foundation. + * @version CVS $Id: WarpRequestHandler.java,v 1.4 2000/12/08 02:57:02 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. + *
+ * This method is the one which will actually perform the operation of + * analyzing the packet and doing whatever needs to be done. + *
+ * 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"); + // 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; + default: + this.log("Wrong packet type "+type); + return(true); + } + return(true); + } catch (IOException e) { + this.log(e); + return(false); + } + } +} 1.3 +116 -116 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpReader.java Index: WarpReader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WarpReader.java 2000/12/07 17:38:13 1.2 +++ WarpReader.java 2000/12/08 02:57:03 1.3 @@ -1,116 +1,116 @@ -/* ========================================================================= * - * * - * 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 ." * - * * - * 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 . * - * * - * 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 . * - * * - * ========================================================================= */ -package org.apache.catalina.connector.warp; - -/** - * - * - * @author
Pier Fumagalli - * @author Copyright © 1999, 2000 The - * Apache Software Foundation. - * @version CVS $Id: WarpReader.java,v 1.2 2000/12/07 17:38:13 pier Exp $ - */ -public class WarpReader { - - /** The current buffer. */ - private byte buf[]; - - /** The current position in the buffer. */ - private int pos; - - public WarpReader() { - this(null); - } - - public WarpReader(byte buf[]) { - super(); - this.reset(buf); - } - - public void reset(byte buf[]) { - this.buf=buf; - this.pos=0; - } - - public int readShort() { - // Check if we have a buffer - if (this.buf==null) throw new NullPointerException("No buffer"); - // Check if we have room for a short in the buffer - if ((this.pos+2)>this.buf.length) - throw new IllegalStateException("Not enough data ("+this.pos+"/"+ - this.buf.length+")"); - // Read the short and return it - int x=(((int)this.buf[this.pos++])&0x0ff); - x=((x<<8)|(((int)this.buf[this.pos++])&0x0ff)); - return(x); - } - - public String readString() { - // Check if we have a buffer - if (this.buf==null) throw new NullPointerException("No buffer"); - // Attempt to read the string length - int len=this.readShort(); - // Check if we have enough space in the buffer for the string - if ((this.pos+len)>buf.length) - throw new IllegalStateException("Not enough data ("+this.pos+"+"+ - len+"="+this.buf.length+")"); - // Create the string, update the position and return. - String s=new String(this.buf,this.pos,len); - this.pos+=len; - return(s); - } -} +/* ========================================================================= * + * * + * 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 ." * + * * + * 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 . * + * * + * 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 . * + * * + * ========================================================================= */ +package org.apache.catalina.connector.warp; + +/** + * + * + * @author Pier Fumagalli + * @author Copyright © 1999, 2000 The + * Apache Software Foundation. + * @version CVS $Id: WarpReader.java,v 1.3 2000/12/08 02:57:03 pier Exp $ + */ +public class WarpReader { + + /** The current buffer. */ + private byte buf[]; + + /** The current position in the buffer. */ + private int pos; + + public WarpReader() { + this(null); + } + + public WarpReader(byte buf[]) { + super(); + this.reset(buf); + } + + public void reset(byte buf[]) { + this.buf=buf; + this.pos=0; + } + + public int readShort() { + // Check if we have a buffer + if (this.buf==null) throw new NullPointerException("No buffer"); + // Check if we have room for a short in the buffer + if ((this.pos+2)>this.buf.length) + throw new IllegalStateException("Not enough data ("+this.pos+"/"+ + this.buf.length+")"); + // Read the short and return it + int x=(((int)this.buf[this.pos++])&0x0ff); + x=((x<<8)|(((int)this.buf[this.pos++])&0x0ff)); + return(x); + } + + public String readString() { + // Check if we have a buffer + if (this.buf==null) throw new NullPointerException("No buffer"); + // Attempt to read the string length + int len=this.readShort(); + // Check if we have enough space in the buffer for the string + if ((this.pos+len)>buf.length) + throw new IllegalStateException("Not enough data ("+this.pos+"+"+ + len+"="+this.buf.length+")"); + // Create the string, update the position and return. + String s=new String(this.buf,this.pos,len); + this.pos+=len; + return(s); + } +} 1.3 +125 -125 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpPacket.java Index: WarpPacket.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpPacket.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WarpPacket.java 2000/12/07 17:38:13 1.2 +++ WarpPacket.java 2000/12/08 02:57:03 1.3 @@ -1,125 +1,125 @@ -/* ========================================================================= * - * * - * 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 ." * - * * - * 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 . * - * * - * 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 . * - * * - * ========================================================================= */ -package org.apache.catalina.connector.warp; - -/** - * - * - * @author Pier Fumagalli - * @author Copyright © 1999, 2000 The - * Apache Software Foundation. - * @version CVS $Id: WarpPacket.java,v 1.2 2000/12/07 17:38:13 pier Exp $ - */ -public class WarpPacket { - - /** The default size. */ - private static final int defaultsize=4096; - - /** The current buffer. */ - private byte buf[]; - - /** The current position in the buffer. */ - private int pos; - - public WarpPacket() { - super(); - this.buf=new byte[defaultsize]; - this.reset(); - } - - public void reset() { - this.pos=0; - if (this.buf.length>(defaultsize<<1)) this.buf=new byte[defaultsize]; - } - - public void writeShort(int k) { - // Check if we have room - if ((this.pos+2)>8)&0x0ff); - this.buf[this.pos++]=(byte)(k&0x0ff); - } - - public void writeString(String s) { - // Retrieve the string bytes - byte k[]=s.getBytes(); - // Write the string length - this.writeShort(k.length); - // Check if we have room - if ((this.pos+k.length)." * + * * + * 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 . * + * * + * 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 . * + * * + * ========================================================================= */ +package org.apache.catalina.connector.warp; + +/** + * + * + * @author Pier Fumagalli + * @author Copyright © 1999, 2000 The + * Apache Software Foundation. + * @version CVS $Id: WarpPacket.java,v 1.3 2000/12/08 02:57:03 pier Exp $ + */ +public class WarpPacket { + + /** The default size. */ + private static final int defaultsize=4096; + + /** The current buffer. */ + private byte buf[]; + + /** The current position in the buffer. */ + private int pos; + + public WarpPacket() { + super(); + this.buf=new byte[defaultsize]; + this.reset(); + } + + public void reset() { + this.pos=0; + if (this.buf.length>(defaultsize<<1)) this.buf=new byte[defaultsize]; + } + + public void writeShort(int k) { + // Check if we have room + if ((this.pos+2)>8)&0x0ff); + this.buf[this.pos++]=(byte)(k&0x0ff); + } + + public void writeString(String s) { + // Retrieve the string bytes + byte k[]=s.getBytes(); + // Write the string length + this.writeShort(k.length); + // Check if we have room + if ((this.pos+k.length)." * - * * - * 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 . * - * * - * 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 . * - * * - * ========================================================================= */ -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; - -/** - * - * - * @author Pier Fumagalli - * @author Copyright © 1999, 2000 The - * Apache Software Foundation. - * @version CVS $Id: WarpHandler.java,v 1.4 2000/12/07 17:38:12 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; - - // -------------------------------------------------------- LOCAL VARIABLES - - /** The lifecycle event support for this component. */ - private LifecycleSupport lifecycle=null; - /** The WARP packet type. */ - private int type=-1; - /** The WARP packet payload. */ - private byte buffer[]=null; - /** Wether type and buffer have already been processed by notifyData(). */ - private boolean processed=false; - /** Wether the stop() method was called. */ - private boolean stopped=false; - /** The name of this handler. */ - 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"); - } - - // --------------------------------------------------------- PUBLIC METHODS - - /** - * Process WARP packets. - *
- * This method will wait for data to be notified by a WarpConnection with - * the processData() method, and will handle it to the abstract process() - * method. - *
- * When process() returns false (meaning that there is no more - * data to process) this method will unregister this handler from the - * WarpConnection, and the thread created in init() will terminate. - */ - public final synchronized void run() { - while(true) { - try { - // Wait for this thread to be notified by processData(). - while (this.processed==true) { - // Check if we were notified by stop() - this.wait(); - if (this.stopped) { - this.processed=true; - this.notifyAll(); - this.connection.removeHandler(this.rid); - if (DEBUG) this.debug("Thread exited"); - } - } - } catch (InterruptedException e) { - // Uh-oh.. Something bad happened. Drop this handler. - this.connection.removeHandler(this.rid); - return; - } - - // If processed is set to true, it means that somehow we were - // not notified by the processData() method. So we just ignore - // and go back to sleep. - if (this.processed) continue; - - // The processed flag is set to false, so we need to handle the - // type and buffer to the process() method. If this method - // returns true, we have some more packets to process before - // terminating this method. - if (process(this.type, this.buffer)) { - // The process method returned true, meaning that we still have - // some other packets to wait for this WARP RID. Set the - // processed flag to true and notify the thread that might be - // waiting in the processData() method, then get back to sleep. - this.processed=true; - this.notifyAll(); - continue; - } else { - // The process() method returned false, meaning that our work - // is done. Let's get out. - break; - } - } - // We got out of the loop (the process() method returned false). Let's - // notify all other threads (just in case after a packet is processed - // another one for the same handler has been received), unregister - // this handler and terminate. - this.processed=true; - this.notifyAll(); - this.connection.removeHandler(this.rid); - if (DEBUG) this.debug("Thread exited"); - } - - /** - * Initialize this handler instance. - *
- * This method will initialize this handler and starts the despooling - * thread that will handle the data to the processData() method. - *
- * 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. - *
- * The thread associated with this handler is stopped and this instance is - * unregistered from the WarpConnection. - */ - 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"); - } - - /** - * Receive notification of data from a WarpConnection. - * - * @param type The WARP packet type. - * @param buffer The WARP packet payload. - */ - protected final synchronized void processData(int type, byte buffer[]) { - // Check if the run() method already handled the previous packet to - // the process() method. If not so, wait until that happens. - while(this.processed==false) try { - this.wait(); - } catch (InterruptedException e) { - return; - } - // We were notified and the processed flag is set to true, meanging - // that the previous packet was successfully despooled by the run() - // method, so we can safely set the type and buffer in our local - // variables. - this.type=type; - this.buffer=buffer; - // Set the processed flag to false, and notify the thread waiting in - // the run() method that another packet is ready to process. - this.processed=false; - this.notifyAll(); - } - - // -------------------------------------------- PACKET TRANSMISSION METHODS - - /** - * Send a WARP packet. - *
- * This method will send a WARP packet back to the client, invoking - * the send() method in the WarpConnection associated with this - * WarpHandler with the appropriate WARP RID. - * - * @param type The WARP packet type. - * @param buffer The buffer containing the data to send. - * @param off The offset in the buffer of the data to send. - * @param len The number of bytes to send. - * @exception IOException If something happened sending the data. - */ - public final void send(int type, byte buffer[], int offset, int len) - throws IOException { - this.connection.send(this.rid, type, buffer, offset, len); - } - - /** - * Send a WARP packet. - *
- * This method will send a WARP packet back to the client, invoking - * the send() method in the WarpConnection associated with this - * WarpHandler with the appropriate WARP RID. - * - * @param type The WARP packet type. - * @param packet The packet to write. - * @exception IOException If something happened sending the data. - */ - public final void send(int type, WarpPacket packet) - throws IOException { - this.send(type,packet.getBuffer(),0,packet.getLength()); - } - - /** - * Send a WARP packet. - *
- * This method is equivalent to send(type, buffer, 0, buffer.length). - * - * @param type The WARP packet type. - * @param buffer The buffer containing the data to send. - * @exception IOException If something happened sending the data. - */ - public final void send(int type, byte buffer[]) - throws IOException { - this.send(type, buffer, 0, buffer.length); - } - - // ------------------------------------------------------- ABSTRACT METHODS - - /** - * Process a WARP packet. - *
- * This method is the one which will actually perform the operation of - * analyzing the packet and doing whatever needs to be done. - *
- * 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 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. - */ - 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. - */ - protected void log(String msg) { - WarpConnection connection=this.getConnection(); - if (connection!=null) connection.log("{"+this.name+"} "+msg); - else WarpDebug.debug(this,msg); - } - - /** - * Log an exception. - * - * @param e The exception to log. - */ - protected void log(Exception exc) { - WarpConnection connection=this.getConnection(); - if (connection!=null) connection.log(exc); - else WarpDebug.debug(this,exc); - } - - /** - * Dump a debug message. - */ - protected void debug(String msg) { - if (DEBUG) WarpDebug.debug(this,msg); - } - - /** - * Dump information for an Exception. - */ - protected void debug(Exception exc) { - if (DEBUG) WarpDebug.debug(this,exc); - } -} +/* ========================================================================= * + * * + * 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 ." * + * * + * 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 . * + * * + * 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 . * + * * + * ========================================================================= */ +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; + +/** + * + * + * @author
Pier Fumagalli + * @author Copyright © 1999, 2000 The + * Apache Software Foundation. + * @version CVS $Id: WarpHandler.java,v 1.5 2000/12/08 02:57:04 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; + + // -------------------------------------------------------- LOCAL VARIABLES + + /** The lifecycle event support for this component. */ + private LifecycleSupport lifecycle=null; + /** The WARP packet type. */ + private int type=-1; + /** The WARP packet payload. */ + private byte buffer[]=null; + /** Wether type and buffer have already been processed by notifyData(). */ + private boolean processed=false; + /** Wether the stop() method was called. */ + private boolean stopped=false; + /** The name of this handler. */ + 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"); + } + + // --------------------------------------------------------- PUBLIC METHODS + + /** + * Process WARP packets. + *
+ * This method will wait for data to be notified by a WarpConnection with + * the processData() method, and will handle it to the abstract process() + * method. + *
+ * When process() returns false (meaning that there is no more + * data to process) this method will unregister this handler from the + * WarpConnection, and the thread created in init() will terminate. + */ + public final synchronized void run() { + while(true) { + try { + // Wait for this thread to be notified by processData(). + while (this.processed==true) { + // Check if we were notified by stop() + this.wait(); + if (this.stopped) { + this.processed=true; + this.notifyAll(); + this.connection.removeHandler(this.rid); + if (DEBUG) this.debug("Thread exited"); + } + } + } catch (InterruptedException e) { + // Uh-oh.. Something bad happened. Drop this handler. + this.connection.removeHandler(this.rid); + return; + } + + // If processed is set to true, it means that somehow we were + // not notified by the processData() method. So we just ignore + // and go back to sleep. + if (this.processed) continue; + + // The processed flag is set to false, so we need to handle the + // type and buffer to the process() method. If this method + // returns true, we have some more packets to process before + // terminating this method. + if (process(this.type, this.buffer)) { + // The process method returned true, meaning that we still have + // some other packets to wait for this WARP RID. Set the + // processed flag to true and notify the thread that might be + // waiting in the processData() method, then get back to sleep. + this.processed=true; + this.notifyAll(); + continue; + } else { + // The process() method returned false, meaning that our work + // is done. Let's get out. + break; + } + } + // We got out of the loop (the process() method returned false). Let's + // notify all other threads (just in case after a packet is processed + // another one for the same handler has been received), unregister + // this handler and terminate. + this.processed=true; + this.notifyAll(); + this.connection.removeHandler(this.rid); + if (DEBUG) this.debug("Thread exited"); + } + + /** + * Initialize this handler instance. + *
+ * This method will initialize this handler and starts the despooling + * thread that will handle the data to the processData() method. + *
+ * 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. + *
+ * The thread associated with this handler is stopped and this instance is + * unregistered from the WarpConnection. + */ + 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"); + } + + /** + * Receive notification of data from a WarpConnection. + * + * @param type The WARP packet type. + * @param buffer The WARP packet payload. + */ + protected final synchronized void processData(int type, byte buffer[]) { + // Check if the run() method already handled the previous packet to + // the process() method. If not so, wait until that happens. + while(this.processed==false) try { + this.wait(); + } catch (InterruptedException e) { + return; + } + // We were notified and the processed flag is set to true, meanging + // that the previous packet was successfully despooled by the run() + // method, so we can safely set the type and buffer in our local + // variables. + this.type=type; + this.buffer=buffer; + // Set the processed flag to false, and notify the thread waiting in + // the run() method that another packet is ready to process. + this.processed=false; + this.notifyAll(); + } + + // -------------------------------------------- PACKET TRANSMISSION METHODS + + /** + * Send a WARP packet. + *
+ * This method will send a WARP packet back to the client, invoking + * the send() method in the WarpConnection associated with this + * WarpHandler with the appropriate WARP RID. + * + * @param type The WARP packet type. + * @param buffer The buffer containing the data to send. + * @param off The offset in the buffer of the data to send. + * @param len The number of bytes to send. + * @exception IOException If something happened sending the data. + */ + public final void send(int type, byte buffer[], int offset, int len) + throws IOException { + this.connection.send(this.rid, type, buffer, offset, len); + } + + /** + * Send a WARP packet. + *
+ * This method will send a WARP packet back to the client, invoking + * the send() method in the WarpConnection associated with this + * WarpHandler with the appropriate WARP RID. + * + * @param type The WARP packet type. + * @param packet The packet to write. + * @exception IOException If something happened sending the data. + */ + public final void send(int type, WarpPacket packet) + throws IOException { + this.send(type,packet.getBuffer(),0,packet.getLength()); + } + + /** + * Send a WARP packet. + *
+ * This method is equivalent to send(type, buffer, 0, buffer.length). + * + * @param type The WARP packet type. + * @param buffer The buffer containing the data to send. + * @exception IOException If something happened sending the data. + */ + public final void send(int type, byte buffer[]) + throws IOException { + this.send(type, buffer, 0, buffer.length); + } + + // ------------------------------------------------------- ABSTRACT METHODS + + /** + * Process a WARP packet. + *
+ * This method is the one which will actually perform the operation of + * analyzing the packet and doing whatever needs to be done. + *
+ * 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 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. + */ + protected WarpConnection getConnection() { + return(this.connection); + } + + /** + * Return the WarpConnector associated with this handler. + */ + protected WarpConnector getConnector() { + return(this.connection.getConnector()); + } + + /** + * 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. + */ + protected void log(String msg) { + WarpConnection connection=this.getConnection(); + if (connection!=null) connection.log("{"+this.name+"} "+msg); + else WarpDebug.debug(this,msg); + } + + /** + * Log an exception. + * + * @param e The exception to log. + */ + protected void log(Exception exc) { + WarpConnection connection=this.getConnection(); + if (connection!=null) connection.log(exc); + else WarpDebug.debug(this,exc); + } + + /** + * Dump a debug message. + */ + protected void debug(String msg) { + if (DEBUG) WarpDebug.debug(this,msg); + } + + /** + * Dump information for an Exception. + */ + protected void debug(Exception exc) { + if (DEBUG) WarpDebug.debug(this,exc); + } +} 1.4 +2 -2 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WarpEngine.java 2000/12/07 21:12:58 1.3 +++ WarpEngine.java 2000/12/08 02:57:04 1.4 @@ -75,9 +75,9 @@ * @author
Pier Fumagalli * @author Copyright © 1999, 2000 The * Apache Software Foundation. - * @version CVS $Id: WarpEngine.java,v 1.3 2000/12/07 21:12:58 pier Exp $ + * @version CVS $Id: WarpEngine.java,v 1.4 2000/12/08 02:57:04 pier Exp $ */ -public class WarpEngine extends StandardEngine implements Engine { +public class WarpEngine extends StandardEngine { // -------------------------------------------------------------- CONSTANTS 1.5 +101 -101 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WarpConstants.java 2000/12/07 17:38:10 1.4 +++ WarpConstants.java 2000/12/08 02:57:04 1.5 @@ -1,101 +1,101 @@ -/* ========================================================================= * - * * - * 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 ." * - * * - * 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 . * - * * - * 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 . * - * * - * ========================================================================= */ -package org.apache.catalina.connector.warp; - -/** - * - * - * @author Pier Fumagalli - * @author Copyright © 1999, 2000 The - * Apache Software Foundation. - * @version CVS $Id: WarpConstants.java,v 1.4 2000/12/07 17:38:10 pier Exp $ - */ -public class WarpConstants { - - /* 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; - - /* The RID indicating that the connection must be closed (0x0ffff). */ - public static final int RID_DISCONNECT = 0x0ffff; - - /* The RID minimum value (0x00001). */ - public static final int RID_MIN = 0x00001; - - /* 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_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; -} +/* ========================================================================= * + * * + * 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 ." * + * * + * 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 . * + * * + * 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 . * + * * + * ========================================================================= */ +package org.apache.catalina.connector.warp; + +/** + * + * + * @author Pier Fumagalli + * @author Copyright © 1999, 2000 The + * Apache Software Foundation. + * @version CVS $Id: WarpConstants.java,v 1.5 2000/12/08 02:57:04 pier Exp $ + */ +public class WarpConstants { + + /* 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; + + /* The RID indicating that the connection must be closed (0x0ffff). */ + public static final int RID_DISCONNECT = 0x0ffff; + + /* The RID minimum value (0x00001). */ + public static final int RID_MIN = 0x00001; + + /* 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_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.4 +19 -1 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WarpConnector.java 2000/12/07 21:12:59 1.3 +++ WarpConnector.java 2000/12/08 02:57:05 1.4 @@ -78,7 +78,7 @@ * @author Pier Fumagalli * @author Copyright © 1999, 2000 The * Apache Software Foundation. - * @version CVS $Id: WarpConnector.java,v 1.3 2000/12/07 21:12:59 pier Exp $ + * @version CVS $Id: WarpConnector.java,v 1.4 2000/12/08 02:57:05 pier Exp $ */ public class WarpConnector implements Connector, Lifecycle, Runnable { @@ -116,6 +116,8 @@ private int acceptcount=10; /** The root path for web applications. */ private String appbase=""; + /** The current Host ID. */ + private int hostid=0; // ------------------------------------------------------------ CONSTRUCTOR @@ -173,6 +175,22 @@ return (response); } + /** + * Set up a virtual host in our Engine and return the associated host ID. + */ + public int setupHost(String name) { + WarpHost host=new WarpHost(); + int id=this.hostid++; + + host.setName(name); + host.setAppBase(this.getAppBase()); + host.setHostID(id); + + this.getContainer().addChild(host); + + return(id); + } + /** * Begin processing requests via this Connector. */ 1.6 +160 -155 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WarpConnectionHandler.java 2000/12/07 17:38:10 1.5 +++ WarpConnectionHandler.java 2000/12/08 02:57:05 1.6 @@ -1,155 +1,160 @@ -/* ========================================================================= * - * * - * 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 ." * - * * - * 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 . * - * * - * 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 . * - * * - * ========================================================================= */ -package org.apache.catalina.connector.warp; - -import java.io.IOException; - -/** - * - * - * @author Pier Fumagalli - * @author Copyright © 1999, 2000 The - * Apache Software Foundation. - * @version CVS $Id: WarpConnectionHandler.java,v 1.5 2000/12/07 17:38:10 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. - *
- * This method is the one which will actually perform the operation of - * analyzing the packet and doing whatever needs to be done. - *
- * 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) { - case WarpConstants.TYP_CONINIT_HST: - // Retrieve this host id - int hid=123; - 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_CONINIT_HID,this.packet); - break; - case WarpConstants.TYP_CONINIT_APP: - // Retrieve this application id - int aid=321; - 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_CONINIT_AID,this.packet); - break; - 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.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 - this.packet.reset(); - 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); - } catch (IOException e) { - this.log(e); - return(false); - } - } -} +/* ========================================================================= * + * * + * 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 ." * + * * + * 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 . * + * * + * 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 . * + * * + * ========================================================================= */ +package org.apache.catalina.connector.warp; + +import java.io.IOException; + +/** + * + * + * @author
Pier Fumagalli + * @author Copyright © 1999, 2000 The + * Apache Software Foundation. + * @version CVS $Id: WarpConnectionHandler.java,v 1.6 2000/12/08 02:57:05 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. + *
+ * This method is the one which will actually perform the operation of + * analyzing the packet and doing whatever needs to be done. + *
+ * 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) { + case WarpConstants.TYP_CONINIT_HST: + String name=reader.readString()+":"+reader.readShort(); + + // Retrieve this host id + int hid=this.getConnector().setupHost(name); + if (DEBUG) this.debug("Created new host "+name+" ID="+hid); + + // Send the HOST ID back to the WARP client + this.packet.reset(); + this.packet.writeShort(hid); + this.send(WarpConstants.TYP_CONINIT_HID,this.packet); + break; + + case WarpConstants.TYP_CONINIT_APP: + + // Retrieve this application id + int aid=321; + 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_CONINIT_AID,this.packet); + break; + + 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.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 + this.packet.reset(); + 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); + } catch (IOException e) { + this.log(e); + return(false); + } + } +}