You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/05/19 07:27:37 UTC
[1/2] httpcomponents-core git commit: [HTTPCORE-468] [Forced Update!]
Repository: httpcomponents-core
Updated Branches:
refs/heads/master 4195288ed -> 33d26c3c2 (forced update)
[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/c96d1ada
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/c96d1ada
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/c96d1ada
Branch: refs/heads/master
Commit: c96d1adab9840c9f2cb58db1f8364c311a8ec8e6
Parents: 9ec06ec
Author: Gary Gregory <gg...@apache.org>
Authored: Thu May 18 16:18:16 2017 -0700
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri May 19 09:21:02 2017 +0200
----------------------------------------------------------------------
RELEASE_NOTES.txt | 9 +++++++
.../hc/core5/http/impl/io/HttpService.java | 27 ++++++++++++--------
.../http/impl/nio/ServerHttp1StreamHandler.java | 14 ++++++----
3 files changed, 34 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c96d1ada/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 7c1c829..6ea30f9 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,3 +1,12 @@
+Release 5.0-ALPHA4
+-------------------
+
+Changelog
+-------------------
+
+* HTTPCORE-468: Allow HttpAsyncService subclasses to customize the HTTP status code.
+
+
Release 5.0-ALPHA3
-------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c96d1ada/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
index b0efe13..216d1f4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpService.java
@@ -267,23 +267,28 @@ public class HttpService {
* @param response the HTTP response.
*/
protected void handleException(final HttpException ex, final ClassicHttpResponse response) {
+ response.setCode(toStatusCode(ex, response));
+ String message = ex.getMessage();
+ if (message == null) {
+ message = ex.toString();
+ }
+ response.setEntity(new StringEntity(message, ContentType.TEXT_PLAIN));
+ }
+
+ protected int toStatusCode(final Exception ex, final ClassicHttpResponse response) {
+ final int code;
if (ex instanceof MethodNotSupportedException) {
- response.setCode(HttpStatus.SC_NOT_IMPLEMENTED);
+ code = HttpStatus.SC_NOT_IMPLEMENTED;
} else if (ex instanceof UnsupportedHttpVersionException) {
- response.setCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
+ code = HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED;
} else if (ex instanceof NotImplementedException) {
- response.setCode(HttpStatus.SC_NOT_IMPLEMENTED);
+ code = HttpStatus.SC_NOT_IMPLEMENTED;
} else if (ex instanceof ProtocolException) {
- response.setCode(HttpStatus.SC_BAD_REQUEST);
+ code = HttpStatus.SC_BAD_REQUEST;
} else {
- response.setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
- }
- String message = ex.getMessage();
- if (message == null) {
- message = ex.toString();
+ code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
}
- final StringEntity entity = new StringEntity(message, ContentType.TEXT_PLAIN);
- response.setEntity(entity);
+ return code;
}
/**
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c96d1ada/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
index 8bafa4c..7b2b698 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
@@ -206,6 +206,14 @@ class ServerHttp1StreamHandler implements ResourceHolder {
}
AsyncResponseProducer handleException(final Exception ex) {
+ String message = ex.getMessage();
+ if (message == null) {
+ message = ex.toString();
+ }
+ return new BasicResponseProducer(toStatusCode(ex), message);
+ }
+
+ protected int toStatusCode(final Exception ex) {
final int code;
if (ex instanceof MethodNotSupportedException) {
code = HttpStatus.SC_NOT_IMPLEMENTED;
@@ -218,11 +226,7 @@ class ServerHttp1StreamHandler implements ResourceHolder {
} else {
code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
}
- String message = ex.getMessage();
- if (message == null) {
- message = ex.toString();
- }
- return new BasicResponseProducer(code, message);
+ return code;
}
void consumeHeader(final HttpRequest request, final boolean requestEndStream) throws HttpException, IOException {
[2/2] httpcomponents-core git commit: Fix typos in examples.
Posted by ol...@apache.org.
Fix typos in examples.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/33d26c3c
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/33d26c3c
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/33d26c3c
Branch: refs/heads/master
Commit: 33d26c3c2a05286682905991d63f6bb51d6bea8d
Parents: c96d1ad
Author: Gary Gregory <gg...@apache.org>
Authored: Thu May 18 17:06:13 2017 -0700
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri May 19 09:21:29 2017 +0200
----------------------------------------------------------------------
.../org/apache/hc/core5/http/examples/AsyncFileServerExample.java | 2 +-
.../apache/hc/core5/http/examples/ClassicFileServerExample.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/33d26c3c/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
index 610c959..b6d74ab 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
@@ -151,7 +151,7 @@ public class AsyncFileServerExample {
System.out.println("File " + file.getPath() + " not found");
responseTrigger.submitResponse(new BasicResponseProducer(
HttpStatus.SC_NOT_FOUND,
- "<html><body><h1>File" + file.getPath() +
+ "<html><body><h1>File " + file.getPath() +
" not found</h1></body></html>",
ContentType.TEXT_HTML));
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/33d26c3c/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
index 1720658..4706bfc 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
@@ -162,7 +162,7 @@ public class ClassicFileServerExample {
response.setCode(HttpStatus.SC_NOT_FOUND);
StringEntity outgoingEntity = new StringEntity(
- "<html><body><h1>File" + file.getPath() +
+ "<html><body><h1>File " + file.getPath() +
" not found</h1></body></html>",
ContentType.create("text/html", "UTF-8"));
response.setEntity(outgoingEntity);