You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2017/05/16 01:55:56 UTC

httpcomponents-core git commit: [HTTPCORE-468]

Repository: httpcomponents-core
Updated Branches:
  refs/heads/dev/4.4.x/HTTPCORE-468 [created] 5bf6e9196


[HTTPCORE-468]

Allow HttpAsyncService subclasses to customize the HTTP status code

Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/5bf6e919
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/5bf6e919
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/5bf6e919

Branch: refs/heads/dev/4.4.x/HTTPCORE-468
Commit: 5bf6e9196007df74387d09b4255e3c0fd57caf2d
Parents: 839f7ae
Author: Gary Gregory <gg...@apache.org>
Authored: Mon May 15 18:55:49 2017 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Mon May 15 18:55:49 2017 -0700

----------------------------------------------------------------------
 .../http/nio/protocol/HttpAsyncService.java     | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/5bf6e919/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
index f941399..789b304 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
@@ -614,6 +614,17 @@ public class HttpAsyncService implements NHttpServerEventHandler {
 
     protected HttpAsyncResponseProducer handleException(
             final Exception ex, final HttpContext context) {
+        String message = ex.getMessage();
+        if (message == null) {
+            message = ex.toString();
+        }
+        final HttpResponse response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_1,
+                toStatusCode(ex, context), context);
+        return new ErrorResponseProducer(response,
+                new NStringEntity(message, ContentType.DEFAULT_TEXT), false);
+    }
+
+    protected int toStatusCode(final Exception ex, final HttpContext context) {
         final int code;
         if (ex instanceof MethodNotSupportedException) {
             code = HttpStatus.SC_NOT_IMPLEMENTED;
@@ -624,14 +635,7 @@ public class HttpAsyncService implements NHttpServerEventHandler {
         } else {
             code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
         }
-        String message = ex.getMessage();
-        if (message == null) {
-            message = ex.toString();
-        }
-        final HttpResponse response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_1,
-                code, context);
-        return new ErrorResponseProducer(response,
-                new NStringEntity(message, ContentType.DEFAULT_TEXT), false);
+        return code;
     }
 
     /**