Skip to content

Commit

Permalink
Fix for artifacts not found (surfacing in 500 internal server errors). (
Browse files Browse the repository at this point in the history
#4100)

* Fix for artifacts not found (surfacing in 500 internal server errors).

When the repository url ends with a `/` we add another causing an incorrect URL, this results in a 404 returned from the maven repo which we translate to a `MavenDownloadingException` causing the 500 responses.

* rename field
  • Loading branch information
pstreef authored Mar 22, 2024
1 parent 687fbb5 commit 5917ccc
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ public Path downloadArtifact(ResolvedDependency dependency) {
return null;
}
return mavenArtifactCache.computeArtifact(dependency, () -> {
String uri = requireNonNull(dependency.getRepository(),
String.format("Repository for dependency '%s' was null.", dependency)).getUri() + "/" +
dependency.getGroupId().replace('.', '/') + '/' +
dependency.getArtifactId() + '/' +
dependency.getVersion() + '/' +
dependency.getArtifactId() + '-' +
(dependency.getDatedSnapshotVersion() == null ? dependency.getVersion() : dependency.getDatedSnapshotVersion()) +
".jar";
String baseUri = requireNonNull(dependency.getRepository(),
String.format("Repository for dependency '%s' was null.", dependency)).getUri();
String path = dependency.getGroupId().replace('.', '/') + '/' +
dependency.getArtifactId() + '/' +
dependency.getVersion() + '/' +
dependency.getArtifactId() + '-' +
(dependency.getDatedSnapshotVersion() == null ? dependency.getVersion() : dependency.getDatedSnapshotVersion()) +
".jar";
String uri = baseUri + (baseUri.endsWith("/") ? "" : "/") + path;

InputStream bodyStream;

Expand All @@ -112,8 +113,8 @@ public Path downloadArtifact(ResolvedDependency dependency) {
try (HttpSender.Response response = Failsafe.with(retryPolicy).get(() -> httpSender.send(request.build()));
InputStream body = response.getBody()) {
if (!response.isSuccessful() || body == null) {
onError.accept(new MavenDownloadingException(String.format("Unable to download dependency %s:%s:%s. Response was %d",
dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), response.getCode()), null,
onError.accept(new MavenDownloadingException(String.format("Unable to download dependency %s:%s:%s from %s. Response was %d",
dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), uri, response.getCode()), null,
dependency.getRequested().getGav()));
return null;
}
Expand Down

0 comments on commit 5917ccc

Please sign in to comment.