hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r232374 - in /jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote: HttpProtocolHandler.java impl/ContentInputBuffer.java impl/ContentOutputBuffer.java impl/CoyoteHttpEntity.java impl/HttpConnectionProcessor.java
Date Fri, 12 Aug 2005 20:36:31 GMT
Author: olegk
Date: Fri Aug 12 13:36:25 2005
New Revision: 232374

URL: http://svn.apache.org/viewcvs?rev=232374&view=rev
Log:
Yet another round of refactoring

Added:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpEntity.java
      - copied, changed from r232346, jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentOutputBuffer.java
Removed:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentInputBuffer.java
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentOutputBuffer.java
Modified:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java?rev=232374&r1=232373&r2=232374&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpProtocolHandler.java
Fri Aug 12 13:36:25 2005
@@ -164,13 +164,9 @@
 	}
 	
 	public void pause() throws Exception {
-		// Does not seem to used by Tomcat 5.5
-        throw new NotImplementedException("Method not implemented"); 
 	}
 
 	public void resume() throws Exception {
-		// Does not seem to used by Tomcat 5.5
-        throw new NotImplementedException("Method not implemented"); 
 	}
 
 	public Adapter getAdapter() {

Copied: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpEntity.java
(from r232346, jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentOutputBuffer.java)
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpEntity.java?p2=jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpEntity.java&p1=jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentOutputBuffer.java&r1=232346&r2=232374&rev=232374&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentOutputBuffer.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/CoyoteHttpEntity.java
Fri Aug 12 13:36:25 2005
@@ -33,11 +33,8 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.coyote.OutputBuffer;
-import org.apache.coyote.Response;
 import org.apache.http.HttpEntity;
 import org.apache.http.coyote.NotImplementedException;
-import org.apache.tomcat.util.buf.ByteChunk;
 
 /**
  * <p>
@@ -46,14 +43,14 @@
  *
  * @version $Revision$
  */
-public class ContentOutputBuffer implements HttpEntity, OutputBuffer {
+public class CoyoteHttpEntity implements HttpEntity {
 
     private long contentLength = -1;
     private String contentType = null;
     private String contentEncoding = null;
     private OutputStream outstream = null;    
     
-    public ContentOutputBuffer() {
+    public CoyoteHttpEntity() {
         super();
     }
 
@@ -103,14 +100,13 @@
         return false;
     }
 
-    public int doWrite(final ByteChunk chunk, final Response response) throws IOException
{
-        if (chunk == null) {
-            throw new IllegalStateException("Byte chunk may not be null");
+    public int writeBytes(final byte[] buffer) throws IOException {
+        if (buffer == null) {
+            throw new IllegalStateException("Buffer may not be null");
         }
         if (this.outstream == null) {
             throw new IllegalStateException("Output stream is null");
         }
-        byte[] buffer = chunk.getBuffer();
         this.outstream.write(buffer);
         return buffer.length;
     }

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java?rev=232374&r1=232373&r2=232374&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java
Fri Aug 12 13:36:25 2005
@@ -42,6 +42,8 @@
 import org.apache.coyote.ActionHook;
 import org.apache.coyote.Adapter;
 import org.apache.coyote.Constants;
+import org.apache.coyote.InputBuffer;
+import org.apache.coyote.OutputBuffer;
 import org.apache.coyote.Request;
 import org.apache.coyote.Response;
 import org.apache.http.ConnectionClosedException;
@@ -77,6 +79,7 @@
 import org.apache.http.protocol.ResponseContent;
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
+import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.http.MimeHeaders;
 
 /**
@@ -87,7 +90,7 @@
  * @version $Revision$
  */
 public class HttpConnectionProcessor extends AbstractHttpProcessor 
-										implements IOProcessor, ActionHook {
+		implements IOProcessor, InputBuffer, OutputBuffer, ActionHook {
 
     private static Log LOG = LogFactory.getLog(HttpConnectionProcessor.class);
 	
@@ -101,12 +104,12 @@
     private final Request coyotereq;
     private final Response coyoteres;
     
-    private ContentInputBuffer inbuffer = null;
-    private ContentOutputBuffer outbuffer = null;
-    
     private HttpRequest httpreq = null;
     private HttpResponse httpres = null;
     
+    private HttpEntity in = null;
+    private CoyoteHttpEntity out = null;
+    
     public HttpConnectionProcessor(
             final HttpServerConnection conn,
             final HttpParams params,
@@ -129,6 +132,8 @@
         
         this.coyotereq = new Request();
         this.coyoteres = new Response();
+        this.coyotereq.setInputBuffer(this);
+        this.coyoteres.setOutputBuffer(this);
         this.coyoteres.setHook(this);
         this.coyoteres.setRequest(this.coyotereq);
 
@@ -211,16 +216,20 @@
     }
 
     private void sendAck() throws IOException {
-        HttpVersion ver = this.httpreq.getRequestLine().getHttpVersion();
-        BasicHttpResponse ack = new BasicHttpResponse(new StatusLine(ver, 
-                HttpStatus.SC_CONTINUE));
-        try {
-            this.conn.sendResponse(ack);
-            LOG.debug("Ack continue sent");
-        } catch (HttpException ex) {
-            LOG.error("Malformed HTTP response", ex);
-            this.conn.close();
-        }
+    	if (this.httpreq instanceof HttpEntityEnclosingRequest) {
+    		if (((HttpEntityEnclosingRequest)this.httpreq).expectContinue()) {
+    	        HttpVersion ver = this.httpreq.getRequestLine().getHttpVersion();
+    	        BasicHttpResponse ack = new BasicHttpResponse(
+    	        		new StatusLine(ver, HttpStatus.SC_CONTINUE));
+    	        try {
+    	            this.conn.sendResponse(ack);
+    	            LOG.debug("Ack continue sent");
+    	        } catch (HttpException ex) {
+    	            LOG.error("Malformed HTTP response", ex);
+    	            this.conn.close();
+    	        }
+    		}
+    	}
     }
     
     private void sendHttpResponse() throws IOException {
@@ -237,14 +246,14 @@
     }
 
     private void flushOutputBuffer() throws IOException {
-        if (this.outbuffer != null) {
-            this.outbuffer.flush();
+        if (this.out != null) {
+            this.out.flush();
         }
     }
     
     private void closeOutputBuffer() throws IOException {
-        if (this.outbuffer != null) {
-            this.outbuffer.close();
+        if (this.out != null) {
+            this.out.close();
         }
     }
     
@@ -323,13 +332,9 @@
         	this.coyotereq.getMimeHeaders().addValue(header.getName()).setString(header.getValue());
         }
         
-        // Create the input buffer
+        // Keep the input entity if available
         if (this.httpreq instanceof HttpEntityEnclosingRequest) {
-        	HttpEntity entity = ((HttpEntityEnclosingRequest)this.httpreq).getEntity();
-        	if (entity != null) {
-                this.inbuffer = new ContentInputBuffer(entity);
-        		this.coyotereq.setInputBuffer(this.inbuffer);
-        	}
+        	this.in = ((HttpEntityEnclosingRequest)this.httpreq).getEntity();
         }
     }
         
@@ -355,6 +360,7 @@
         HttpVersion ver = this.httpreq.getRequestLine().getHttpVersion();
         int statuscode = this.coyoteres.getStatus(); 
         BasicHttpResponse tmp = new BasicHttpResponse(new StatusLine(ver, statuscode));
+        this.httpres = tmp;
         MimeHeaders headers = this.coyoteres.getMimeHeaders();
         int size = headers.size();
         for (int i = 0; i < size; i++) {
@@ -368,13 +374,11 @@
         }
         ResponseStrategy responsestrategy = new DefaultResponseStrategy();
         if (responsestrategy.canHaveEntity(this.httpreq, this.httpres)) {
-            this.outbuffer = new ContentOutputBuffer();
-            this.outbuffer.setContentLength(this.coyoteres.getContentLengthLong());
-            this.outbuffer.setContentType(this.coyoteres.getContentType());
-        	tmp.setEntity(this.outbuffer);
-        	this.coyoteres.setOutputBuffer(this.outbuffer);
+            this.out = new CoyoteHttpEntity();
+            this.out.setContentLength(this.coyoteres.getContentLengthLong());
+            this.out.setContentType(this.coyoteres.getContentType());
+        	tmp.setEntity(this.out);
         }
-        this.httpres = tmp;
     }
 
     private void manageHttpConnection() throws IOException {
@@ -394,10 +398,10 @@
     private void reset() {
         this.coyotereq.recycle();
         this.coyoteres.recycle();
-        this.inbuffer = null;
-        this.outbuffer = null;
         this.httpreq = null;
         this.httpres = null;
+        this.out = null;
+        this.in = null;
     }
     
     public void close() throws IOException {
@@ -484,5 +488,38 @@
         			" not implemented"); 
         }
 	}
-    
+
+	private byte[] inbuffer = new byte[1024];
+	
+	public int doRead(final ByteChunk chunk, final Request request) throws IOException {
+		if (chunk == null) {
+			throw new IllegalArgumentException("Byte chunk may not be null");
+		}
+		if (this.in != null) {
+			int l = this.in.getContent().read(this.inbuffer);
+			if (l >= 0) {
+				chunk.setBytes(this.inbuffer, 0, l);
+			}
+			return l;
+		} else {
+			return -1;
+		}
+	}
+
+	public int doWrite(final ByteChunk chunk, final Response response) throws IOException {
+		if (chunk == null) {
+			throw new IllegalArgumentException("Byte chunk may not be null");
+		}
+		if (!this.coyoteres.isCommitted()) {
+            prepareHttpResponse();
+            sendHttpResponse();
+            this.coyoteres.setCommitted(true);
+		}
+		if (this.out != null) {
+			return this.out.writeBytes(chunk.getBytes()); 
+		} else {
+			return 0;
+		}
+	}
+	
 }



Mime
View raw message