[jira] [Commented] (HTTPCORE-468) Allow HttpAsyncService subclasses to customize the HTTP status code

2017-05-19 Thread Oleg Kalnichevski (JIRA)

[ 
https://issues.apache.org/jira/browse/HTTPCORE-468?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16017016#comment-16017016
 ] 

Oleg Kalnichevski commented on HTTPCORE-468:


This is the reason I stopped changing release notes at the same time with 
functional changes. They tend to cause unnecessary conflicts when merging or 
cherry-picking.

Oleg

> Allow HttpAsyncService subclasses to customize the HTTP status code
> ---
>
> Key: HTTPCORE-468
> URL: https://issues.apache.org/jira/browse/HTTPCORE-468
> Project: HttpComponents HttpCore
>  Issue Type: Improvement
>  Components: HttpCore NIO
>Affects Versions: 4.4.6
>Reporter: Gary Gregory
>Assignee: Gary Gregory
> Fix For: 4.4.7, 5.0-alpha4
>
>
> As a developer, I would like to allow my {{HttpAsyncService}} subclasses to 
> customize the HTTP status code. I propose to refactor the method 
> {{org.apache.http.nio.protocol.HttpAsyncService.handleException(Exception, 
> HttpContext)}} like so:
> {noformat}
> 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 @@
>  
>  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 @@
>  } 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;
>  }
>  
>  /**
> {noformat}
> As in {{dev/4.4.x/HTTPCORE-468}}.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[jira] [Commented] (HTTPCORE-468) Allow HttpAsyncService subclasses to customize the HTTP status code

2017-05-18 Thread Gary Gregory (JIRA)

[ 
https://issues.apache.org/jira/browse/HTTPCORE-468?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16016651#comment-16016651
 ] 

Gary Gregory commented on HTTPCORE-468:
---

Merged to master.

[not sure why this ended up in two commits instead of one, despite my fiddling 
with git and the command line and in Egit]
commit 8374fec658d42a321a671a8c89660d02203fe9f8 for the main work.
commit 28cfcce90ac732b1f6a4d5d7176330c89d628ed3 for the release notes

> Allow HttpAsyncService subclasses to customize the HTTP status code
> ---
>
> Key: HTTPCORE-468
> URL: https://issues.apache.org/jira/browse/HTTPCORE-468
> Project: HttpComponents HttpCore
>  Issue Type: Improvement
>  Components: HttpCore NIO
>Affects Versions: 4.4.6
>Reporter: Gary Gregory
>Assignee: Gary Gregory
> Fix For: 4.4.7
>
>
> As a developer, I would like to allow my {{HttpAsyncService}} subclasses to 
> customize the HTTP status code. I propose to refactor the method 
> {{org.apache.http.nio.protocol.HttpAsyncService.handleException(Exception, 
> HttpContext)}} like so:
> {noformat}
> 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 @@
>  
>  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 @@
>  } 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;
>  }
>  
>  /**
> {noformat}
> As in {{dev/4.4.x/HTTPCORE-468}}.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[jira] [Commented] (HTTPCORE-468) Allow HttpAsyncService subclasses to customize the HTTP status code

2017-05-18 Thread Oleg Kalnichevski (JIRA)

[ 
https://issues.apache.org/jira/browse/HTTPCORE-468?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16015360#comment-16015360
 ] 

Oleg Kalnichevski commented on HTTPCORE-468:


Looks good, other that copying of release notes from the previous release.

Oleg

> Allow HttpAsyncService subclasses to customize the HTTP status code
> ---
>
> Key: HTTPCORE-468
> URL: https://issues.apache.org/jira/browse/HTTPCORE-468
> Project: HttpComponents HttpCore
>  Issue Type: Improvement
>  Components: HttpCore NIO
>Affects Versions: 4.4.6
>Reporter: Gary Gregory
>Assignee: Gary Gregory
> Fix For: 4.4.7
>
>
> As a developer, I would like to allow my {{HttpAsyncService}} subclasses to 
> customize the HTTP status code. I propose to refactor the method 
> {{org.apache.http.nio.protocol.HttpAsyncService.handleException(Exception, 
> HttpContext)}} like so:
> {noformat}
> 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 @@
>  
>  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 @@
>  } 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;
>  }
>  
>  /**
> {noformat}
> As in {{dev/4.4.x/HTTPCORE-468}}.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org



[jira] [Commented] (HTTPCORE-468) Allow HttpAsyncService subclasses to customize the HTTP status code

2017-05-17 Thread Gary Gregory (JIRA)

[ 
https://issues.apache.org/jira/browse/HTTPCORE-468?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16015264#comment-16015264
 ] 

Gary Gregory commented on HTTPCORE-468:
---

Hi All,

Ported to the branch {{dev/5.0.x/HTTPCORE-468}}. Please review.

Thank you,
Gary

> Allow HttpAsyncService subclasses to customize the HTTP status code
> ---
>
> Key: HTTPCORE-468
> URL: https://issues.apache.org/jira/browse/HTTPCORE-468
> Project: HttpComponents HttpCore
>  Issue Type: Improvement
>  Components: HttpCore NIO
>Affects Versions: 4.4.6
>Reporter: Gary Gregory
>Assignee: Gary Gregory
> Fix For: 4.4.7
>
>
> As a developer, I would like to allow my {{HttpAsyncService}} subclasses to 
> customize the HTTP status code. I propose to refactor the method 
> {{org.apache.http.nio.protocol.HttpAsyncService.handleException(Exception, 
> HttpContext)}} like so:
> {noformat}
> 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 @@
>  
>  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 @@
>  } 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;
>  }
>  
>  /**
> {noformat}
> As in {{dev/4.4.x/HTTPCORE-468}}.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

-
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org