You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2018/08/13 23:45:27 UTC
httpcomponents-core git commit: Better exception messages. No need to
break up exception message strings.
Repository: httpcomponents-core
Updated Branches:
refs/heads/4.4.x 505e3feae -> a6536f2c3
Better exception messages. No need to break up exception message
strings.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/a6536f2c
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/a6536f2c
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/a6536f2c
Branch: refs/heads/4.4.x
Commit: a6536f2c3ddcd876f7ba9283eb23bd20913273b4
Parents: 505e3fe
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Aug 13 17:45:24 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Mon Aug 13 17:45:24 2018 -0600
----------------------------------------------------------------------
.../org/apache/http/impl/nio/codecs/ChunkDecoder.java | 4 ++--
.../http/impl/nio/codecs/LengthDelimitedDecoder.java | 14 +++++---------
.../org/apache/http/ConnectionClosedException.java | 12 ++++++++++++
.../java/org/apache/http/TruncatedChunkException.java | 2 ++
.../org/apache/http/impl/io/ChunkedInputStream.java | 4 ++--
.../apache/http/impl/io/ContentLengthInputStream.java | 8 ++++----
6 files changed, 27 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a6536f2c/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
index a6c0fea..5bc3291 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/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");
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a6536f2c/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
index 64e223a..1493f3d 100644
--- a/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
+++ b/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/LengthDelimitedDecoder.java
@@ -87,19 +87,15 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
this.completed = true;
if (this.len < this.contentLength) {
throw new ConnectionClosedException(
- "Premature end of Content-Length delimited message body (expected: "
- + this.contentLength + "; received: " + this.len + ")");
+ "Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
+ contentLength, len);
}
}
this.len += bytesRead;
if (this.len >= this.contentLength) {
this.completed = true;
}
- if (this.completed && bytesRead == 0) {
- return -1;
- } else {
- return bytesRead;
- }
+ return this.completed && bytesRead == 0 ? -1 : bytesRead;
}
@Override
@@ -140,8 +136,8 @@ public class LengthDelimitedDecoder extends AbstractContentDecoder
this.completed = true;
if (this.len < this.contentLength) {
throw new ConnectionClosedException(
- "Premature end of Content-Length delimited message body (expected: "
- + this.contentLength + "; received: " + this.len + ")");
+ "Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
+ contentLength, len);
}
}
this.len += bytesRead;
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a6536f2c/httpcore/src/main/java/org/apache/http/ConnectionClosedException.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/ConnectionClosedException.java b/httpcore/src/main/java/org/apache/http/ConnectionClosedException.java
index 0599181..7e406a5 100644
--- a/httpcore/src/main/java/org/apache/http/ConnectionClosedException.java
+++ b/httpcore/src/main/java/org/apache/http/ConnectionClosedException.java
@@ -56,4 +56,16 @@ public class ConnectionClosedException extends IOException {
super(HttpException.clean(message));
}
+ /**
+ * 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 4.4.11
+ */
+ public ConnectionClosedException(final String format, final Object... args) {
+ super(HttpException.clean(String.format(format, args)));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a6536f2c/httpcore/src/main/java/org/apache/http/TruncatedChunkException.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/TruncatedChunkException.java b/httpcore/src/main/java/org/apache/http/TruncatedChunkException.java
index 4ff9c3b..671efb4 100644
--- a/httpcore/src/main/java/org/apache/http/TruncatedChunkException.java
+++ b/httpcore/src/main/java/org/apache/http/TruncatedChunkException.java
@@ -50,6 +50,8 @@ public class TruncatedChunkException extends MalformedChunkCodingException {
*
* @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 4.4.11
*/
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/a6536f2c/httpcore/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java b/httpcore/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
index 5165b7d..68fe740 100644
--- a/httpcore/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
+++ b/httpcore/src/main/java/org/apache/http/impl/io/ChunkedInputStream.java
@@ -261,8 +261,8 @@ public class ChunkedInputStream extends InputStream {
this.buffer.clear();
final int bytesRead2 = this.in.readLine(this.buffer);
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 = this.buffer.indexOf(';');
if (separator < 0) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/a6536f2c/httpcore/src/main/java/org/apache/http/impl/io/ContentLengthInputStream.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/impl/io/ContentLengthInputStream.java b/httpcore/src/main/java/org/apache/http/impl/io/ContentLengthInputStream.java
index 6bfbacd..c4d8848 100644
--- a/httpcore/src/main/java/org/apache/http/impl/io/ContentLengthInputStream.java
+++ b/httpcore/src/main/java/org/apache/http/impl/io/ContentLengthInputStream.java
@@ -138,8 +138,8 @@ public class ContentLengthInputStream extends InputStream {
if (b == -1) {
if (pos < contentLength) {
throw new ConnectionClosedException(
- "Premature end of Content-Length delimited message body (expected: "
- + contentLength + "; received: " + pos + ")");
+ "Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
+ contentLength, pos);
}
} else {
pos++;
@@ -176,8 +176,8 @@ public class ContentLengthInputStream extends InputStream {
final int readLen = this.in.read(b, off, chunk);
if (readLen == -1 && pos < contentLength) {
throw new ConnectionClosedException(
- "Premature end of Content-Length delimited message body (expected: "
- + contentLength + "; received: " + pos + ")");
+ "Premature end of Content-Length delimited message body (expected: %,d; received: %,d)",
+ contentLength, pos);
}
if (readLen > 0) {
pos += readLen;