I am invoking java classes on a Javascript engine, so I am limited on what I can do.
The code works fine, but when I invoke the Javascript on a loop, it times out after the first invocation.
The code just downloads a ZIP from a url, and stores it to a path. Here is the full code:
var result = (function() {
var URL = Packages.java.net.URL;
var Files = Packages.java.nio.file.Files;
var Paths = Packages.java.nio.file.Paths;
var StandardCopyOption = Packages.java.nio.file.StandardCopyOption;
var urlAddr = new URL(
target_url
);
var connection = urlAddr.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", bearer);
connection.setReadTimeout(20*1000);
connection.connect();
Files.copy(connection.getInputStream(), Paths.get(file_path+new_filename+".zip"), StandardCopyOption.REPLACE_EXISTING);
return "";
}());
The error I am getting from the server:
Java Exception: java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out: during call of javax.script.ScriptEngine.eval.
Before someone suggests, I cant get away from the java being called inside the javascript.
I thought it could be a connection being kept open.
UPDATE: this javascript for some reason is always taking 5 minutes to run....
UPDATE2: Files.copy seems to be the issue, since its the one taking the 5 minutes from the code.... the file is very small, and 5 min wouldnt justify