public static void downloadFromHttpUrl(String destPkgUrl, File targetFile) throws IOException {
        final URL url = new URL(destPkgUrl);
        final URLConnection connection = url.openConnection();
        if (StringUtils.isNotEmpty(url.getUserInfo())) {
            final AuthenticationDataBasic authBasic = new AuthenticationDataBasic(url.getUserInfo());
            for (Map.Entry<String, String> header : authBasic.getHttpHeaders()) {
                connection.setRequestProperty(header.getKey(), header.getValue());
            }
        }
        try (InputStream in = connection.getInputStream()) {
            log.info("Downloading function package from {} to {} ...", destPkgUrl, targetFile.getAbsoluteFile());
            Files.copy(in, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        }
        log.info("Downloading function package from {} to {} completed!", destPkgUrl, targetFile.getAbsoluteFile());
    }
@Test
    public void testDownloadFileWithBasicAuth() throws Exception {
        @Cleanup("stop")
        WireMockServer server = new WireMockServer(0);
        server.start();
        configureFor(server.port());
        stubFor(get(urlPathEqualTo("/"))
                .withBasicAuth("foo", "bar")
                .willReturn(aResponse().withBody("Hello world!").withStatus(200)));
        final String jarHttpUrl = "http://foo:bar@localhost:" + server.port() + "/";
        final File file = Files.newTemporaryFile();
        file.deleteOnExit();
        assertThat(file.length()).isZero();
        FunctionCommon.downloadFromHttpUrl(jarHttpUrl, file);
        assertThat(file.length()).isGreaterThan(0);
    }