hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r231326 - in /jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl: HttpConnectionProcessor.java HttpProcessingContext.java
Date Wed, 10 Aug 2005 21:07:58 GMT
Author: olegk
Date: Wed Aug 10 14:07:52 2005
New Revision: 231326

URL: http://svn.apache.org/viewcvs?rev=231326&view=rev
Log:
HttpConnectionProcessor changed to extend the AbstractHttpProcessor

Added:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpProcessingContext.java
  (with props)
Modified:
    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/impl/HttpConnectionProcessor.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java?rev=231326&r1=231325&r2=231326&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
Wed Aug 10 14:07:52 2005
@@ -49,6 +49,7 @@
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
+import org.apache.http.HttpMutableRequest;
 import org.apache.http.HttpMutableResponse;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
@@ -71,6 +72,7 @@
 import org.apache.http.impl.DefaultResponseStrategy;
 import org.apache.http.impl.ResponseStrategy;
 import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.AbstractHttpProcessor;
 import org.apache.tomcat.util.http.MimeHeaders;
 
 /**
@@ -80,7 +82,8 @@
  *
  * @version $Revision$
  */
-public class HttpConnectionProcessor implements IOProcessor, ActionHook {
+public class HttpConnectionProcessor extends AbstractHttpProcessor 
+										implements IOProcessor, ActionHook {
 
     private static Log LOG = LogFactory.getLog(HttpConnectionProcessor.class);
 	
@@ -102,7 +105,7 @@
             final HttpParams params,
             final Adapter adapter,
             final IOProcessingListener listener) {
-    	super();
+    	super(new HttpProcessingContext(null));
         if (conn == null) {
             throw new IllegalArgumentException("HTTP connection may not be null");
         }
@@ -121,6 +124,8 @@
         this.coyoteres = new Response();
         this.coyoteres.setHook(this);
         this.coyoteres.setRequest(this.coyotereq);
+        
+        getContext().setAttribute(HttpProcessingContext.HTTP_CONNECTION, conn);
     }
 
     public void run() {
@@ -162,7 +167,7 @@
     }
 
     private void receiveHttpRequest() throws IOException, HttpException {
-        this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_NEW);
+        this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PARSE);
     	this.httpreq = this.conn.receiveRequest(this.params);
         this.coyotereq.setStartTime(System.currentTimeMillis());
         LOG.debug("HTTP request received");
@@ -194,14 +199,21 @@
     	}
     }
 
-    private void prepareCoyoteRequest() throws HttpException {
-        this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PARSE);
+    private void prepareCoyoteRequest() throws IOException, HttpException {
+
+    	this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PREPARE);
+        // Preprocess the request 
+        if (this.httpreq instanceof HttpMutableRequest) {
+        	preprocessRequest((HttpMutableRequest)this.httpreq);
+        }
+
         // Convert the request line
         RequestLine reqline = this.httpreq.getRequestLine();
         HttpVersion ver = reqline.getHttpVersion();
         if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
             throw new UnsupportedHttpVersionException("Unsupported verion: " + ver); 
         }
+
         this.coyotereq.method().setString(reqline.getMethod());
         this.coyotereq.unparsedURI().setString(reqline.getUri());
         
@@ -288,7 +300,8 @@
         }
 	}
 
-    private void prepareHttpResponse() {
+    private void prepareHttpResponse() throws IOException, HttpException {
+        this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_ENDINPUT);
         if (this.httpres != null) {
             return;
         }
@@ -316,6 +329,11 @@
         	this.coyoteres.setOutputBuffer(buffer);
         }
         this.httpres = tmp;
+
+        // Postprocess the response 
+        if (this.httpres instanceof HttpMutableResponse) {
+        	postprocessResponse((HttpMutableResponse)this.httpres);
+        }
     }
 
     private void manageHttpConnection() throws IOException {

Added: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpProcessingContext.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpProcessingContext.java?rev=231326&view=auto
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpProcessingContext.java
(added)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpProcessingContext.java
Wed Aug 10 14:07:52 2005
@@ -0,0 +1,84 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * 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/>.
+ *
+ */
+
+package org.apache.http.coyote.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class HttpProcessingContext implements HttpContext {
+    
+    public static final String HTTP_CONNECTION  = "http.connection"; 
+    public static final String HTTP_REQUEST     = "http.request"; 
+    public static final String HTTP_RESPONSE    = "http.response"; 
+    
+    private final HttpContext parentContext;
+    private Map<String, Object> map = null;
+    
+    public HttpProcessingContext(final HttpContext parentContext) {
+        super();
+        this.parentContext = parentContext;
+    }
+    
+    public Object getAttribute(final String id) {
+        if (id == null) {
+            throw new IllegalArgumentException("Id may not be null");
+        }
+        Object obj = null;
+        if (this.map != null) {
+            obj = this.map.get(id);
+        }
+        if (obj == null && this.parentContext != null) {
+            obj = this.parentContext.getAttribute(id);
+        }
+        return obj;
+    }
+
+    public void setAttribute(final String id, final Object obj) {
+        if (id == null) {
+            throw new IllegalArgumentException("Id may not be null");
+        }
+        if (this.map == null) {
+            this.map = new HashMap<String, Object>();
+        }
+        this.map.put(id, obj);
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpProcessingContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpProcessingContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpProcessingContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message