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/11/09 01:20:22 UTC
httpcomponents-core git commit: Add
org.apache.hc.core5.http.HttpHost.create(URI).
Repository: httpcomponents-core
Updated Branches:
refs/heads/master 2673f76b8 -> f57aff3d4
Add org.apache.hc.core5.http.HttpHost.create(URI).
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/f57aff3d
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/f57aff3d
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/f57aff3d
Branch: refs/heads/master
Commit: f57aff3d4286b0d4054cb9b4f52665f284bd882a
Parents: 2673f76
Author: Gary Gregory <ga...@gmail.com>
Authored: Thu Nov 8 18:20:19 2018 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Thu Nov 8 18:20:19 2018 -0700
----------------------------------------------------------------------
RELEASE_NOTES.txt | 3 +++
.../java/org/apache/hc/core5/http/HttpHost.java | 16 +++++++++++++++-
.../java/org/apache/hc/core5/http/TestHttpHost.java | 8 ++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f57aff3d/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 50239c2..df7ec0f 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -36,6 +36,9 @@ Release 5.0-BETA6
* Deprecate constructors in org.apache.hc.core5.http.HttpHost that do not have the scheme argument first in favor of new constructors that do.
Contributed by Gary Gregory <ggregory at apache.org>
+* Add org.apache.hc.core5.http.HttpHost.create(URI)
+ Contributed by Gary Gregory <ggregory at apache.org>
+
Release 5.0-BETA5
-------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f57aff3d/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
index aadb02d..94baca3 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
@@ -29,6 +29,7 @@ package org.apache.hc.core5.http;
import java.io.Serializable;
import java.net.InetAddress;
+import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;
@@ -162,7 +163,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
}
/**
- * Creates {@code HttpHost} instance from string. Text may not contain any blanks.
+ * Creates {@code HttpHost} instance from a string. Text may not contain any blanks.
*
* @since 4.4
*/
@@ -198,6 +199,19 @@ public final class HttpHost implements NamedEndpoint, Serializable {
}
/**
+ * Creates an {@code HttpHost} instance from the scheme, host, and port from the given URI. Other URI elements are ignored.
+ *
+ * @param uri scheme, host, and port.
+ * @return a new HttpHost
+ *
+ * @since 5.0
+ */
+ public static HttpHost create(final URI uri) {
+ final String scheme = uri.getScheme();
+ return new HttpHost(scheme != null ? scheme : URIScheme.HTTP.getId(), uri.getHost(), uri.getPort());
+ }
+
+ /**
* Creates {@code HttpHost} instance with the default scheme and port and the given hostname.
*
* @param hostname the hostname (IP or DNS name)
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f57aff3d/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java b/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java
index 8b7fca4..1fa99a4 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/TestHttpHost.java
@@ -32,6 +32,7 @@ import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
+import java.net.URI;
import java.net.URISyntaxException;
import org.junit.Assert;
@@ -204,6 +205,13 @@ public class TestHttpHost {
}
@Test
+ public void testCreateFromURI() throws Exception {
+ Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create(URI.create("https://somehost:8080")));
+ Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create(URI.create("HttpS://SomeHost:8080")));
+ Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create(URI.create("HttpS://SomeHost:8080/foo")));
+ }
+
+ @Test
public void testCreateFromStringInvalid() throws Exception {
try {
HttpHost.create(" host ");