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:29 UTC
[18/32] httpcomponents-core git commit: Better exception messages.
Better exception messages.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/4316c748
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/4316c748
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/4316c748
Branch: refs/heads/api_javadocs
Commit: 4316c748a5d2982855f6755e689fe136fdf6ad0c
Parents: 3267db4
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Aug 13 17:13:56 2018 -0600
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Aug 14 09:27:43 2018 +0200
----------------------------------------------------------------------
.../apache/hc/core5/http/ConnectionClosedException.java | 12 ++++++++++++
.../apache/hc/core5/http/TruncatedChunkException.java | 12 ++++++++++++
.../hc/core5/http/impl/io/ChunkedInputStream.java | 9 ++++-----
.../hc/core5/http/impl/io/ContentLengthInputStream.java | 8 ++++----
.../org/apache/hc/core5/http/impl/nio/ChunkDecoder.java | 10 +++++-----
.../hc/core5/http/impl/nio/LengthDelimitedDecoder.java | 8 ++++----
6 files changed, 41 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/4316c748/httpcore5/src/main/java/org/apache/hc/core5/http/ConnectionClosedException.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/ConnectionClosedException.java b/httpcore5/src/main/java/org/apache/hc/core5/http/ConnectionClosedException.java
index ffbee69..e24f06a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/ConnectionClosedException.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/ConnectionClosedException.java
@@ -55,6 +55,18 @@ public class ConnectionClosedException extends IOException {
}
/**
+ * Constructs a new ConnectionClosedException 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 ConnectionClosedException(final String format, final Object... args) {
+ super(HttpException.clean(String.format(format, args)));
+ }
+
+ /**
* Constructs a {@code ConnectionClosedException} with the specified detail message
* and cause.
*
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/4316c748/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 446b715..7e3b679 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
@@ -45,4 +45,16 @@ public class TruncatedChunkException extends MalformedChunkCodingException {
super(HttpException.clean(message));
}
+ /**
+ * Constructs a new TruncatedChunkException 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 TruncatedChunkException(final String format, final Object... args) {
+ super(HttpException.clean(String.format(format, args)));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/4316c748/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java
index 0fd0360..c6adb50 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ChunkedInputStream.java
@@ -194,9 +194,8 @@ public class ChunkedInputStream extends InputStream {
return bytesRead;
}
eof = true;
- throw new TruncatedChunkException("Truncated chunk "
- + "( expected size: " + chunkSize
- + "; actual size: " + pos + ")");
+ throw new TruncatedChunkException("Truncated chunk (expected size: %,d; actual size: %,d)",
+ chunkSize, pos);
}
/**
@@ -261,8 +260,8 @@ public class ChunkedInputStream extends InputStream {
lineBuffer.clear();
final int bytesRead2 = this.buffer.readLine(lineBuffer, inputStream);
if (bytesRead2 == -1) {
- throw new ConnectionClosedException("Premature end of chunk coded message body: " +
- "closing chunk expected");
+ throw new ConnectionClosedException(
+ "Premature end of chunk coded message body: closing chunk expected");
}
int separator = lineBuffer.indexOf(';');
if (separator < 0) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/4316c748/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java
index 501c2b2..b544971 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/ContentLengthInputStream.java
@@ -134,9 +134,9 @@ public class ContentLengthInputStream extends InputStream {
final int b = this.buffer.read(this.inputStream);
if (b == -1) {
if (pos < contentLength) {
- throw new ConnectionClosedException(String.format(
+ throw new ConnectionClosedException(
"Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
- contentLength, pos));
+ contentLength, pos);
}
} else {
pos++;
@@ -172,9 +172,9 @@ public class ContentLengthInputStream extends InputStream {
}
final int count = this.buffer.read(b, off, chunk, this.inputStream);
if (count == -1 && pos < contentLength) {
- throw new ConnectionClosedException(String.format(
+ throw new ConnectionClosedException(
"Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
- contentLength, pos));
+ contentLength, pos);
}
if (count > 0) {
pos += count;
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/4316c748/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
index 04057f2..e5e1a95 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ChunkDecoder.java
@@ -135,8 +135,8 @@ public class ChunkDecoder extends AbstractContentDecoder {
}
this.pos = 0L;
} else if (this.endOfStream) {
- throw new ConnectionClosedException("Premature end of chunk coded message body: " +
- "closing chunk expected");
+ throw new ConnectionClosedException(
+ "Premature end of chunk coded message body: closing chunk expected");
}
}
@@ -223,9 +223,9 @@ public class ChunkDecoder extends AbstractContentDecoder {
if (!this.buffer.hasData() && this.endOfStream) {
this.state = COMPLETED;
this.completed = true;
- throw new TruncatedChunkException("Truncated chunk "
- + "( expected size: " + this.chunkSize
- + "; actual size: " + this.pos + ")");
+ throw new TruncatedChunkException(
+ "Truncated chunk (expected size: %,d; actual size: %,d)",
+ chunkSize, pos);
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/4316c748/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
index d47cdd6..38b6569 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/LengthDelimitedDecoder.java
@@ -85,9 +85,9 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder implements Fi
if (bytesRead == -1) {
this.completed = true;
if (this.len < this.contentLength) {
- throw new ConnectionClosedException(String.format(
+ throw new ConnectionClosedException(
"Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
- this.contentLength, this.len));
+ this.contentLength, this.len);
}
}
this.len += bytesRead;
@@ -137,9 +137,9 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder implements Fi
if (bytesRead == -1) {
this.completed = true;
if (this.len < this.contentLength) {
- throw new ConnectionClosedException(String.format(
+ throw new ConnectionClosedException(
"Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
- this.contentLength, this.len));
+ this.contentLength, this.len);
}
}
this.len += bytesRead;