hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r227056 - in /jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote: DefaultHttpConnectionManager.java HttpConnectionProcessor.java HttpProtocolHandler.java HttpService.java
Date Tue, 02 Aug 2005 18:17:54 GMT
Author: olegk
Date: Tue Aug  2 11:17:45 2005
New Revision: 227056

URL: http://svn.apache.org/viewcvs?rev=227056&view=rev
Log:
Added HttpService interface

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

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/DefaultHttpConnectionManager.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/DefaultHttpConnectionManager.java?rev=227056&r1=227055&r2=227056&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/DefaultHttpConnectionManager.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/DefaultHttpConnectionManager.java
Tue Aug  2 11:17:45 2005
@@ -37,7 +37,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.HttpServerConnection;
-import org.apache.http.params.HttpParams;
 
 /**
  * <p>
@@ -50,20 +49,22 @@
 
     private static Log LOG = LogFactory.getLog(DefaultHttpConnectionManager.class);
     
-    private final HttpParams params;
     private final Executor executor;
+    private final HttpService service;
     private final List<IOProcessor> processors;
     
-    public DefaultHttpConnectionManager(final HttpParams params, final Executor executor)
{
+    public DefaultHttpConnectionManager(
+            final HttpService service,
+            final Executor executor) {
         super();
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
+        if (service == null) {
+            throw new IllegalArgumentException("Http service may not be null");
         }
         if (executor == null) {
             throw new IllegalArgumentException("Executor may not be null");
         }
-        this.params = params;
         this.executor = executor;
+        this.service = service;
         this.processors = new LinkedList<IOProcessor>();
     }
 
@@ -107,7 +108,8 @@
             }
             
         };
-        HttpConnectionProcessor processor = new HttpConnectionProcessor(conn, this.params,
listener);
+        HttpConnectionProcessor processor = new HttpConnectionProcessor(
+                conn, this.service, listener);
         addProcessor(processor);
         this.executor.execute(processor);
     }

Modified: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpConnectionProcessor.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpConnectionProcessor.java?rev=227056&r1=227055&r2=227056&view=diff
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpConnectionProcessor.java
(original)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpConnectionProcessor.java
Tue Aug  2 11:17:45 2005
@@ -35,23 +35,13 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.ConnectionClosedException;
-import org.apache.http.Header;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
-import org.apache.http.HttpMutableResponse;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpServerConnection;
-import org.apache.http.HttpStatus;
-import org.apache.http.MethodNotSupportedException;
-import org.apache.http.ProtocolException;
-import org.apache.http.entity.EntityConsumer;
-import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.BasicHttpResponse;
 import org.apache.http.impl.ConnectionReuseStrategy;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.DefaultHttpParams;
-import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 
 /**
@@ -68,26 +58,26 @@
     private volatile boolean destroyed = false;
     
     private final HttpServerConnection conn;
-    private final HttpParams params;
+    private final HttpService service;
     private final IOProcessingListener listener;
+    private final HttpParams params;
     
     public HttpConnectionProcessor(
             final HttpServerConnection conn,
-            final HttpParams parentparams,
+    		final HttpService service,
             final IOProcessingListener listener) {
     	super();
         if (conn == null) {
             throw new IllegalArgumentException("HTTP connection may not be null");
         }
+        if (service == null) {
+            throw new IllegalArgumentException("HTTP service may not be null");
+        }
         this.conn = conn;
-        this.params = new DefaultHttpParams();
-        this.params.setDefaults(parentparams);
-        this.params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 5000);
+        this.service = service;
         this.listener = listener;
-    }
-
-    public HttpConnectionProcessor(final HttpServerConnection conn, final HttpParams params)
{
-        this(conn, params, null);
+        this.params = new DefaultHttpParams();
+        this.params.setDefaults(service.getParams());
     }
 
     public void run() {
@@ -119,13 +109,13 @@
         try {
             HttpRequest request = this.conn.receiveRequest(this.params);
             LOG.debug("HTTP request received");
-            handleRequest(request, response);
+            this.service.process(request, response);
         } catch (ConnectionClosedException ex) {
         	LOG.debug("Client closed connection");
             this.conn.close();
             return;
         } catch (HttpException ex) {
-            handleException(ex, response);
+            this.service.process(ex, response);
         } catch (IOException ex) {
         	LOG.warn("I/O error receiving HTTP request", ex);
             this.conn.close();
@@ -167,83 +157,5 @@
     public boolean isDestroyed() {
         return this.destroyed;
     }
-	    
-    private void handleException(final HttpException ex, final HttpMutableResponse response)
{
-        if (ex instanceof MethodNotSupportedException) {
-            response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
-        } else if (ex instanceof ProtocolException) {
-            response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
-        } else {
-            response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
-        }
-        response.setHeader(new Header("Server", "Jakarta HttpCommons"));
-        response.setHeader(new Header("Connection", "Close"));
-    }
-    
-    public void handleRequest(final HttpRequest request,
-			final HttpMutableResponse response) throws IOException {
-		StringBuffer buffer = new StringBuffer();
-		buffer.append("<html>");
-		buffer.append("<body>");
-		buffer.append("<p>Request method: ");
-		buffer.append(request.getRequestLine().getMethod());
-		buffer.append("</p>");
-		buffer.append("<p>Request URI: ");
-		buffer.append(request.getRequestLine().getUri());
-		buffer.append("</p>");
-		buffer.append("<p>Request Version: ");
-		buffer.append(request.getRequestLine().getHttpVersion());
-		buffer.append("</p>");
-		if (request instanceof HttpEntityEnclosingRequest) {
-			HttpEntity entity = ((HttpEntityEnclosingRequest) request)
-					.getEntity();
-			buffer.append("<p>Content Type: ");
-			buffer.append(entity.getContentType());
-			buffer.append("</p>");
-			buffer.append("<p>Content Chunk-coded: ");
-			buffer.append(entity.isChunked());
-			buffer.append("</p>");
-			EntityConsumer consume = new EntityConsumer(
-					(HttpEntityEnclosingRequest) request);
-			if (entity.getContentType() != null
-					&& entity.getContentType().toLowerCase()
-							.startsWith("text/")) {
-				buffer.append("<p>");
-				buffer.append(consume.asString());
-				buffer.append("</p>");
-			} else {
-				byte[] raw = consume.asByteArray();
-				buffer.append("<p>");
-				for (int i = 0; i < raw.length; i++) {
-					buffer.append(Integer.toHexString(raw[i]).toLowerCase());
-					if (i % 20 == 19) {
-						buffer.append("<br>");
-					} else {
-						buffer.append(" ");
-					}
-				}
-				buffer.append("</p>");
-			}
-		}
-		buffer.append("</body>");
-		buffer.append("</html>");
-		StringEntity body = new StringEntity(buffer.toString());
-		body.setContentType("text/html; charset=UTF-8");
-
-		response.setStatusCode(HttpStatus.SC_OK);
-		response.setHeader(new Header("Server", "Jakarta HttpCommons"));
-		response.setHeader(new Header("Connection", "Keep-Alive"));
-		if (body.isChunked() || body.getContentLength() < 0) {
-			response.setHeader(new Header("Transfer-Encoding", "chunked"));
-		} else {
-			response.setHeader(new Header("Content-Length", Long.toString(body
-					.getContentLength())));
-		}
-		if (body.getContentType() != null) {
-			response
-					.setHeader(new Header("Content-Type", body.getContentType()));
-		}
-		response.setEntity(body);
-	}
-       
+	           
 }

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=227056&r1=227055&r2=227056&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
Tue Aug  2 11:17:45 2005
@@ -107,14 +107,20 @@
 	}
 	
 	public void init() throws Exception {
-        this.requestExecutor = new ThreadPoolExecutor(this.minThreads, this.maxThreads,
+        this.requestExecutor = new ThreadPoolExecutor(
+                this.minThreads, this.maxThreads,
                 0L, TimeUnit.MILLISECONDS,
                 new LinkedBlockingQueue<Runnable>());
-        this.connmanager = new DefaultHttpConnectionManager(this.params, this.requestExecutor);

-        this.listenerExecutor = new ThreadPoolExecutor(1, 1,
+        this.connmanager = new DefaultHttpConnectionManager(
+                new CoyoteHttpService(this.adapter, this.params), 
+                this.requestExecutor); 
+        this.listenerExecutor = new ThreadPoolExecutor(
+                1, 1,
                 0L, TimeUnit.MILLISECONDS,
                 new LinkedBlockingQueue<Runnable>());
-        this.listener = new ConnectionListener(this.port, this.connmanager);
+        this.listener = new ConnectionListener(
+                this.port, 
+                this.connmanager);
 	}
 
     public void destroy() throws Exception {

Added: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpService.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpService.java?rev=227056&view=auto
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpService.java
(added)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/HttpService.java
Tue Aug  2 11:17:45 2005
@@ -0,0 +1,55 @@
+/*
+ * $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;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpMutableResponse;
+import org.apache.http.HttpRequest;
+import org.apache.http.params.HttpParams;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ */
+public interface HttpService {
+
+	void process(HttpRequest request, HttpMutableResponse respose) 
+		throws IOException, HttpException;
+
+	void process(HttpException ex, HttpMutableResponse respose);
+    
+    HttpParams getParams();
+	
+}

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

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

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



Mime
View raw message