hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject httpcomponents-core git commit: [HTTPCORE-468]
Date Tue, 16 May 2017 09:14:26 GMT
Repository: httpcomponents-core
Updated Branches:
  refs/heads/4.4.x 40580bd2d -> d038f4ba0


[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/d038f4ba
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/d038f4ba
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/d038f4ba

Branch: refs/heads/4.4.x
Commit: d038f4ba0e1a35c4b24e8406db438f521323649d
Parents: 40580bd
Author: Gary Gregory <ggregory@apache.org>
Authored: Tue May 16 02:14:23 2017 -0700
Committer: Gary Gregory <ggregory@apache.org>
Committed: Tue May 16 02:14:23 2017 -0700

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               |  3 +++
 .../http/nio/protocol/HttpAsyncService.java     | 20 ++++++++++++--------
 2 files changed, 15 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d038f4ba/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 94e4c5c..272c2ba 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -27,6 +27,9 @@ Changelog
 * HTTPCORE-466: Round out the SslContextBuilder by adding missing APIs.
   Contributed by Gary Gregory <ggregory at apache.org>
 
+* HTTPCORE-468: Allow HttpAsyncService subclasses to customize the HTTP status code.
+  Contributed by Gary Gregory <ggregory at apache.org>
+
 
 Release 4.4.6
 -------------------

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d038f4ba/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;
     }
 
     /**


Mime
View raw message