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 2018/08/21 15:01:34 UTC
[23/32] httpcomponents-core git commit: Better formatting of
exception message.
Better formatting of exception message.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/f5a28b9f
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/f5a28b9f
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/f5a28b9f
Branch: refs/heads/api_javadocs
Commit: f5a28b9f237f07dcb8b952d79b59e5da8a2b6c87
Parents: 2e5d72b
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Aug 13 23:43:46 2018 -0600
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Aug 14 09:29:13 2018 +0200
----------------------------------------------------------------------
.../core5/http2/impl/DefaultH2RequestConverter.java | 16 ++++++++--------
.../http2/impl/DefaultH2ResponseConverter.java | 14 +++++++-------
.../org/apache/hc/core5/http/HttpException.java | 12 ++++++++++++
.../core5/http/MalformedChunkCodingException.java | 12 ++++++++++++
.../org/apache/hc/core5/http/ProtocolException.java | 12 ++++++++++++
.../hc/core5/http/TruncatedChunkException.java | 2 +-
.../http/impl/DefaultContentLengthStrategy.java | 6 +++---
.../apache/hc/core5/http/message/HeaderGroup.java | 2 +-
8 files changed, 56 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f5a28b9f/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java
index 0c6156b..69384db 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2RequestConverter.java
@@ -71,7 +71,7 @@ public final class DefaultH2RequestConverter implements H2MessageConverter<HttpR
for (int n = 0; n < name.length(); n++) {
final char ch = name.charAt(n);
if (Character.isAlphabetic(ch) && !Character.isLowerCase(ch)) {
- throw new ProtocolException("Header name '" + name + "' is invalid (header name contains uppercase characters)");
+ throw new ProtocolException("Header name '%s' is invalid (header name contains uppercase characters)", name);
}
}
@@ -82,27 +82,27 @@ public final class DefaultH2RequestConverter implements H2MessageConverter<HttpR
if (name.equals(H2PseudoRequestHeaders.METHOD)) {
if (method != null) {
- throw new ProtocolException("Multiple '" + name + "' request headers are illegal");
+ throw new ProtocolException("Multiple '%s' request headers are illegal", name);
}
method = value;
} else if (name.equals(H2PseudoRequestHeaders.SCHEME)) {
if (scheme != null) {
- throw new ProtocolException("Multiple '" + name + "' request headers are illegal");
+ throw new ProtocolException("Multiple '%s' request headers are illegal", name);
}
scheme = value;
} else if (name.equals(H2PseudoRequestHeaders.PATH)) {
if (path != null) {
- throw new ProtocolException("Multiple '" + name + "' request headers are illegal");
+ throw new ProtocolException("Multiple '%s' request headers are illegal", name);
}
path = value;
} else if (name.equals(H2PseudoRequestHeaders.AUTHORITY)) {
authority = value;
} else {
- throw new ProtocolException("Unsupported request header '" + name + "'");
+ throw new ProtocolException("Unsupported request header '%s'", name);
}
} else {
if (name.equalsIgnoreCase(HttpHeaders.CONNECTION)) {
- throw new ProtocolException("Header '" + header.getName() + ": " + header.getValue() + "' is illegal for HTTP/2 messages");
+ throw new ProtocolException("Header '%s: %s' is illegal for HTTP/2 messages", header.getName(), header.getValue());
}
messageHeaders.add(header);
}
@@ -182,10 +182,10 @@ public final class DefaultH2RequestConverter implements H2MessageConverter<HttpR
final String name = header.getName();
final String value = header.getValue();
if (name.startsWith(":")) {
- throw new ProtocolException("Header name '" + name + "' is invalid");
+ throw new ProtocolException("Header name '%s' is invalid", name);
}
if (name.equalsIgnoreCase(HttpHeaders.CONNECTION)) {
- throw new ProtocolException("Header '" + name + ": " + value + "' is illegal for HTTP/2 messages");
+ throw new ProtocolException("Header '%s: %s' is illegal for HTTP/2 messages", name, value);
}
headers.add(new BasicHeader(name.toLowerCase(Locale.ROOT), value));
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f5a28b9f/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2ResponseConverter.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2ResponseConverter.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2ResponseConverter.java
index 17b979d..2616ef6 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2ResponseConverter.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/DefaultH2ResponseConverter.java
@@ -65,7 +65,7 @@ public class DefaultH2ResponseConverter implements H2MessageConverter<HttpRespon
for (int n = 0; n < name.length(); n++) {
final char ch = name.charAt(n);
if (Character.isAlphabetic(ch) && !Character.isLowerCase(ch)) {
- throw new ProtocolException("Header name '" + name + "' is invalid (header name contains uppercase characters)");
+ throw new ProtocolException("Header name '%s' is invalid (header name contains uppercase characters)", name);
}
}
@@ -75,15 +75,15 @@ public class DefaultH2ResponseConverter implements H2MessageConverter<HttpRespon
}
if (name.equals(H2PseudoResponseHeaders.STATUS)) {
if (statusText != null) {
- throw new ProtocolException("Multiple '" + name + "' response headers are illegal");
+ throw new ProtocolException("Multiple '%s' response headers are illegal", name);
}
statusText = value;
} else {
- throw new ProtocolException("Unsupported response header '" + name + "'");
+ throw new ProtocolException("Unsupported response header '%s'", name);
}
} else {
if (name.equalsIgnoreCase(HttpHeaders.CONNECTION)) {
- throw new ProtocolException("Header '" + header.getName() + ": " + header.getValue() + "' is illegal for HTTP/2 messages");
+ throw new ProtocolException("Header '%s: %s' is illegal for HTTP/2 messages", header.getName(), header.getValue());
}
messageHeaders.add(header);
}
@@ -111,7 +111,7 @@ public class DefaultH2ResponseConverter implements H2MessageConverter<HttpRespon
public List<Header> convert(final HttpResponse message) throws HttpException {
final int code = message.getCode();
if (code < 100 || code >= 600) {
- throw new ProtocolException("Response status " + code + " is invalid");
+ throw new ProtocolException("Response status %s is invalid", code);
}
final List<Header> headers = new ArrayList<>();
headers.add(new BasicHeader(H2PseudoResponseHeaders.STATUS, Integer.toString(code), false));
@@ -121,10 +121,10 @@ public class DefaultH2ResponseConverter implements H2MessageConverter<HttpRespon
final String name = header.getName();
final String value = header.getValue();
if (name.startsWith(":")) {
- throw new ProtocolException("Header name '" + name + "' is invalid");
+ throw new ProtocolException("Header name '%s' is invalid", name);
}
if (name.equalsIgnoreCase(HttpHeaders.CONNECTION)) {
- throw new ProtocolException("Header '" + name + ": " + value + "' is illegal for HTTP/2 messages");
+ throw new ProtocolException("Header '%s: %s' is illegal for HTTP/2 messages", name, value);
}
headers.add(new BasicHeader(name.toLowerCase(Locale.ROOT), value));
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f5a28b9f/httpcore5/src/main/java/org/apache/hc/core5/http/HttpException.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpException.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpException.java
index 207f72e..d39bc15 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpException.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpException.java
@@ -91,6 +91,18 @@ public class HttpException extends Exception {
}
/**
+ * Constructs a new HttpException with the specified detail message.
+ *
+ * @param format The exception detail message format; see {@link String#format(String, Object...)}.
+ * @param args The exception detail message arguments; see {@link String#format(String, Object...)}.
+ *
+ * @since 5.0
+ */
+ public HttpException(final String format, final Object... args) {
+ super(HttpException.clean(String.format(format, args)));
+ }
+
+ /**
* Creates a new HttpException with the specified detail message and cause.
*
* @param message the exception detail message
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f5a28b9f/httpcore5/src/main/java/org/apache/hc/core5/http/MalformedChunkCodingException.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/MalformedChunkCodingException.java b/httpcore5/src/main/java/org/apache/hc/core5/http/MalformedChunkCodingException.java
index 4ad32d2..3b37182 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/MalformedChunkCodingException.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/MalformedChunkCodingException.java
@@ -54,4 +54,16 @@ public class MalformedChunkCodingException extends IOException {
super(message);
}
+ /**
+ * Constructs a new MalformedChunkCodingException with the specified detail message.
+ *
+ * @param format The exception detail message format; see {@link String#format(String, Object...)}.
+ * @param args The exception detail message arguments; see {@link String#format(String, Object...)}.
+ *
+ * @since 5.0
+ */
+ public MalformedChunkCodingException(final String format, final Object... args) {
+ super(HttpException.clean(String.format(format, args)));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f5a28b9f/httpcore5/src/main/java/org/apache/hc/core5/http/ProtocolException.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/ProtocolException.java b/httpcore5/src/main/java/org/apache/hc/core5/http/ProtocolException.java
index a916042..8593860 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/ProtocolException.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/ProtocolException.java
@@ -54,6 +54,18 @@ public class ProtocolException extends HttpException {
}
/**
+ * Constructs a new ProtocolException with the specified detail message.
+ *
+ * @param format The exception detail message format; see {@link String#format(String, Object...)}.
+ * @param args The exception detail message arguments; see {@link String#format(String, Object...)}.
+ *
+ * @since 5.0
+ */
+ public ProtocolException(final String format, final Object... args) {
+ super(format, args);
+ }
+
+ /**
* Creates a new ProtocolException with the specified detail message and cause.
*
* @param message the exception detail message
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f5a28b9f/httpcore5/src/main/java/org/apache/hc/core5/http/TruncatedChunkException.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/TruncatedChunkException.java b/httpcore5/src/main/java/org/apache/hc/core5/http/TruncatedChunkException.java
index 7e3b679..ab0909e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/TruncatedChunkException.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/TruncatedChunkException.java
@@ -54,7 +54,7 @@ public class TruncatedChunkException extends MalformedChunkCodingException {
* @since 5.0
*/
public TruncatedChunkException(final String format, final Object... args) {
- super(HttpException.clean(String.format(format, args)));
+ super(format, args);
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f5a28b9f/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultContentLengthStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultContentLengthStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultContentLengthStrategy.java
index ea724d0..3976c6b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultContentLengthStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultContentLengthStrategy.java
@@ -69,11 +69,11 @@ public class DefaultContentLengthStrategy implements ContentLengthStrategy {
// treat it as a single-valued header here.
final Header transferEncodingHeader = message.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
if (transferEncodingHeader != null) {
- final String s = transferEncodingHeader.getValue();
- if (HeaderElements.CHUNKED_ENCODING.equalsIgnoreCase(s)) {
+ final String headerValue = transferEncodingHeader.getValue();
+ if (HeaderElements.CHUNKED_ENCODING.equalsIgnoreCase(headerValue)) {
return CHUNKED;
}
- throw new NotImplementedException("Unsupported transfer encoding: " + s);
+ throw new NotImplementedException("Unsupported transfer encoding: " + headerValue);
}
if (message.containsHeaders(HttpHeaders.CONTENT_LENGTH) > 1) {
throw new ProtocolException("Multiple Content-Length headers");
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f5a28b9f/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
index 907c98b..7d99852 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/HeaderGroup.java
@@ -267,7 +267,7 @@ public class HeaderGroup implements MessageHeaders, Serializable {
}
}
if (count > 1) {
- throw new ProtocolException("Multiple headers '" + name + "' found");
+ throw new ProtocolException("Multiple headers '%s'' found", name);
}
return singleHeader;
}