hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r544108 - in /jakarta/httpcomponents/httpcore/trunk: module-main/src/main/java/org/apache/http/protocol/HttpService.java module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
Date Mon, 04 Jun 2007 09:46:36 GMT
Author: olegk
Date: Mon Jun  4 02:45:55 2007
New Revision: 544108

URL: http://svn.apache.org/viewvc?view=rev&rev=544108
Log:
Cleanups in the HTTP service protocol code; NIO and classic I/O HTTP service implementations
made more consistent

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpService.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpService.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpService.java?view=diff&rev=544108&r1=544107&r2=544108
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpService.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpService.java
Mon Jun  4 02:45:55 2007
@@ -140,11 +140,8 @@
                 ver = HttpVersion.HTTP_1_1;
             }
 
-            boolean receiveEntity = false;
-            boolean runService = true;
-
             if (request instanceof HttpEntityEnclosingRequest) {
-                receiveEntity = true;
+
                 if (((HttpEntityEnclosingRequest) request).expectContinue()) {
                     response = this.responseFactory.newHttpResponse(ver, 
                             HttpStatus.SC_CONTINUE, context);
@@ -166,33 +163,26 @@
                         conn.sendResponseHeader(response);
                         conn.flush();
                         response = null;
-                    } else {
-                        // The request does not meet the server expections
-                        runService = false;
-                        receiveEntity = false;
+                        conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
                     }
+                } else {
+                    conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
                 }
             }
 
-            if (receiveEntity) {
-                conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
-            }
-
             if (response == null) {
                 response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_OK, context);
                 HttpParamsLinker.link(request, this.params);
-            }
-            
-            if (runService) {
+
                 context.setAttribute(HttpExecutionContext.HTTP_REQUEST, request);
                 context.setAttribute(HttpExecutionContext.HTTP_RESPONSE, response);
 
                 this.processor.process(request, context);
                 doService(request, response, context);
             }
-
-            if (receiveEntity) {
-                // Make sure the request content is fully consumed
+            
+            // Make sure the request content is fully consumed
+            if (request instanceof HttpEntityEnclosingRequest) {
                 HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
                 if (entity != null) {
                     entity.consumeContent();

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java?view=diff&rev=544108&r1=544107&r2=544108
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
Mon Jun  4 02:45:55 2007
@@ -392,44 +392,20 @@
         }
     }
     
-    private HttpResponse handleException(
-            final ServerConnState connState,
-            final NHttpServerConnection conn,
-            final HttpException ex,
-            final HttpContext context) throws HttpException, IOException {
-
-        HttpRequest request = connState.getRequest();
-
-        context.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn);
-        context.setAttribute(HttpExecutionContext.HTTP_REQUEST, request);
-        
-        HttpVersion ver;
-        if (request != null) {
-            ver = request.getRequestLine().getHttpVersion(); 
-        } else {
-            ver = HttpVersion.HTTP_1_0;
-        }
-        int code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
+    private void handleException(final HttpException ex, final HttpResponse response) {
         if (ex instanceof MethodNotSupportedException) {
-            code = HttpStatus.SC_NOT_IMPLEMENTED;
+            response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
         } else if (ex instanceof UnsupportedHttpVersionException) {
-            code = HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED;
+            response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
         } else if (ex instanceof ProtocolException) {
-            code = HttpStatus.SC_BAD_REQUEST;
+            response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
+        } else {
+            response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
         }
-        
-        HttpResponse response =  this.responseFactory.newHttpResponse(
-                ver, 
-                code, 
-                context);
-
-        HttpParamsLinker.link(response, this.params);
-        
         byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage());
         ByteArrayEntity entity = new ByteArrayEntity(msg);
         entity.setContentType("text/plain; charset=US-ASCII");
         response.setEntity(entity);
-        return response;
     }
     
     private void handleRequest(
@@ -467,7 +443,10 @@
                     try {
                         this.expectationVerifier.verify(request, response, context);
                     } catch (HttpException ex) {
-                        response = handleException(connState, conn, ex ,context);
+                        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0,

+                                HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
+                        HttpParamsLinker.link(request, this.params);
+                        handleException(ex, response);
                     }
                 }
             
@@ -523,7 +502,10 @@
                 }
 
             } catch (HttpException ex) {
-                response = handleException(connState, conn, ex ,context);
+                response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, 
+                        HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
+                HttpParamsLinker.link(request, this.params);
+                handleException(ex, response);
             }
         }
 



Mime
View raw message