use a temporary redirect for SNAPSHOT download

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1549551 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-12-09 11:22:27 +00:00
parent ab7ef5c73f
commit d1de91d824
2 changed files with 21 additions and 10 deletions

View File

@ -528,7 +528,7 @@ public class ArchivaDavResourceFactory
return path; return path;
} }
private String evaluatePathWithVersion( ArchivaDavResourceLocator archivaLocator, ManagedRepositoryContent managedRepositoryContent ) private String evaluatePathWithVersion( ArchivaDavResourceLocator archivaLocator, ManagedRepositoryContent managedRepositoryContent, String contextPath )
throws DavException throws DavException
{ {
String layout = managedRepositoryContent.getRepository() == null ? new ManagedRepository( ).getLayout() : managedRepositoryContent.getRepository().getLayout(); String layout = managedRepositoryContent.getRepository() == null ? new ManagedRepository( ).getLayout() : managedRepositoryContent.getRepository().getLayout();
@ -540,8 +540,10 @@ public class ArchivaDavResourceFactory
} }
catch ( RelocationException e ) catch ( RelocationException e )
{ {
log.debug( "Relocation to {}", e.getPath() ); String path = e.getPath();
throw new BrowserRedirectException( e.getPath(), e.getRelocationType() ); log.debug( "Relocation to {}", path );
throw new BrowserRedirectException(contextPath + ( StringUtils.startsWith( path, "/" ) ? "": "/" ) + path, e.getRelocationType() );
} }
catch ( XMLException e ) catch ( XMLException e )
{ {
@ -559,7 +561,7 @@ public class ArchivaDavResourceFactory
if ( isAuthorized( request, managedRepositoryContent.getId() ) ) if ( isAuthorized( request, managedRepositoryContent.getId() ) )
{ {
// Maven Centric part ask evaluation if -SNAPSHOT // Maven Centric part ask evaluation if -SNAPSHOT
String path = evaluatePathWithVersion(archivaLocator, managedRepositoryContent); String path = evaluatePathWithVersion(archivaLocator, managedRepositoryContent, request.getContextPath());
if ( path.startsWith( "/" ) ) if ( path.startsWith( "/" ) )
{ {
path = path.substring( 1 ); path = path.substring( 1 );

View File

@ -240,8 +240,9 @@ public class ArchivaDavResourceFactoryTest
expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
expect( repoRequest.isSupportFile( expect( request.getContextPath() ).andReturn( "" ).times( 2 );
"org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
expect( expect(
repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
@ -319,8 +320,9 @@ public class ArchivaDavResourceFactoryTest
expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
expect( repoRequest.isSupportFile( expect( request.getContextPath() ).andReturn( "" ).times( 2 );
"org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
expect( expect(
repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
@ -400,8 +402,9 @@ public class ArchivaDavResourceFactoryTest
expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 ); expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
expect( repoRequest.isSupportFile( expect( request.getContextPath() ).andReturn( "" ).times( 2 );
"org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
expect( expect(
repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
@ -469,6 +472,8 @@ public class ArchivaDavResourceFactoryTest
expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 ); expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
expect( request.getContextPath() ).andReturn( "" ).times( 1 );
expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" ); expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
@ -530,6 +535,8 @@ public class ArchivaDavResourceFactoryTest
expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
expect( request.getContextPath() ).andReturn( "" ).times( 2 );
archivaConfigurationControl.replay(); archivaConfigurationControl.replay();
repoContentFactoryControl.replay(); repoContentFactoryControl.replay();
requestControl.replay(); requestControl.replay();
@ -579,6 +586,8 @@ public class ArchivaDavResourceFactoryTest
expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 ); expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
expect( request.getContextPath() ).andReturn( "" ).times( 2 );
archivaConfigurationControl.replay(); archivaConfigurationControl.replay();
repoContentFactoryControl.replay(); repoContentFactoryControl.replay();
requestControl.replay(); requestControl.replay();