public DefaultHttpDownloader(Configuration config, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) { this.readTimeout = readTimeout; this.connectTimeout = connectTimeout; downloader = new BaseHttpDownloader(new AuthenticatorFacade(), config, null); }
Loggers.get(getClass()).debug("Download: " + uri + " (" + getProxySynthesis(uri, ProxySelector.getDefault()) + ")"); HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); connection.setRequestMethod(requestMethod);
BaseHttpDownloader(AuthenticatorFacade system, Configuration config, @Nullable String userAgent) { initProxy(system, config); initUserAgent(userAgent, config); }
Loggers.get(getClass()).debug("Download: " + uri + " (" + getProxySynthesis(uri, ProxySelector.getDefault()) + ")"); HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); connection.setRequestMethod(requestMethod);
private static String getProxySynthesis(URI uri) { return getProxySynthesis(uri, ProxySelector.getDefault()); }
public HttpInputSupplier newInputSupplier(URI uri, @Nullable Integer connectTimeoutMillis, @Nullable Integer readTimeoutMillis) { return newInputSupplier(uri, GET, connectTimeoutMillis, readTimeoutMillis); }
public HttpInputSupplier newInputSupplier(URI uri, String requestMethod, @Nullable Integer connectTimeoutMillis, @Nullable Integer readTimeoutMillis) { return newInputSupplier(uri, requestMethod, null, null, connectTimeoutMillis, readTimeoutMillis); }
@Override public void download(URI uri, File toFile) { try { copyInputStreamToFile(downloader.newInputSupplier(uri, this.connectTimeout, this.readTimeout).getInput(), toFile); } catch (IOException e) { deleteQuietly(toFile); throw failToDownload(uri, e); } }
@Override public InputStream openStream(URI uri) { try { return downloader.newInputSupplier(uri, this.connectTimeout, this.readTimeout).getInput(); } catch (IOException e) { throw failToDownload(uri, e); } }
@Override protected String readString(URI uri, Charset charset) { try { return IOUtils.toString(downloader.newInputSupplier(uri, this.connectTimeout, this.readTimeout).getInput(), charset); } catch (IOException e) { throw failToDownload(uri, e); } }
public DefaultHttpDownloader(Server server, Configuration config, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) { this.readTimeout = readTimeout; this.connectTimeout = connectTimeout; downloader = new BaseHttpDownloader(new AuthenticatorFacade(), config, server.getVersion()); }
BaseHttpDownloader(AuthenticatorFacade system, Configuration config, @Nullable String userAgent) { initProxy(system, config); initUserAgent(userAgent, config); }
@Override public byte[] download(URI uri) { try { return ByteStreams.toByteArray(downloader.newInputSupplier(uri, this.connectTimeout, this.readTimeout).getInput()); } catch (IOException e) { throw failToDownload(uri, e); } }
public DefaultHttpDownloader(Configuration config, @Nullable Integer connectTimeout, @Nullable Integer readTimeout) { this.readTimeout = readTimeout; this.connectTimeout = connectTimeout; downloader = new BaseHttpDownloader(new AuthenticatorFacade(), config, null); }
@Test public void configure_http_proxy_credentials() { DefaultHttpDownloader.AuthenticatorFacade system = mock(DefaultHttpDownloader.AuthenticatorFacade.class); MapSettings settings = new MapSettings(); settings.setProperty("https.proxyHost", "1.2.3.4"); settings.setProperty("http.proxyUser", "the_login"); settings.setProperty("http.proxyPassword", "the_passwd"); new DefaultHttpDownloader.BaseHttpDownloader(system, settings.asConfig(), null); verify(system).setDefaultAuthenticator(argThat(authenticator -> { DefaultHttpDownloader.ProxyAuthenticator a = (DefaultHttpDownloader.ProxyAuthenticator) authenticator; PasswordAuthentication authentication = a.getPasswordAuthentication(); return authentication.getUserName().equals("the_login") && new String(authentication.getPassword()).equals("the_passwd"); })); }
public HttpInputSupplier newInputSupplier(URI uri, @Nullable Integer connectTimeoutMillis, @Nullable Integer readTimeoutMillis) { return newInputSupplier(uri, GET, connectTimeoutMillis, readTimeoutMillis); }
private static String getProxySynthesis(URI uri) { return getProxySynthesis(uri, ProxySelector.getDefault()); }
public HttpInputSupplier newInputSupplier(URI uri, String requestMethod, @Nullable Integer connectTimeoutMillis, @Nullable Integer readTimeoutMillis) { return newInputSupplier(uri, requestMethod, null, null, connectTimeoutMillis, readTimeoutMillis); }
@Test public void shouldGetProxySynthesis() throws URISyntaxException { ProxySelector proxySelector = mock(ProxySelector.class); when(proxySelector.select(any(URI.class))).thenReturn(Arrays.<Proxy>asList(new FakeProxy())); assertThat(DefaultHttpDownloader.BaseHttpDownloader.getProxySynthesis(new URI("http://an_url"), proxySelector)).isEqualTo("HTTP proxy: /123.45.67.89:4040"); }
@Override public byte[] download(URI uri) { try { return ByteStreams.toByteArray(downloader.newInputSupplier(uri, this.connectTimeout, this.readTimeout).getInput()); } catch (IOException e) { throw failToDownload(uri, e); } }