hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r506560 - in /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol: BufferingHttpServiceHandler.java ThrottlingHttpServiceHandler.java
Date Mon, 12 Feb 2007 18:16:12 GMT
Author: olegk
Date: Mon Feb 12 10:16:11 2007
New Revision: 506560

URL: http://svn.apache.org/viewvc?view=rev&rev=506560
Log:
HTTPCORE-44: Fixed NPE in BufferingHttpServiceHandler and ThrottlingHttpServiceHandler when
request is invalid

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java
    jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.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=506560&r1=506559&r2=506560
==============================================================================
--- 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
Mon Feb 12 10:16:11 2007
@@ -291,9 +291,7 @@
             final HttpException ex) {
 
         HttpRequest request = conn.getHttpRequest();
-        HttpVersion ver = request.getRequestLine().getHttpVersion();
-        HttpResponse response =  this.responseFactory.newHttpResponse(
-                ver, HttpStatus.SC_BAD_REQUEST, conn.getContext());
+        HttpContext context = conn.getContext();
 
         int code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
         if (ex instanceof MethodNotSupportedException) {
@@ -304,7 +302,14 @@
             code = HttpStatus.SC_BAD_REQUEST;
         }
         
-        response.setStatusLine(HttpVersion.HTTP_1_0, 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");

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=506560&r1=506559&r2=506560
==============================================================================
--- 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 Feb 12 10:16:11 2007
@@ -339,11 +339,10 @@
     private HttpResponse handleException(
             final NHttpServerConnection conn,
             final HttpException ex) {
-        HttpRequest request = conn.getHttpRequest();
-        HttpVersion ver = request.getRequestLine().getHttpVersion();
-        HttpResponse response =  this.responseFactory.newHttpResponse(
-                ver, HttpStatus.SC_BAD_REQUEST, conn.getContext());
 
+        HttpRequest request = conn.getHttpRequest();
+        HttpContext context = conn.getContext();
+        
         int code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
         if (ex instanceof MethodNotSupportedException) {
             code = HttpStatus.SC_NOT_IMPLEMENTED;
@@ -352,8 +351,15 @@
         } else if (ex instanceof ProtocolException) {
             code = HttpStatus.SC_BAD_REQUEST;
         }
-        
-        response.setStatusLine(HttpVersion.HTTP_1_0, 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");



Mime
View raw message