HttpHost implements NamedEndpoint, Serializable { public static HttpHost create(final String s) throws URISyntaxException { Args.notEmpty(s, "HTTP Host"); String text = s; String scheme = null; final int schemeIdx = text.indexOf(": if (schemeIdx > 0) { scheme = text.substring(0, schemeIdx); if (TextUtils.containsBlanks(scheme)) { throw new URISyntaxException(s, "scheme contains blanks"); } text = text.substring(schemeIdx + 3); } int port = -1; final int portIdx = text.lastIndexOf(":"); if (portIdx > 0) { try { port = Integer.parseInt(text.substring(portIdx + 1)); } catch (final NumberFormatException ex) { throw new URISyntaxException(s, "invalid port"); } text = text.substring(0, portIdx); } if (TextUtils.containsBlanks(text)) { throw new URISyntaxException(s, "hostname contains blanks"); } return new HttpHost(scheme, null, text, port); } HttpHost(final String scheme, final InetAddress address, final String hostname, final int port);  HttpHost(final String scheme, final String hostname, final int port);  HttpHost(final String hostname, final int port);  HttpHost(final String scheme, final String hostname);  HttpHost(final String hostname);  HttpHost(final String scheme, final InetAddress address, final int port);  HttpHost(final InetAddress address, final int port);  HttpHost(final InetAddress address);  HttpHost(final String scheme, final NamedEndpoint namedEndpoint);  HttpHost(final URIAuthority authority); static HttpHost create(final String s); static HttpHost create(final URI uri); @Override String getHostName(); @Override int getPort(); String getSchemeName(); InetAddress getAddress(); String toURI(); String toHostString(); @Override String toString(); @Override boolean equals(final Object obj); @Override int hashCode(); static final URIScheme DEFAULT_SCHEME; }
@Test public void testCreateFromString() throws Exception { Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create("https: Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create("HttpS: Assert.assertEquals(new HttpHost(null, "somehost", 1234), HttpHost.create("somehost:1234")); Assert.assertEquals(new HttpHost(null, "somehost", -1), HttpHost.create("somehost")); }
@Test public void testCreateFromURI() throws Exception { Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create(URI.create("https: Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create(URI.create("HttpS: Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create(URI.create("HttpS: }
@Test public void testCreateFromStringInvalid() throws Exception { try { HttpHost.create(" host "); Assert.fail("URISyntaxException expected"); } catch (final URISyntaxException expected) { } try { HttpHost.create("host :8080"); Assert.fail("URISyntaxException expected"); } catch (final URISyntaxException expected) { } try { HttpHost.create(""); Assert.fail("IllegalArgumentException expected"); } catch (final IllegalArgumentException expected) { } }