private CloseableHttpResponse execute(String requestUrl, String userName, String password) throws IOException { CloseableHttpResponse response; Proxy proxy = proxyConfig.getProxyForUrl(requestUrl); if (proxy != null) { LOGGER.info("Downloading via proxy " + proxy.toString()); return executeViaProxy(proxy, requestUrl); } else { LOGGER.info("No proxy was configured, downloading directly"); if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) { LOGGER.info("Using credentials (" + userName + ") from settings.xml"); // Auth target host URL aURL = new URL(requestUrl); HttpClientContext localContext = makeLocalContext(aURL); CredentialsProvider credentialsProvider = makeCredentialsProvider( aURL.getHost(), aURL.getPort(), userName, password); response = buildHttpClient(credentialsProvider).execute(new HttpGet(requestUrl),localContext); } else { response = buildHttpClient(null).execute(new HttpGet(requestUrl)); } } return response; }
private CloseableHttpResponse executeViaProxy(Proxy proxy, String requestUrl) throws IOException { final CloseableHttpClient proxyClient; if (proxy.useAuthentication()){ proxyClient = buildHttpClient(makeCredentialsProvider(proxy.host,proxy.port,proxy.username,proxy.password)); } else { proxyClient = buildHttpClient(null); } final HttpHost proxyHttpHost = new HttpHost(proxy.host, proxy.port); final RequestConfig requestConfig = RequestConfig.custom().setProxy(proxyHttpHost).build(); final HttpGet request = new HttpGet(requestUrl); request.setConfig(requestConfig); return proxyClient.execute(request); }
public YarnInstaller getYarnInstaller(ProxyConfig proxy) { return new YarnInstaller(getInstallConfig(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy)); }
@Override public void download(String downloadUrl, String destination, String userName, String password) throws DownloadException { // force tls to 1.2 since github removed weak cryptographic standards // https://blog.github.com/2018-02-02-weak-cryptographic-standards-removal-notice/ System.setProperty("https.protocols", "TLSv1.2"); String fixedDownloadUrl = downloadUrl; try { fixedDownloadUrl = FilenameUtils.separatorsToUnix(fixedDownloadUrl); URI downloadURI = new URI(fixedDownloadUrl); if ("file".equalsIgnoreCase(downloadURI.getScheme())) { FileUtils.copyFile(new File(downloadURI), new File(destination)); } else { CloseableHttpResponse response = execute(fixedDownloadUrl, userName, password); int statusCode = response.getStatusLine().getStatusCode(); if(statusCode != 200){ throw new DownloadException("Got error code "+ statusCode +" from the server."); } new File(FilenameUtils.getFullPathNoEndSeparator(destination)).mkdirs(); ReadableByteChannel rbc = Channels.newChannel(response.getEntity().getContent()); FileOutputStream fos = new FileOutputStream(destination); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); fos.close(); } } catch (IOException | URISyntaxException e) { throw new DownloadException("Could not download " + fixedDownloadUrl, e); } }
public NodeInstaller getNodeInstaller(ProxyConfig proxy) { return new NodeInstaller(getInstallConfig(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy)); }
public NPMInstaller getNPMInstaller(ProxyConfig proxy) { return new NPMInstaller(getInstallConfig(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy)); }