You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2007/02/02 20:57:31 UTC

svn commit: r502707 - in /jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector: HttpProtocolHandler.java impl/CoyoteHttpConnectionImpl.java impl/HttpConnectionProcessor.java

Author: olegk
Date: Fri Feb  2 11:57:30 2007
New Revision: 502707

URL: http://svn.apache.org/viewvc?view=rev&rev=502707
Log:
Fixed breakage in the test Tomcat connector caused by the API changes in HttpCore

Modified:
    jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/HttpProtocolHandler.java
    jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java
    jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java

Modified: jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/HttpProtocolHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/HttpProtocolHandler.java?view=diff&rev=502707&r1=502706&r2=502707
==============================================================================
--- jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/HttpProtocolHandler.java (original)
+++ jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/HttpProtocolHandler.java Fri Feb  2 11:57:30 2007
@@ -39,7 +39,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.coyote.Adapter;
 import org.apache.coyote.ProtocolHandler;
-import org.apache.http.impl.DefaultHttpParams;
+import org.apache.http.impl.params.DefaultHttpParams;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;

Modified: jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java?view=diff&rev=502707&r1=502706&r2=502707
==============================================================================
--- jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java (original)
+++ jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java Fri Feb  2 11:57:30 2007
@@ -40,7 +40,6 @@
 import org.apache.coyote.Response;
 import org.apache.http.ConnectionClosedException;
 import org.apache.http.Header;
-import org.apache.http.HeaderElement;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
@@ -48,12 +47,12 @@
 import org.apache.http.HttpRequestFactory;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolException;
 import org.apache.http.RequestLine;
+import org.apache.http.entity.ContentLengthStrategy;
 import org.apache.http.impl.DefaultHttpRequestFactory;
+import org.apache.http.impl.entity.StrictContentLengthStrategy;
 import org.apache.http.impl.io.SocketHttpDataReceiver;
 import org.apache.http.impl.io.SocketHttpDataTransmitter;
-import org.apache.http.io.CharArrayBuffer;
 import org.apache.http.io.ChunkedInputStream;
 import org.apache.http.io.ChunkedOutputStream;
 import org.apache.http.io.ContentLengthInputStream;
@@ -68,9 +67,9 @@
 import org.apache.http.message.BufferedHeader;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HTTP;
 import org.apache.http.tcconnector.CommitTrigger;
 import org.apache.http.tcconnector.CoyoteHttpConnection;
+import org.apache.http.util.CharArrayBuffer;
 import org.apache.http.util.HeaderUtils;
 import org.apache.tomcat.util.buf.ByteChunk;
 
@@ -88,6 +87,7 @@
     private final HttpDataReceiver datareceiver;
     private final CharArrayBuffer charbuffer; 
     private final HttpRequestFactory requestfactory;
+    private final ContentLengthStrategy contentLenStrategy;
     private final byte[] readbuffer;
     private final int maxHeaderCount;
 
@@ -118,6 +118,7 @@
         this.datareceiver = new SocketHttpDataReceiver(socket, buffersize); 
         this.charbuffer = new CharArrayBuffer(256);
         this.requestfactory = new DefaultHttpRequestFactory();
+        this.contentLenStrategy = new StrictContentLengthStrategy();
         this.readbuffer = new byte[buffersize];
         this.maxHeaderCount = params.getIntParameter(HttpConnectionParams.MAX_HEADER_COUNT, -1);
     }
@@ -182,37 +183,13 @@
         // Prepare input stream
         this.in = null;
         if (request instanceof HttpEntityEnclosingRequest) {
-            Header transferEncodingHeader = request.getLastHeader(HTTP.TRANSFER_ENCODING);
-            Header contentLengthHeader = request.getLastHeader(HTTP.CONTENT_LEN);
-            if (transferEncodingHeader != null) {
-                HeaderElement[] encodings = transferEncodingHeader.getElements();
-                for (i = 0; i < encodings.length; i++) {
-                    String encoding = encodings[i].getName();
-                    if (encoding != null && encoding.length() > 0 
-                        && !encoding.equalsIgnoreCase(HTTP.CHUNK_CODING)
-                        && !encoding.equalsIgnoreCase(HTTP.IDENTITY_CODING)) {
-                        throw new ProtocolException("Unsupported transfer encoding: " + encoding);
-                    }
-                }
-                int len = encodings.length;
-                if (HTTP.IDENTITY_CODING.equalsIgnoreCase(transferEncodingHeader.getValue())) {
-                    this.in = new HttpDataInputStream(this.datareceiver);                            
-                } else if ((len > 0) && (HTTP.CHUNK_CODING.equalsIgnoreCase(
-                        encodings[len - 1].getName()))) { 
-                    this.in = new ChunkedInputStream(datareceiver);
-                } else {
-                    throw new ProtocolException("Chunk-encoding must be the last one applied");
-                }
-            } else if (contentLengthHeader != null) {
-                try {
-                    long contentlen = Long.parseLong(contentLengthHeader.getValue());
-                    this.in = new ContentLengthInputStream(datareceiver, contentlen);
-                } catch (NumberFormatException e) {
-                    throw new ProtocolException("Invalid content length: " + 
-                            contentLengthHeader.getValue());
-                }
+            long len = this.contentLenStrategy.determineLength(request);
+            if (len == ContentLengthStrategy.CHUNKED) {
+                this.in = new ChunkedInputStream(this.datareceiver);
+            } else if (len == ContentLengthStrategy.IDENTITY) {
+                this.in = new HttpDataInputStream(this.datareceiver);                            
             } else {
-                throw new ProtocolException("Request entity is not correctly delimited");
+                this.in = new ContentLengthInputStream(datareceiver, len);
             }
         }
         return request;

Modified: jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java?view=diff&rev=502707&r1=502706&r2=502707
==============================================================================
--- jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java (original)
+++ jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java Fri Feb  2 11:57:30 2007
@@ -60,12 +60,11 @@
 import org.apache.http.StatusLine;
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.io.CharArrayBuffer;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.message.BasicStatusLine;
 import org.apache.http.message.BufferedHeader;
 import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.AbstractHttpProcessor;
+import org.apache.http.protocol.BasicHttpProcessor;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpExecutionContext;
@@ -81,6 +80,7 @@
 import org.apache.http.tcconnector.NotImplementedException;
 import org.apache.http.tcconnector.UnsupportedHttpVersionException;
 import org.apache.http.tcconnector.params.CoyoteParams;
+import org.apache.http.util.CharArrayBuffer;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.buf.CharChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
@@ -93,8 +93,7 @@
  *
  * @version $Revision:379772 $
  */
-public class HttpConnectionProcessor extends AbstractHttpProcessor 
-		implements IOProcessor, ActionHook {
+public class HttpConnectionProcessor implements IOProcessor, ActionHook {
 
     private static Log LOG = LogFactory.getLog(HttpConnectionProcessor.class);
 	
@@ -106,6 +105,7 @@
     private final IOProcessingListener listener;
     private final HttpContext context;
     private final ConnectionReuseStrategy connStrategy;
+    private final BasicHttpProcessor httpProcessor;
 
     private final Request coyotereq;
     private final Response coyoteres;
@@ -150,11 +150,12 @@
         this.coyoteres.setHook(this);
         this.coyoteres.setRequest(this.coyotereq);
         
+        this.httpProcessor = new BasicHttpProcessor();
         // Add required protocol interceptors
-        addInterceptor(new ResponseContent());
-        addInterceptor(new ResponseConnControl());
-        addInterceptor(new ResponseDate());
-        addInterceptor(new ResponseServer());
+        this.httpProcessor.addInterceptor(new ResponseContent());
+        this.httpProcessor.addInterceptor(new ResponseConnControl());
+        this.httpProcessor.addInterceptor(new ResponseDate());
+        this.httpProcessor.addInterceptor(new ResponseServer());
         
         // Add connection to the HTTP context
         this.context.setAttribute(HttpContext.HTTP_CONNECTION, conn);
@@ -217,20 +218,20 @@
         
         this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PREPARE);
 
-        preprocessRequest(this.httpreq, this.context);
+        this.httpProcessor.process(this.httpreq, this.context);
         // Add request to the HTTP context
         this.context.setAttribute(HttpContext.HTTP_REQUEST, this.httpreq);
     }
 
     private HttpResponse createResponse(int status) {
-        BasicHttpResponse response = new BasicHttpResponse();
-    	response.getParams().setDefaults(this.params);
+        HttpVersion ver;
         if (this.httpreq != null) {
-            HttpVersion ver = this.httpreq.getRequestLine().getHttpVersion();
-            response.setStatusLine(ver, status);
+            ver = this.httpreq.getRequestLine().getHttpVersion();
         } else {
-            response.setStatusCode(status);
+            ver = HttpVersion.HTTP_1_1;
         }
+        HttpResponse response = new BasicHttpResponse(ver, status);
+        response.getParams().setDefaults(this.params);
     	return response;
     }
     
@@ -263,7 +264,7 @@
     
     private void sendHttpResponse() throws IOException {
     	try {
-    	    postprocessResponse(this.httpres, this.context);
+    	    this.httpProcessor.process(this.httpres, this.context);
     		this.conn.sendResponse(this.httpres);
             LOG.debug("HTTP response header sent");
     	} catch (HttpException ex) {
@@ -459,7 +460,7 @@
 
     private void manageHttpConnection() throws IOException {
     	if (this.conn.isOpen()) {
-            if (!this.connStrategy.keepAlive(this.httpres)) {
+            if (!this.connStrategy.keepAlive(this.httpres, this.context)) {
                 this.conn.close();
             	LOG.debug("Connection closed");
                 this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_ENDED);