Skip to content

Commit

Permalink
improve exception text, add timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jan 21, 2025
1 parent 7f49eb4 commit 52ff7e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/mvn/MavenUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ else if ("optional".equals(placeholder)) {
if (!modifed) break;
}
if (value != null && value.indexOf("${") != -1) {
throw new IOException("cannot resolve [" + value + "] for [" + pom + "], available properties are [" + ListUtil.toList(properties.keySet(), ", ") + "]");
throw new IOException("Cannot resolve [" + value + "] for [" + pom + "], available properties are [" + ListUtil.toList(properties.keySet(), ", ") + "]");
}
return value;
}
Expand Down Expand Up @@ -404,7 +404,7 @@ public static void download(POM pom, Collection<Repository> repositories, String
}
}
catch (IOException ioe) {
IOException ex = new IOException("tied to download [" + type + "], because no local copy at [" + res + "] is available.");
IOException ex = new IOException("Failed to download [" + type + "], because no local copy found at [" + res + "].");
ExceptionUtil.initCauseEL(ex, ioe);
// MUST add again ResourceUtil.deleteEmptyFoldersInside(pom.getLocalDirectory());
throw ex;
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/lucee/runtime/mvn/POM.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class POM {

public static final Repository DEFAULT_REPOSITORY = new Repository("maven-central", "Maven Central", "https://repo1.maven.org/maven2/");

public static final int CONNECTION_TIMEOUT = 50000;
public static final int READ_TIMEOUT_HEAD = 5000;
public static final int READ_TIMEOUT_GET = 20000;

public static final int SCOPE_COMPILE = 1;
public static final int SCOPE_TEST = 2;
public static final int SCOPE_PROVIDED = 4;
Expand Down Expand Up @@ -428,6 +432,8 @@ public URL getArtifact(String type, Collection<Repository> repositories) throws
url = new URL(r.getUrl() + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "." + type);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("HEAD");
connection.setConnectTimeout(CONNECTION_TIMEOUT);
connection.setReadTimeout(READ_TIMEOUT_HEAD);
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
return url;
Expand All @@ -440,6 +446,8 @@ else if (responseCode == 301 || responseCode == 302) {
url = new URL(newUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("HEAD");
connection.setConnectTimeout(CONNECTION_TIMEOUT);
connection.setReadTimeout(READ_TIMEOUT_HEAD);
responseCode = connection.getResponseCode();
if (responseCode == 200) {
return url;
Expand All @@ -450,7 +458,7 @@ else if (responseCode == 301 || responseCode == 302) {
else sb.append(", ");
sb.append(url.toExternalForm());
}
throw new IOException("could not find a valid endpoint [" + toString() + "] for type [" + type + "], possibles endpoint are [" + sb + "]");
throw new IOException("Failed to download java artifact [" + toString() + "] for type [" + type + "], attempted endpoint(s): [" + sb + "]");
}

@Override
Expand Down

0 comments on commit 52ff7e7

Please sign in to comment.