costin      02/04/05 10:42:03

  Added:       coyote/src/java/org/apache/coyote/tomcat3
                        CoyoteInterceptor2.java Tomcat3Adapter.java
                        Tomcat3Request.java Tomcat3Response.java
  Log:
  Initial ( and incomplete ) refactoring to use ProtocolHandler and
  stateless objects.
  
  I used different names to avoid affecting the existing ( working ) impl.,
  the code is cut and pasted.
  
  After I get everything stable we can switch back to the original
  names or keep the new ones.
  
  Revision  Changes    Path
  1.1                  
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat3/CoyoteInterceptor2.java
  
  Index: CoyoteInterceptor2.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.coyote.tomcat3;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import java.text.*;
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.util.res.StringManager;
  import org.apache.tomcat.util.IntrospectionUtils;
  import org.apache.tomcat.util.buf.*;
  import org.apache.tomcat.util.http.*;
  import org.apache.tomcat.util.log.*;
  import org.apache.tomcat.util.compat.*;
  import org.apache.tomcat.util.net.*;
  import org.apache.coyote.*;
  
  /** Standalone http.
   *
   *  Connector properties:
   *  <ul>
   *  <li> secure - will load a SSL socket factory and act as https server</li>
   *  </ul>
   *
   *  Properties passed to the net layer:
   *  <ul>
   *  <li>timeout</li>
   *  <li>backlog</li>
   *  <li>address</li>
   *  <li>port</li>
   *  </ul>
   * Thread pool properties:
   *  <ul>
   *  <li>minSpareThreads</li>
   *  <li>maxSpareThreads</li>
   *  <li>maxThreads</li>
   *  <li>poolOn</li>
   *  </ul>
   * Properties for HTTPS:
   *  <ul>
   *  <li>keystore - certificates - default to ~/.keystore</li>
   *  <li>keypass - password</li>
   *  <li>clientauth - true if the server should authenticate the client using 
certs</li>
   *  </ul>
   * Properties for HTTP:
   *  <ul>
   *  <li>reportedname - name of server sent back to browser (security purposes)</li>
   *  </ul>
   */
  public class CoyoteInterceptor2 extends BaseInterceptor
  {
      private String processorClassName="org.apache.coyote.http11.Http11Protocol";
      Tomcat3Adapter adapter;
      ProtocolHandler proto;
      
      public CoyoteInterceptor2() {
        super();
        // defaults:
          this.setAttribute( "port", "8080" );
          this.setAttribute( "soLinger", "100" );
      }
  
      // -------------------- PoolTcpConnector --------------------
  
      /** Set the class of the processor to use.
       */
      public void setProcessorClassName(String pcn) {
        processorClassName = pcn;
      }
  
      // -------------------- Start/stop --------------------
      Hashtable attributes=new Hashtable();
      
      public void setAttribute( String prop, Object value) {
        attributes.put( prop, value );
      }
  
  
      public void setProperty( String prop, String value ) {
          setAttribute( prop, value );
      }
  
      /** Called when the ContextManger is started
       */
      public void engineInit(ContextManager cm) throws TomcatException {
        super.engineInit( cm );
          
          adapter=new Tomcat3Adapter(cm);
          try {
              Class c=Class.forName(processorClassName);
              proto=(ProtocolHandler)c.newInstance();
          } catch( Exception ex ) {
              ex.printStackTrace();
          }
  
          proto.setAdapter( adapter );
          try {
              Enumeration keys=attributes.keys();
              while( keys.hasMoreElements() ) {
                  String k=(String)keys.nextElement();
                  Object o=attributes.get(k);
                  if( o instanceof String )
                      IntrospectionUtils.setProperty( proto, k, (String)o );
                  else
                      IntrospectionUtils.setAttribute( proto, k, o );
              }
          } catch( Exception ex ) {
              throw new TomcatException( "Error setting protocol properties ", ex );
          }
      }
  
      /** Called when the ContextManger is started
       */
      public void engineStart(ContextManager cm) throws TomcatException {
        try {
              proto.init();
        } catch( Exception ex ) {
              ex.printStackTrace();
            throw new TomcatException( ex );
        }
      }
  
      public void engineShutdown(ContextManager cm) throws TomcatException {
        try {
            proto.destroy();    
          } catch( Exception ex ) {
            throw new TomcatException( ex );
        }
      }
  
      // -------------------- Handler implementation --------------------
  
      /** Handle HTTP expectations.
       */
      public int preService(org.apache.tomcat.core.Request request,
                            org.apache.tomcat.core.Response response) {
        if(response instanceof CoyoteResponse) {
            try {
                ((CoyoteResponse)response).sendAcknowledgement();
            } catch(Exception ex) {
                log("Can't send ACK", ex);
            }
        }
        return 0;
      }
  }
  
  
  
  
  1.1                  
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat3/Tomcat3Adapter.java
  
  Index: Tomcat3Adapter.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.coyote.tomcat3;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import java.text.*;
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.util.res.StringManager;
  import org.apache.tomcat.util.buf.*;
  import org.apache.tomcat.util.http.*;
  import org.apache.tomcat.util.net.*;
  import org.apache.tomcat.util.net.ServerSocketFactory;
  import org.apache.tomcat.util.log.*;
  import org.apache.tomcat.util.compat.*;
  import org.apache.coyote.Adapter;
  import org.apache.coyote.Processor;
  
  /** Adapter between Coyote and Tomcat.
   *
   *  This class handles the task of passing of an individual request to
   *  Tomcat to handle.  Also some of the connection-specific methods are
   *  delegated to here.
   *  @Author Bill Barker
   */
  public class Tomcat3Adapter implements Adapter {
      ContextManager cm;
      
      Tomcat3Adapter(ContextManager ctxman) {
        cm   = ctxman;
      }
  
      static int containerRequestNOTE=1; // XXX Implement a NoteManager, namespaces.
      
      /** Pass off an individual request to Tomcat.
       */
      public void service(org.apache.coyote.Request request, 
                        org.apache.coyote.Response response) 
            throws Exception
      {
          Tomcat3Request reqA;
          Tomcat3Response resA;
  
          reqA=(Tomcat3Request)request.getNote( containerRequestNOTE );
          if( reqA==null ) {
              reqA=new Tomcat3Request();
              resA=new Tomcat3Response();
              cm.initRequest( reqA, resA );
  
              reqA.setCoyoteRequest(request);
              resA.setCoyoteResponse(response);
          } else {
              resA=(Tomcat3Response)reqA.getResponse();
          }
          
            
        cm.service( reqA, resA );
  
          reqA.recycle();
          resA.recycle();
      }
  }
  
  
  
  1.1                  
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat3/Tomcat3Request.java
  
  Index: Tomcat3Request.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.coyote.tomcat3;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import java.text.*;
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.util.res.StringManager;
  import org.apache.tomcat.util.buf.*;
  import org.apache.tomcat.util.http.*;
  import org.apache.tomcat.util.net.*;
  import org.apache.tomcat.util.net.ServerSocketFactory;
  import org.apache.tomcat.util.log.*;
  import org.apache.tomcat.util.compat.*;
  import org.apache.coyote.Adapter;
  import org.apache.coyote.Processor;
  
  /** The Request to connect with Coyote.
   *  This class handles the I/O requirements and transferring the request
   *  line and Mime headers between Coyote and Tomcat.
   *  @Author Bill Barker
   */
  public class Tomcat3Request extends org.apache.tomcat.core.Request {
  
      org.apache.coyote.Request coyoteRequest=null;
      
      SSLSupport sslSupport=null;
      ByteChunk  readChunk = new ByteChunk();
      int  pos=-1;
      int  end=-1;
      byte [] readBuffer = null;
      Socket socket = null;
  
      public Tomcat3Request() {
          super();
          remoteAddrMB.recycle();
          remoteHostMB.recycle();
      }
  
      public void recycle() {
        super.recycle();
        if( coyoteRequest != null) coyoteRequest.recycle();
          remoteAddrMB.recycle();
          remoteHostMB.recycle();
  
        readChunk.recycle();
        sslSupport=null;
        readBuffer=null;
        pos=-1;
        end=-1;
      }
  
      /** Attach the Coyote Request to this Request.
       *  This is currently set pre-request to allow copying the request
       *  attributes to the Tomcat attributes.
       */
      public void setCoyoteRequest(org.apache.coyote.Request cReq) {
        coyoteRequest=cReq;
        // This is really ugly, but fast.
        // I could still be talked out of it.
        schemeMB.recycle();
        methodMB.recycle();
        uriMB.recycle();
        queryMB.recycle();
        protoMB.recycle();
        try {
            schemeMB.duplicate(coyoteRequest.scheme());
            methodMB.duplicate(coyoteRequest.method());
            uriMB.duplicate(coyoteRequest.requestURI());
            queryMB.duplicate(coyoteRequest.query());
            protoMB.duplicate(coyoteRequest.protocol());
        } catch(IOException iex) { // ignore
        }
        headers  = coyoteRequest.getMimeHeaders();
        scookies.setHeaders(headers);
        params.setHeaders(headers);
      }
      /** Set the socket for this request.
       */
      public void setSocket(Socket socket) {
        this.socket = socket;
      }
  
      /** Read a single character from the request body.
       */
      public int doRead() throws IOException {
        if( available == 0 ) 
            return -1;
        // #3745
        // if available == -1: unknown length, we'll read until end of stream.
        if( available!= -1 )
            available--;
        if(pos >= end) {
            if(readBytes() < 0)
                return -1;
        }
        return readBuffer[pos++] & 0xFF;
      }
  
      /** Read a chunk from the request body.
       */
      public int doRead(byte[] b, int off, int len) throws IOException {
        if( available == 0 )
            return -1;
        // if available == -1: unknown length, we'll read until end of stream.
        if(pos >= end) {
            if(readBytes() < 0) 
                return -1;
        }
        int rd = -1;
        if((end - pos) > len) {
            rd = len;
        } else {
            rd = end - pos;
        }
  
          System.arraycopy(readBuffer, pos, b, off, rd);
        pos += rd;
        if( available!= -1 )
            available -= rd;
  
        return rd;
      }
      
      /**
       * Read bytes to the read chunk buffer.
       */
      protected int readBytes()
          throws IOException {
  
          int result = coyoteRequest.doRead(readChunk);
          if (result > 0) {
              readBuffer = readChunk.getBytes();
              end = readChunk.getEnd();
              pos = readChunk.getStart();
          }
          return result;
  
      }
  
      // -------------------- override special methods
  
      public MessageBytes remoteAddr() {
        if( remoteAddrMB.isNull() ) {
            remoteAddrMB.setString(socket.getInetAddress().getHostAddress());
        }
        return remoteAddrMB;
      }
  
      public MessageBytes remoteHost() {
        if( remoteHostMB.isNull() ) {
            remoteHostMB.setString( socket.getInetAddress().getHostName() );
        }
        return remoteHostMB;
      }
  
      public String getLocalHost() {
        InetAddress localAddress = socket.getLocalAddress();
        localHost = localAddress.getHostName();
        return localHost;
      }
  
      public MessageBytes serverName(){
          // if(! serverNameMB.isNull()) return serverNameMB;
          // parseHostHeader();
          return coyoteRequest.serverName();
      }
  
      public int getServerPort(){
          // if(serverPort!=-1) return serverPort;
          //No need to delay execution - the host is certainly needed for
          // mapping.
          // parseHostHeader();
          return coyoteRequest.getServerPort();
      }
  
      /** Define the SSL Support support instance for this socket.
       */
      void setSSLSupport(SSLSupport s){
          sslSupport=s;
      }
   
  }
  
  
  
  1.1                  
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat3/Tomcat3Response.java
  
  Index: Tomcat3Response.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    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 Group.
   *
   * 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
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  
  package org.apache.coyote.tomcat3;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import java.text.*;
  import org.apache.tomcat.core.*;
  import org.apache.tomcat.util.res.StringManager;
  import org.apache.tomcat.util.buf.*;
  import org.apache.tomcat.util.http.*;
  import org.apache.tomcat.util.net.*;
  import org.apache.tomcat.util.net.ServerSocketFactory;
  import org.apache.tomcat.util.log.*;
  import org.apache.tomcat.util.compat.*;
  
  
  /** The Response to connect with Coyote.
   *  This class mostly handles the I/O between Tomcat and Coyte.
   *  @Author Bill Barker
   */
  
  class Tomcat3Response extends  Response {
      String reportedname=null;
      org.apache.coyote.Response coyoteResponse=null;
      ByteChunk outputChunk = new ByteChunk();
      boolean  acknowledged=false;
      
      public Tomcat3Response() {
          super();
      }
  
      /** Attach a Coyote Request to this request.
       */
      public void setCoyoteResponse(org.apache.coyote.Response cRes) {
        coyoteResponse = cRes;
        headers = coyoteResponse.getMimeHeaders();
      }
  
      public void init() {
        super.init();
      }
  
      public void recycle() {
        super.recycle();
        if(coyoteResponse != null) coyoteResponse.recycle();
        outputChunk.recycle();
        acknowledged=false;
      }
  
      public void setReported(String reported) {
          reportedname = reported;
      }
  
      public void endHeaders()  throws IOException {
        super.endHeaders();
        coyoteResponse.setStatus(getStatus());
        coyoteResponse.sendHeaders();
      }
  
      public void doWrite( byte buffer[], int pos, int count)
        throws IOException
      {
        if( count > 0 ) {
            outputChunk.setBytes(buffer, pos, count);
            coyoteResponse.doWrite( outputChunk );
        }
      }
  
      public void reset() throws IllegalStateException {
        super.reset();
        if( ! included )
            coyoteResponse.reset();
      }
      public void finish() throws IOException {
        super.finish();
        coyoteResponse.finish();
      }
      /**
       * Send an acknowledgment of a request.
       * 
       * @exception IOException if an input/output error occurs
       */
      public void sendAcknowledgement()
          throws IOException {
  
        if( status >= 300 ) // Don't ACK on errors.
            acknowledged = true;
        // Don't ACK twice on the same request. (e.g. on a forward)
        if(acknowledged)
            return;
          // Ignore any call from an included servlet
          if (isIncluded())
              return; 
          if (isBufferCommitted())
              throw new IllegalStateException
                  (sm.getString("hsrf.error.ise"));
  
        coyoteResponse.acknowledge();
        acknowledged=true;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to