hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r231300 - in /jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl: ContentOutputBuffer.java HttpConnectionProcessor.java
Date Wed, 10 Aug 2005 19:41:20 GMT
Author: olegk
Date: Wed Aug 10 12:41:15 2005
New Revision: 231300

URL: http://svn.apache.org/viewcvs?rev=231300&view=rev
Log:
Added Coyote output buffer impl and Cotoye response to HTTP response conversion code

Added:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentOutputBuffer.java
  (with props)
Modified:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/HttpConnectionProcessor.java

Added: 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/ContentOutputBuffer.java?rev=231300&view=auto
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentOutputBuffer.java
(added)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/impl/ContentOutputBuffer.java
Wed Aug 10 12:41:15 2005
@@ -0,0 +1,125 @@
+/*
+ * $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.io.IOException;
+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>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ */
+public class ContentOutputBuffer implements HttpEntity, OutputBuffer {
+
+    private long contentLength = -1;
+    private String contentType = null;
+    private String contentEncoding = null;
+    private OutputStream outstream = null;    
+    
+    public ContentOutputBuffer() {
+        super();
+    }
+
+    public InputStream getContent() throws IOException {
+        throw new NotImplementedException("getContent() method not implemented");
+    }
+
+    public long getContentLength() {
+        return this.contentLength;
+    }
+
+    public void setContentLength(long contentLength) {
+        this.contentLength = contentLength;
+    }
+
+    public boolean isChunked() {
+        return this.contentLength < 0;
+    }
+
+    public boolean isRepeatable() {
+        return false;
+    }
+    
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    public void setContentType(final String contentType) {
+        this.contentType = contentType;
+    }
+    
+    public String getContentEncoding() {
+        return this.contentEncoding;
+    }
+    
+    public void setContentEncoding(final String contentEncoding) {
+        this.contentEncoding = contentEncoding;
+    }
+    
+    public boolean writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        this.outstream = outstream;
+        // We intend to keep the output stream for further write 
+        // operations. MUST return false;
+        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");
+        }
+        if (this.outstream == null) {
+            throw new IllegalStateException("Output stream is null");
+        }
+        byte[] buffer = chunk.getBuffer();
+        this.outstream.write(buffer);
+        return buffer.length;
+    }
+    
+    public void close() throws IOException {
+        if (this.outstream != null) {
+            this.outstream.close();
+            this.outstream = null;
+        }
+    }
+        
+}

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

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

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

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=231300&r1=231299&r2=231300&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 12:41:15 2005
@@ -58,15 +58,20 @@
 import org.apache.http.MethodNotSupportedException;
 import org.apache.http.ProtocolException;
 import org.apache.http.RequestLine;
+import org.apache.http.StatusLine;
 import org.apache.http.coyote.IOProcessingListener;
 import org.apache.http.coyote.IOProcessor;
 import org.apache.http.coyote.MalformedURIException;
+import org.apache.http.coyote.NotImplementedException;
 import org.apache.http.coyote.UnsupportedHttpVersionException;
 import org.apache.http.coyote.params.CoyoteParams;
 import org.apache.http.impl.BasicHttpResponse;
 import org.apache.http.impl.ConnectionReuseStrategy;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultResponseStrategy;
+import org.apache.http.impl.ResponseStrategy;
 import org.apache.http.params.HttpParams;
+import org.apache.tomcat.util.http.MimeHeaders;
 
 /**
  * <p>
@@ -126,6 +131,7 @@
                         receiveHttpRequest();
                         prepareCoyoteRequest();
                         callServletContainer();
+                        prepareHttpResponse();
                         sendHttpResponse();
                     	manageHttpConnection();
                 	} catch (HttpException ex) {
@@ -158,7 +164,6 @@
     private void receiveHttpRequest() throws IOException, HttpException {
         this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_NEW);
     	this.httpreq = this.conn.receiveRequest(this.params);
-        this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PARSE);
         this.coyotereq.setStartTime(System.currentTimeMillis());
         LOG.debug("HTTP request received");
     }
@@ -190,7 +195,7 @@
     }
 
     private void prepareCoyoteRequest() throws HttpException {
-        this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PREPARE);
+        this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_PARSE);
         // Convert the request line
         RequestLine reqline = this.httpreq.getRequestLine();
         HttpVersion ver = reqline.getHttpVersion();
@@ -283,6 +288,36 @@
         }
 	}
 
+    private void prepareHttpResponse() {
+        if (this.httpres != null) {
+            return;
+        }
+        HttpVersion ver = this.httpreq.getRequestLine().getHttpVersion();
+        int statuscode = this.coyoteres.getStatus(); 
+        BasicHttpResponse tmp = new BasicHttpResponse(new StatusLine(ver, statuscode, 
+                HttpStatus.getStatusText(statuscode)));
+        MimeHeaders headers = this.coyoteres.getMimeHeaders();
+        int size = headers.size();
+        for (int i = 0; i < size; i++) {
+            String name = headers.getName(i).getString();
+            String value = headers.getValue(i).getString();
+            tmp.addHeader(new Header(name, value, false));
+        }
+        String lang = this.coyoteres.getContentLanguage();
+        if (lang != null) {
+        	tmp.setHeader(new Header("Content-Language", lang, false));
+        }
+        ResponseStrategy responsestrategy = new DefaultResponseStrategy();
+        if (responsestrategy.canHaveEntity(this.httpreq, this.httpres)) {
+        	ContentOutputBuffer buffer = new ContentOutputBuffer();
+        	buffer.setContentLength(this.coyoteres.getContentLengthLong());
+        	buffer.setContentType(this.coyoteres.getContentType());
+        	tmp.setEntity(buffer);
+        	this.coyoteres.setOutputBuffer(buffer);
+        }
+        this.httpres = tmp;
+    }
+
     private void manageHttpConnection() throws IOException {
     	if (this.conn.isOpen()) {
             ConnectionReuseStrategy connreuse = new DefaultConnectionReuseStrategy();
@@ -319,7 +354,21 @@
     }
 	           
 	public void action(final ActionCode actionCode, final Object param) {
-		// Process callbacks from the container
+        if (actionCode == ActionCode.ACTION_COMMIT) {
+        } else if (actionCode == ActionCode.ACTION_ACK) {
+        } else if (actionCode == ActionCode.ACTION_CLIENT_FLUSH) {
+        } else if (actionCode == ActionCode.ACTION_CLOSE) {
+        } else if (actionCode == ActionCode.ACTION_RESET) {
+        } else if (actionCode == ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE) {
+        } else if (actionCode == ActionCode.ACTION_REQ_HOST_ATTRIBUTE) {
+        } else if (actionCode == ActionCode.ACTION_REQ_REMOTEPORT_ATTRIBUTE) {
+        } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_NAME_ATTRIBUTE) {
+        } else if (actionCode == ActionCode.ACTION_REQ_LOCALPORT_ATTRIBUTE) {
+        } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE) {
+        } else {
+        	throw new NotImplementedException("Action code " + actionCode + 
+        			" not implemented"); 
+        }
 	}
     
 }



Mime
View raw message