Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit 90e3680

Browse files
committed
Fixing redirect url for certain cases
1 parent 51f9d78 commit 90e3680

2 files changed

Lines changed: 119 additions & 100 deletions

File tree

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ protected String getArtifactUrl( Artifact artifact )
232232
protected String getArtifactUrl( Artifact artifact, String repositoryId )
233233
throws ArchivaRestServiceException
234234
{
235+
log.debug( "Getting artifact url {}", artifact );
236+
log.debug( "Getting artifact context {}", artifact.getContext() );
235237
try
236238
{
237239

@@ -244,13 +246,16 @@ protected String getArtifactUrl( Artifact artifact, String repositoryId )
244246

245247
sb.append( "/repository" );
246248

249+
247250
// when artifact come from a remote repository when have here the remote repo id
248251
// we must replace it with a valid managed one available for the user.
249252
if ( StringUtils.isEmpty( repositoryId ) )
250253
{
251254
List<String> userRepos = userRepositories.getObservableRepositoryIds( getPrincipal() );
255+
log.debug( "Available repositories: {}", StringUtils.join( userRepos, "," ) );
252256
// is it a good one? if yes nothing to
253257
// if not search the repo who is proxy for this remote
258+
boolean found = false;
254259
if ( !userRepos.contains( artifact.getContext() ) )
255260
{
256261
for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorAdmin.getProxyConnectorAsMap().entrySet() )
@@ -262,8 +267,16 @@ protected String getArtifactUrl( Artifact artifact, String repositoryId )
262267
&& userRepos.contains( entry.getKey() ) )
263268
{
264269
sb.append( '/' ).append( entry.getKey() );
270+
found = true;
271+
break;
265272
}
266273
}
274+
if (found) {
275+
break;
276+
}
277+
}
278+
if (!found) {
279+
sb.append( '/' ).append( artifact.getRepositoryId( ) );
267280
}
268281

269282
}

0 commit comments

Comments
 (0)