I want to download pdf file but source url is too slow. Because of this, I am giving connection timeout exception with following code.
try {
URL url = new URL(source);
HttpURLConnection huc = (HttpURLConnection)
url.openConnection();
huc.setConnectTimeout(0); //for unlimited
huc.setReadTimeout(0);
try (InputStream in = huc.getInputStream()) {
Files.copy(in, Paths.get(destination), StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
LOGGER.info("Error occured while copying file, %s", e);
return false;
}
I tried to change setConnectTimeout and setReadTimeout values both 0 and 5 minutes by converting to milliseconds but after the ~130 seconds, it throws connection timeout exception. I couldn't change this value. After the set read and connection timeout, getConnectionTimeout and getReadTimeout value return value, my set.
Also I tried apache libraries to copy input stream to destination but again I received connection timeout exception.
I have already known, connection bigger than 15 seconds is abnormal but I want to download file how long it takes.
So, how to increase this timeout value?