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/14 07:38:33 UTC

[10/11] httpcomponents-core git commit: Refactor common code into a new ctor.

Refactor common code into a new ctor.

Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/2e5d72b4
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/2e5d72b4
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/2e5d72b4

Branch: refs/heads/master
Commit: 2e5d72b4d8ffe7687ba211cab335e218599fe148
Parents: 825d67d
Author: Gary Gregory <ga...@gmail.com>
Authored: Mon Aug 13 23:16:42 2018 -0600
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Aug 14 09:29:13 2018 +0200

----------------------------------------------------------------------
 .../org/apache/hc/core5/http/LengthRequiredException.java   | 4 ++--
 .../hc/core5/http/UnsupportedHttpVersionException.java      | 9 +++++++++
 .../hc/core5/http/impl/io/DefaultBHttpClientConnection.java | 4 ++--
 .../hc/core5/http/impl/io/DefaultBHttpServerConnection.java | 2 +-
 .../apache/hc/core5/http/impl/io/HttpRequestExecutor.java   | 2 +-
 .../hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java   | 2 +-
 .../hc/core5/http/impl/nio/ClientHttp1StreamHandler.java    | 4 ++--
 .../hc/core5/http/impl/nio/ServerHttp1StreamHandler.java    | 4 ++--
 8 files changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2e5d72b4/httpcore5/src/main/java/org/apache/hc/core5/http/LengthRequiredException.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/LengthRequiredException.java b/httpcore5/src/main/java/org/apache/hc/core5/http/LengthRequiredException.java
index 4edad35..29b6abe 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/LengthRequiredException.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/LengthRequiredException.java
@@ -37,10 +37,10 @@ public class LengthRequiredException extends ProtocolException {
     private static final long serialVersionUID = 1049109801075840707L;
 
     /**
-     * Creates an exception without a detail message.
+     * Creates an exception without a default detail message.
      */
     public LengthRequiredException() {
-        super();
+        super("Length required");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2e5d72b4/httpcore5/src/main/java/org/apache/hc/core5/http/UnsupportedHttpVersionException.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/UnsupportedHttpVersionException.java b/httpcore5/src/main/java/org/apache/hc/core5/http/UnsupportedHttpVersionException.java
index a340894..c81b2e2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/UnsupportedHttpVersionException.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/UnsupportedHttpVersionException.java
@@ -44,6 +44,15 @@ public class UnsupportedHttpVersionException extends ProtocolException {
     }
 
     /**
+     * Creates an exception with a detail message for the given ProtocolVersion.
+     *
+     * @param protocolVersion The unsupported ProtocolVersion.
+     */
+    public UnsupportedHttpVersionException(final ProtocolVersion protocolVersion) {
+        super("Unsupported version: " + protocolVersion);
+    }
+
+    /**
      * Creates an exception with the specified detail message.
      *
      * @param message The exception detail message

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2e5d72b4/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
index 4f770d0..841d48f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnection.java
@@ -147,7 +147,7 @@ public class DefaultBHttpClientConnection extends BHttpConnectionBase
         }
         final long len = this.outgoingContentStrategy.determineLength(request);
         if (len == ContentLengthStrategy.UNDEFINED) {
-            throw new LengthRequiredException("Length required");
+            throw new LengthRequiredException();
         }
         try (final OutputStream outStream = createContentOutputStream(len, this.outbuffer, socketHolder.getOutputStream(), entity.getTrailers())) {
             entity.writeTo(outStream);
@@ -186,7 +186,7 @@ public class DefaultBHttpClientConnection extends BHttpConnectionBase
         final ClassicHttpResponse response = this.responseParser.parse(this.inBuffer, socketHolder.getInputStream());
         final ProtocolVersion transportVersion = response.getVersion();
         if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-            throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
+            throw new UnsupportedHttpVersionException(transportVersion);
         }
         this.version = transportVersion;
         onResponseReceived(response);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2e5d72b4/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
index c9d87c3..3bde5f1 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
@@ -135,7 +135,7 @@ public class DefaultBHttpServerConnection extends BHttpConnectionBase implements
         final ClassicHttpRequest request = this.requestParser.parse(this.inBuffer, socketHolder.getInputStream());
         final ProtocolVersion transportVersion = request.getVersion();
         if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-            throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
+            throw new UnsupportedHttpVersionException(transportVersion);
         }
         request.setScheme(this.scheme);
         this.version = transportVersion;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2e5d72b4/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
index a84fbe0..f7b948f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/HttpRequestExecutor.java
@@ -128,7 +128,7 @@ public class HttpRequestExecutor {
             final ProtocolVersion transportVersion = request.getVersion();
             if (transportVersion != null) {
                 if (transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-                    throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
+                    throw new UnsupportedHttpVersionException(transportVersion);
                 }
                 context.setProtocolVersion(transportVersion);
             }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2e5d72b4/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
index e9f1acd..c3bdcfa 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
@@ -272,7 +272,7 @@ public class ClientHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
             final int chunkSizeHint = h1Config.getChunkSizeHint() >= 0 ? h1Config.getChunkSizeHint() : 2048;
             return new ChunkEncoder(channel, buffer, metrics, chunkSizeHint);
         } else {
-            throw new LengthRequiredException("Length required");
+            throw new LengthRequiredException();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2e5d72b4/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
index b0485a4..56766af 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
@@ -145,7 +145,7 @@ class ClientHttp1StreamHandler implements ResourceHolder {
         if (requestCommitted.compareAndSet(false, true)) {
             final ProtocolVersion transportVersion = request.getVersion();
             if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-                throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
+                throw new UnsupportedHttpVersionException(transportVersion);
             }
             context.setProtocolVersion(transportVersion);
             context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);
@@ -203,7 +203,7 @@ class ClientHttp1StreamHandler implements ResourceHolder {
         }
         final ProtocolVersion transportVersion = response.getVersion();
         if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-            throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
+            throw new UnsupportedHttpVersionException(transportVersion);
         }
 
         final int status = response.getCode();

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2e5d72b4/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 44fbe6f..a43b288 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
@@ -127,7 +127,7 @@ class ServerHttp1StreamHandler implements ResourceHolder {
 
             final ProtocolVersion transportVersion = response.getVersion();
             if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-                throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
+                throw new UnsupportedHttpVersionException(transportVersion);
             }
 
             final int status = response.getCode();
@@ -211,7 +211,7 @@ class ServerHttp1StreamHandler implements ResourceHolder {
 
         final ProtocolVersion transportVersion = request.getVersion();
         if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
-            throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
+            throw new UnsupportedHttpVersionException(transportVersion);
         }
         context.setProtocolVersion(transportVersion);
         context.setAttribute(HttpCoreContext.HTTP_REQUEST, request);