pier 01/07/19 20:25:30 Modified: catalina/src/share/org/apache/catalina/connector/warp WarpConnection.java WarpRequest.java WarpRequestHandler.java WarpResponse.java Log: Reflect changes of JTC into JT4 for Tomcat B6 Revision Changes Path 1.9 +4 -2 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WarpConnection.java 2001/07/20 00:00:53 1.8 +++ WarpConnection.java 2001/07/20 03:25:30 1.9 @@ -210,7 +210,8 @@ public void send(WarpPacket packet) throws IOException { if (Constants.DEBUG) { - logger.debug(">> TYPE="+packet.getType()+" LENGTH="+packet.size); + String typ=Integer.toHexString(packet.getType()); + logger.debug(">> TYPE="+typ+" LENGTH="+packet.size); logger.debug(">> "+packet.dump()); } @@ -251,7 +252,8 @@ } if (Constants.DEBUG) { - logger.debug("<< TYPE="+packet.getType()+" LENGTH="+packet.size); + String typ=Integer.toHexString(packet.getType()); + logger.debug("<< TYPE="+typ+" LENGTH="+packet.size); logger.debug("<< "+packet.dump()); } } 1.6 +0 -1 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpRequest.java Index: WarpRequest.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpRequest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WarpRequest.java 2001/07/20 00:01:26 1.5 +++ WarpRequest.java 2001/07/20 03:25:30 1.6 @@ -62,7 +62,6 @@ public class WarpRequest extends HttpRequestBase { private Host host=null; - private Context context=null; public WarpRequest() { super(); 1.9 +4 -3 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WarpRequestHandler.java 2001/07/20 00:01:32 1.8 +++ WarpRequestHandler.java 2001/07/20 03:25:30 1.9 @@ -132,8 +132,8 @@ if (Constants.DEBUG) logger.debug("Request content type="+ctyp+" length="+ clen); - request.setContentType(ctyp); - request.setContentLength(clen); + if (ctyp.length()>0) request.setContentType(ctyp); + if (clen>0) request.setContentLength(clen); break; } @@ -172,7 +172,8 @@ } catch (Exception e) { logger.log(e); } - response.getStream().close(); + request.finishRequest(); + response.finishResponse(); if (Constants.DEBUG) logger.debug("Request has been processed"); break; 1.5 +97 -17 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpResponse.java Index: WarpResponse.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpResponse.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WarpResponse.java 2001/07/20 00:01:38 1.4 +++ WarpResponse.java 2001/07/20 03:25:30 1.5 @@ -84,36 +84,75 @@ import org.apache.catalina.util.RequestUtil; public class WarpResponse extends HttpResponseBase { + /** The local stream */ + private Stream localstream; + /** The packet used for processing headers */ private WarpPacket packet; + /** The connection to which we are associated */ private WarpConnection connection; + /** + * Create a new instance of a <code>WarpResponse</code>. + */ public WarpResponse() { super(); - recycle(); + // A WarpResponse is _always_ associated with a Stream + this.localstream=new Stream(this); + this.setStream(localstream); } + /** + * Recycle this <code>WarpResponse</code> instance. + */ public void recycle() { + // Recycle our parent super.recycle(); - this.setStream(new Stream(this)); + // Recycle the stream + this.localstream.recycle(); + // Tell the parent that a stream is already in use. + this.setStream(localstream); } + /** + * Set the <code>WarpPacket</code> instance used to process headers. + */ public void setPacket(WarpPacket packet) { this.packet=packet; } + /** + * Return the <code>WarpPacket</code> instance used to process headers. + */ public WarpPacket getPacket() { return(this.packet); } - + + /** + * Associate this <code>WarpResponse</code> instance with a specific + * <code>WarpConnection</code> instance. + */ public void setConnection(WarpConnection connection) { this.connection=connection; } + /** + * Return the <code>WarpConnection</code> associated this instance of + * <code>WarpResponse</code>. + */ public WarpConnection getConnection() { return(this.connection); } /** + * Flush output and finish. + */ + public void finishResponse() + throws IOException { + super.finishResponse(); + this.localstream.finish(); + } + + /** * Send the HTTP response headers, if this has not already occurred. */ protected void sendHeaders() throws IOException { @@ -205,38 +244,79 @@ committed = true; } - - private class Stream extends OutputStream { - private WarpConnection connection; - private WarpPacket packet; - - private Stream(WarpResponse response) { + + /** + * The <code>OutputStream</code> that will handle all response body + * transmission. + */ + protected class Stream extends OutputStream { + /** The response associated with this stream instance. */ + private WarpResponse response=null; + /** The packet used by this stream instance. */ + private WarpPacket packet=null; + /** Wether <code>close()</code> was called or not. */ + private boolean closed=false; + + /** + * Construct a new instance of a <code>WarpResponse.Stream</code> + * associated with a parent <code>WarpResponse</code>. + */ + protected Stream(WarpResponse response) { super(); - this.connection=response.getConnection(); + this.response=response; this.packet=new WarpPacket(); - packet.setType(Constants.TYPE_RES_BODY); } + /** + * Write one byte of data to the <code>WarpPacket</code> nested + * within this <code>WarpResponse.Stream</code>. All data is buffered + * until the <code>flush()</code> or <code>close()</code> method is + * not called. + */ public void write(int b) throws IOException { + if (closed) throw new IOException("Stream closed"); packet.buffer[packet.size++]=(byte)b; } + /** + * Flush the current packet to the WARP client. + */ public void flush() throws IOException { - this.connection.send(packet); - packet.reset(); + if (closed) throw new IOException("Stream closed"); packet.setType(Constants.TYPE_RES_BODY); + response.getConnection().send(packet); + packet.reset(); } - + + /** + * Flush this <code>WarpResponse.Stream</code> and close it. + */ public void close() throws IOException { + if (closed) throw new IOException("Stream closed"); flush(); - packet.reset(); packet.setType(Constants.TYPE_RES_DONE); - this.connection.send(packet); + response.getConnection().send(packet); packet.reset(); - packet.setType(Constants.TYPE_RES_BODY); + } + + /** + * Flush this <code>WarpResponse.Stream</code> and close it. + */ + public void finish() + throws IOException { + if (closed) return; + else this.close(); + } + + /** + * Recycle this <code>WarpResponse.Stream</code> instance. + */ + public void recycle() { + this.packet.reset(); + this.closed=false; } } }