]> source.dussan.org Git - archiva.git/commitdiff
use a temporary redirect for SNAPSHOT download
authorOlivier Lamy <olamy@apache.org>
Mon, 9 Dec 2013 11:22:27 +0000 (11:22 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 9 Dec 2013 11:22:27 +0000 (11:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1549551 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java

index beb08e2c50eb4d8aa8280d02834478a26cf43029..e24df205ea401b64028e9e443e74357d31c69abc 100644 (file)
@@ -528,7 +528,7 @@ public class ArchivaDavResourceFactory
         return path;
     }
 
-    private String evaluatePathWithVersion( ArchivaDavResourceLocator archivaLocator, ManagedRepositoryContent managedRepositoryContent )
+    private String evaluatePathWithVersion( ArchivaDavResourceLocator archivaLocator, ManagedRepositoryContent managedRepositoryContent, String contextPath )
         throws DavException
     {
         String layout = managedRepositoryContent.getRepository() == null ? new ManagedRepository( ).getLayout() : managedRepositoryContent.getRepository().getLayout();
@@ -540,8 +540,10 @@ public class ArchivaDavResourceFactory
         }
         catch ( RelocationException e )
         {
-            log.debug( "Relocation to {}", e.getPath() );
-            throw new BrowserRedirectException( e.getPath(), e.getRelocationType() );
+            String path = e.getPath();
+            log.debug( "Relocation to {}", path );
+
+            throw new BrowserRedirectException(contextPath + ( StringUtils.startsWith( path, "/" ) ? "": "/" ) + path, e.getRelocationType() );
         }
         catch ( XMLException e )
         {
@@ -559,7 +561,7 @@ public class ArchivaDavResourceFactory
         if ( isAuthorized( request, managedRepositoryContent.getId() ) )
         {
             // Maven Centric part ask evaluation if -SNAPSHOT
-            String path = evaluatePathWithVersion(archivaLocator, managedRepositoryContent);
+            String path = evaluatePathWithVersion(archivaLocator, managedRepositoryContent, request.getContextPath());
             if ( path.startsWith( "/" ) )
             {
                 path = path.substring( 1 );
index 20b1ad8e33d7df9ef49b01129c961dd3b30bbeb6..573e93e2bbcfd252b85aa5c57bff1ed12465ccb2 100644 (file)
@@ -240,8 +240,9 @@ public class ArchivaDavResourceFactoryTest
 
             expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
 
-            expect( repoRequest.isSupportFile(
-                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
+            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+
+            expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
 
             expect(
                 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( repoRequest.isSupportFile(
-                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
+            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+
+            expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
 
             expect(
                 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( repoRequest.isSupportFile(
-                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
+            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+
+            expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
 
             expect(
                 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.getContextPath() ).andReturn( "" ).times( 1 );
+
             expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
 
             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.getContextPath() ).andReturn( "" ).times( 2 );
+
             archivaConfigurationControl.replay();
             repoContentFactoryControl.replay();
             requestControl.replay();
@@ -579,6 +586,8 @@ public class ArchivaDavResourceFactoryTest
 
             expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
 
+            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+
             archivaConfigurationControl.replay();
             repoContentFactoryControl.replay();
             requestControl.replay();