Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6E535200C7D for ; Tue, 16 May 2017 11:14:28 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 67C9A160BAC; Tue, 16 May 2017 09:14:28 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AEC36160B9D for ; Tue, 16 May 2017 11:14:27 +0200 (CEST) Received: (qmail 99912 invoked by uid 500); 16 May 2017 09:14:26 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 99903 invoked by uid 99); 16 May 2017 09:14:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 May 2017 09:14:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2DF2BDFC2E; Tue, 16 May 2017 09:14:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ggregory@apache.org To: commits@hc.apache.org Message-Id: <6de9a74182c04c31af09d29aae047162@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: httpcomponents-core git commit: [HTTPCORE-468] Date: Tue, 16 May 2017 09:14:26 +0000 (UTC) archived-at: Tue, 16 May 2017 09:14:28 -0000 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 Authored: Tue May 16 02:14:23 2017 -0700 Committer: Gary Gregory 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 +* HTTPCORE-468: Allow HttpAsyncService subclasses to customize the HTTP status code. + Contributed by Gary Gregory + 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; } /**