hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r509010 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
Date Sun, 18 Feb 2007 21:33:24 GMT
Author: olegk
Date: Sun Feb 18 13:33:23 2007
New Revision: 509010

URL: http://svn.apache.org/viewvc?view=rev&rev=509010
Log:
HTTPCORE-42: BufferingHttpServiceHandler can now correctly handle excpetion failures when
the expectation verifier returns a non 1xx response

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

Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java?view=diff&rev=509010&r1=509009&r2=509010
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
Sun Feb 18 13:33:23 2007
@@ -164,17 +164,38 @@
             ver = HttpVersion.HTTP_1_1;
         }
 
+        HttpResponse response;
+        
         try {
 
             if (request instanceof HttpEntityEnclosingRequest) {
                 if (((HttpEntityEnclosingRequest) request).expectContinue()) {
-                    HttpResponse ack = this.responseFactory.newHttpResponse(
+                    response = this.responseFactory.newHttpResponse(
                             ver, HttpStatus.SC_CONTINUE, context);
-                    ack.getParams().setDefaults(this.params);
+                    response.getParams().setDefaults(this.params);
+                    
                     if (this.expectationVerifier != null) {
-                        this.expectationVerifier.verify(request, ack, context);
+                        try {
+                            this.expectationVerifier.verify(request, response, context);
+                        } catch (HttpException ex) {
+                            response = this.responseFactory.newHttpResponse(
+                                    HttpVersion.HTTP_1_0, 
+                                    HttpStatus.SC_INTERNAL_SERVER_ERROR, 
+                                    context);
+                            response.getParams().setDefaults(this.params);
+                            handleException(ex, response);
+                        }
+                    }
+                    
+                    if (response.getStatusLine().getStatusCode() < 200) {
+                        // Send 1xx response indicating the server expections
+                        // have been met
+                        conn.submitResponse(response);
+                    } else {
+                        // The request does not meet the server expections
+                        sendResponse(conn, response);
+                        return;
                     }
-                    conn.submitResponse(ack);
                 }
                 // Request content is expected. 
                 // Wait until the request content is fully received
@@ -209,10 +230,13 @@
     }
 
     public void exception(final NHttpServerConnection conn, final HttpException httpex) {
+        HttpContext context = conn.getContext();
         try {
-            
-            HttpResponse response = handleException(conn, httpex);
-            commitResponse(conn, response);
+            HttpResponse response = this.responseFactory.newHttpResponse(
+                    HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
+            response.getParams().setDefaults(this.params);
+            handleException(httpex, response);
+            sendResponse(conn, response);
             
         } catch (IOException ex) {
             shutdownConnection(conn);
@@ -323,13 +347,7 @@
         }
     }
     
-    private HttpResponse handleException(
-            final NHttpServerConnection conn,
-            final HttpException ex) {
-
-        HttpRequest request = conn.getHttpRequest();
-        HttpContext context = conn.getContext();
-
+    private void handleException(final HttpException ex, final HttpResponse response) {
         int code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
         if (ex instanceof MethodNotSupportedException) {
             code = HttpStatus.SC_NOT_IMPLEMENTED;
@@ -338,20 +356,12 @@
         } else if (ex instanceof ProtocolException) {
             code = HttpStatus.SC_BAD_REQUEST;
         }
+        response.setStatusCode(code);
         
-        HttpVersion ver;
-        if (request != null) {
-            ver = request.getRequestLine().getHttpVersion(); 
-        } else {
-            ver = HttpVersion.HTTP_1_0;
-        }
-        HttpResponse response =  this.responseFactory.newHttpResponse(ver, code, context);
-
         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 processRequest(
@@ -389,13 +399,16 @@
             }
             
         } catch (HttpException ex) {
-            response = handleException(conn, ex);
+            response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, 
+                    HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
+            response.getParams().setDefaults(this.params);
+            handleException(ex, response);
         }
 
-        commitResponse(conn, response);
+        sendResponse(conn, response);
     }
 
-    private void commitResponse(
+    private void sendResponse(
             final NHttpServerConnection conn,
             final HttpResponse response) throws IOException, HttpException {
 



Mime
View raw message