/** * @since 4.4 */ public Request viaProxy(final String proxy) { try { this.proxy = HttpHost.create(proxy); } catch (final URISyntaxException e) { throw new IllegalArgumentException("Invalid host"); } return this; }
/** * @since 4.4 */ public Executor auth(final String host, final Credentials creds) { final HttpHost httpHost; try { httpHost = HttpHost.create(host); } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + host); } return auth(httpHost, creds); }
/** * @since 4.4 */ public Executor authPreemptiveProxy(final String proxy) { final HttpHost httpHost; try { httpHost = HttpHost.create(proxy); } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + proxy); } return authPreemptiveProxy(httpHost); }
/** * @since 4.4 */ public Executor authPreemptive(final String host) { final HttpHost httpHost; try { httpHost = HttpHost.create(host); } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + host); } return authPreemptive(httpHost); }
/** * @since 4.4 */ public Request viaProxy(final String proxy) { try { this.proxy = HttpHost.create(proxy); } catch (final URISyntaxException e) { throw new IllegalArgumentException("Invalid host"); } return this; }
/** * @since 4.4 */ public Executor authPreemptive(final String host) { final HttpHost httpHost; try { httpHost = HttpHost.create(host); } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + host); } return authPreemptive(httpHost); }
/** * @since 4.4 */ public Executor auth(final String host, final Credentials creds) { final HttpHost httpHost; try { httpHost = HttpHost.create(host); } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + host); } return auth(httpHost, creds); }
/** * @since 4.4 */ public Executor authPreemptiveProxy(final String proxy) { final HttpHost httpHost; try { httpHost = HttpHost.create(proxy); } catch (final URISyntaxException ex) { throw new IllegalArgumentException("Invalid host: " + proxy); } return authPreemptiveProxy(httpHost); }
@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) { } }
@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 testCreateFromString() throws Exception { Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create("https://somehost:8080")); Assert.assertEquals(new HttpHost("https", "somehost", 8080), HttpHost.create("HttpS://SomeHost:8080")); Assert.assertEquals(new HttpHost(null, "somehost", 1234), HttpHost.create("somehost:1234")); Assert.assertEquals(new HttpHost(null, "somehost", -1), HttpHost.create("somehost")); }