private void downloadFile(Request req) {
        String url = req.parameters().get(0).asString();
        String authHeader = req.parameters().size() > 1 ? req.parameters().get(1).asString() : null;

        File downloadDir = new File(rootDownloadDir, urlToDirName(url));
        UrlDownloader downloader;
        try {
            downloader = downloader(url, new DownloadOptions(authHeader));
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
        if (downloader.alreadyDownloaded(downloadDir)) {
            log.log(Level.INFO, "URL '" + url + "' already downloaded");
            req.returnValues().add(new StringValue(new File(downloadDir, downloader.fileName()).getAbsolutePath()));
            req.returnRequest();
            return;
        }

        try {
            Files.createDirectories(downloadDir.toPath());
            Optional<File> file = downloader.download(downloadDir);
            if (file.isPresent())
                req.returnValues().add(new StringValue(file.get().getAbsolutePath()));
            else
                req.setError(DOES_NOT_EXIST, "URL '" + url + "' not found");
        } catch (RuntimeException e) {
            logAndSetRpcError(req, url, e, HTTP_ERROR);
        } catch (Throwable e) {
            logAndSetRpcError(req, url, e, INTERNAL_ERROR);
        }
        req.returnRequest();
    }
An RPC server that handles URL download requests.

@author Lester Solbakken
config-proxy/src/main/java/com/yahoo/vespa/config/proxy/filedistribution/UrlDownloadRpcServer.java