You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by sh...@locus.apache.org on 2000/05/25 16:18:23 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/service/connector Ajp13ConnectorRequest.java Ajp13ConnectorResponse.java

shachor     00/05/25 07:18:23

  Modified:    src/share/org/apache/tomcat/service/connector
                        Ajp13ConnectorRequest.java
                        Ajp13ConnectorResponse.java
  Log:
  Support for reading form data in ajp13 and some bug fixes
  
  Revision  Changes    Path
  1.2       +44 -13    jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorRequest.java
  
  Index: Ajp13ConnectorRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorRequest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Ajp13ConnectorRequest.java	2000/05/19 07:14:16	1.1
  +++ Ajp13ConnectorRequest.java	2000/05/25 14:18:22	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorRequest.java,v 1.1 2000/05/19 07:14:16 shachor Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/05/19 07:14:16 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorRequest.java,v 1.2 2000/05/25 14:18:22 shachor Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/05/25 14:18:22 $
    *
    * ====================================================================
    *
  @@ -73,6 +73,12 @@
   
   public class Ajp13ConnectorRequest extends RequestImpl 
   {
  +	public static final int  MAX_READ_SIZE = TcpConnector.MAX_PACKET_SIZE - 
  +	                                         TcpConnector.H_SIZE - 
  +	                                         2;
  +	                                         
  +	public static final byte JK_AJP13_GET_BODY_CHUNK = 6;
  +	
       public static final byte SC_A_CONTEXT      = 1;
       public static final byte SC_A_SERVLET_PATH = 2;
       public static final byte SC_A_REMOTE_USER  = 3;
  @@ -112,10 +118,8 @@
       };
   
       MsgConnector con;
  -    Hashtable env_vars;
   
  -    private InputStream in;
  -    byte bodyBuff[];
  +    byte []bodyBuff = new byte[MAX_READ_SIZE];
       int blen;
       int pos;
   
  @@ -212,6 +216,17 @@
   
           contentLength = headers.getIntHeader("content-length");
           contentType = headers.getHeader("content-type");
  +    	((BufferedServletInputStream)this.in).setLimit(contentLength);
  +    	if(contentLength > 0) {    		
  +    		/* Read present data */
  +    		int err = con.receive(msg);
  +            if(err < 0) {
  +            	return -1;                
  +			}
  +
  +    		blen = msg.peekInt();
  +    		msg.getBytes(bodyBuff);
  +    	}
       
           return 0;
       }
  @@ -219,8 +234,7 @@
       public int doRead() throws IOException 
       {
           if(pos > blen) {
  -            System.out.println("Read after end " + pos + " " + blen );
  -            return  -1;
  +            refeelReadBuffer();
           }
           return bodyBuff[pos++];
       }
  @@ -228,15 +242,15 @@
       public int doRead(byte[] b, int off, int len) throws IOException 
       {
           // XXXXXX Stupid, but the whole thing must be rewriten ( see super()! )
  -        for(int i = off ; i < len+off ; i++) {
  -            int a=doRead();
  -            if(a==-1) {
  +        for(int i = off ; i < (len + off) ; i++) {
  +            int a = doRead();
  +            if(-1 == a) {
                   System.out.println("Y");
                   return i-off;
               }
  -            b[i]=(byte)a;
  +            b[i] = (byte)a;
           }
  -        System.out.println("doRead " + off + " " + len );
  +        
           return len;
       }
       
  @@ -252,4 +266,21 @@
           pos = 0;
           this.in = new BufferedServletInputStream(this);
       }   
  +    
  +    public void refeelReadBuffer() throws IOException 
  +    {
  +		MsgBuffer msg = con.getMsgBuffer();
  +		msg.appendByte(JK_AJP13_GET_BODY_CHUNK);
  +		msg.appendInt(MAX_READ_SIZE);
  +		con.send(msg);
  +		
  +		int err = con.receive(msg);
  +        if(err < 0) {
  +        	throw new IOException();
  +		}
  +
  +    	blen = msg.peekInt();
  +    	pos = 0;
  +    	msg.getBytes(bodyBuff);
  +    }    
   }
  
  
  
  1.3       +27 -19    jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorResponse.java
  
  Index: Ajp13ConnectorResponse.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorResponse.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Ajp13ConnectorResponse.java	2000/05/23 21:39:52	1.2
  +++ Ajp13ConnectorResponse.java	2000/05/25 14:18:23	1.3
  @@ -1,8 +1,8 @@
   
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorResponse.java,v 1.2 2000/05/23 21:39:52 costin Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/05/23 21:39:52 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorResponse.java,v 1.3 2000/05/25 14:18:23 shachor Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/05/25 14:18:23 $
    *
    * ====================================================================
    *
  @@ -75,6 +75,10 @@
   
   public class Ajp13ConnectorResponse extends ResponseImpl 
   {
  +	public static final int  MAX_SEND_SIZE = TcpConnector.MAX_PACKET_SIZE - 
  +	                                         TcpConnector.H_SIZE - 
  +	                                         2;
  +	
       public static final byte JK_AJP13_SEND_BODY_CHUNK   = 3;
       public static final byte JK_AJP13_SEND_HEADERS      = 4;
       public static final byte JK_AJP13_END_RESPONSE      = 5;
  @@ -96,7 +100,7 @@
   
       public Ajp13ConnectorResponse() 
       {
  -}
  +	}
   
       // XXX if more headers that MAX_SIZE, send 2 packets!   
       public void endHeaders() throws IOException 
  @@ -107,11 +111,12 @@
               return;
           }
       
  -	// Servlet Engine header will be set per/adapter - smarter adapters will
  -	// not send it every time ( have it in C side ), and we may also want
  -	// to add informations about the adapter used 
  -	if( request.getContext() != null)
  -	    setHeader("Servlet-Engine", request.getContext().getEngineHeader());
  +		// Servlet Engine header will be set per/adapter - smarter adapters will
  +		// not send it every time ( have it in C side ), and we may also want
  +		// to add informations about the adapter used 
  +		if(request.getContext() != null) {
  +	    	setHeader("Servlet-Engine", request.getContext().getEngineHeader());
  +	    }
   
           MsgBuffer msg=con.getMsgBuffer();
           msg.reset();
  @@ -219,8 +224,7 @@
           rout.setResponse(this);
           this.out = rout;
       }
  -    
  -    
  +        
   	class Ajp13OutputStream extends BufferedServletOutputStream  
   	{     
       	MsgConnector con;
  @@ -233,14 +237,18 @@
   
       	public void doWrite(  byte b[], int off, int len) throws IOException 
       	{
  -        	// XXX check if len > MAX_PACKET_SIZE !
  -        	MsgBuffer buf = con.getMsgBuffer();
  -        	buf.reset();
  -        	buf.appendByte(Ajp13ConnectorResponse.JK_AJP13_SEND_BODY_CHUNK);
  -        	// XXX avoid copy !!
  -        	buf.appendBytes( b, off, len );
  -        	buf.end();
  -        	con.send(buf);
  +        	int sent = 0;
  +        	while(sent < len) {
  +        		int to_send = len - sent;
  +        		to_send = to_send > MAX_SEND_SIZE ? MAX_SEND_SIZE : to_send;
  +        		
  +	        	MsgBuffer buf = con.getMsgBuffer();
  +	        	buf.reset();
  +	        	buf.appendByte(Ajp13ConnectorResponse.JK_AJP13_SEND_BODY_CHUNK);	        	
  +	        	buf.appendBytes(b, off + sent, to_send);	        
  +	        	con.send(buf);
  +	        	sent += to_send;
  +	        }
       	}
   
       	protected void endResponse() throws IOException