summaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorolivier lamy <olamy@apache.org>2016-10-05 14:31:48 +1100
committerolivier lamy <olamy@apache.org>2016-10-05 14:31:48 +1100
commitc4596cb59135d4d1f284f98e9bd1ca267bee289f (patch)
tree90788c96a82cb62eb1e9a334ae09755f7ba41d9e /archiva-modules
parent70323bbefbc70103cfe58deeb0816c2e961d2d78 (diff)
parentef0f29235d7d5ebecf3f60accf2c76bcb7c8230b (diff)
downloadarchiva-c4596cb59135d4d1f284f98e9bd1ca267bee289f.tar.gz
archiva-c4596cb59135d4d1f284f98e9bd1ca267bee289f.zip
Merge branch 'pr/28'
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java14
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletProxiedMetadataTestCase.java40
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java31
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletNoProxyTest.java40
4 files changed, 82 insertions, 43 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
index 93547c0d9..d4958b113 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
@@ -47,7 +47,6 @@ import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.proxy.model.RepositoryProxyConnectors;
-import org.apache.archiva.proxy.model.ProxyFetchResult;
import org.apache.archiva.redback.authentication.AuthenticationException;
import org.apache.archiva.redback.authentication.AuthenticationResult;
import org.apache.archiva.redback.authorization.AuthorizationException;
@@ -577,8 +576,7 @@ public class ArchivaDavResourceFactory
String path = e.getPath();
log.debug( "Relocation to {}", path );
- throw new BrowserRedirectException( contextPath + ( StringUtils.startsWith( path, "/" ) ? "" : "/" ) + path,
- e.getRelocationType() );
+ throw new BrowserRedirectException( addHrefPrefix( contextPath, path ), e.getRelocationType() );
}
catch ( XMLException e )
{
@@ -935,6 +933,16 @@ public class ArchivaDavResourceFactory
return archivaLocator;
}
+ private String addHrefPrefix( String contextPath, String path ) {
+ String prefix = archivaConfiguration.getConfiguration().getWebapp().getUi().getApplicationUrl();
+ if (prefix == null || prefix.isEmpty()) {
+ prefix = contextPath;
+ }
+ return prefix + ( StringUtils.startsWith( path, "/" ) ? "" :
+ ( StringUtils.endsWith( prefix, "/" ) ? "" : "/" ) )
+ + path;
+ }
+
private static class LogicalResource
{
private String path;
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletProxiedMetadataTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletProxiedMetadataTestCase.java
index 58ce852a3..eb7bd3637 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletProxiedMetadataTestCase.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletProxiedMetadataTestCase.java
@@ -62,46 +62,6 @@ public abstract class AbstractRepositoryServletProxiedMetadataTestCase
return response.getContentAsString();
}
- protected String createVersionMetadata( String groupId, String artifactId, String version )
- {
- return createVersionMetadata( groupId, artifactId, version, null, null, null );
- }
-
- protected String createVersionMetadata( String groupId, String artifactId, String version, String timestamp,
- String buildNumber, String lastUpdated )
- {
- StringBuilder buf = new StringBuilder();
-
- buf.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" );
- buf.append( "<metadata>\n" );
- buf.append( " <groupId>" ).append( groupId ).append( "</groupId>\n" );
- buf.append( " <artifactId>" ).append( artifactId ).append( "</artifactId>\n" );
- buf.append( " <version>" ).append( version ).append( "</version>\n" );
-
- boolean hasSnapshot = StringUtils.isNotBlank( timestamp ) || StringUtils.isNotBlank( buildNumber );
- boolean hasLastUpdated = StringUtils.isNotBlank( lastUpdated );
-
- if ( hasSnapshot || hasLastUpdated )
- {
- buf.append( " <versioning>\n" );
- if ( hasSnapshot )
- {
- buf.append( " <snapshot>\n" );
- buf.append( " <buildNumber>" ).append( buildNumber ).append( "</buildNumber>\n" );
- buf.append( " <timestamp>" ).append( timestamp ).append( "</timestamp>\n" );
- buf.append( " </snapshot>\n" );
- }
- if ( hasLastUpdated )
- {
- buf.append( " <lastUpdated>" ).append( lastUpdated ).append( "</lastUpdated>\n" );
- }
- buf.append( " </versioning>\n" );
- }
- buf.append( "</metadata>" );
-
- return buf.toString();
- }
-
protected String createProjectMetadata( String groupId, String artifactId, String latest, String release,
String[] versions )
{
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
index 68b0535dc..6c87d82ad 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
@@ -75,6 +75,7 @@ import java.net.URL;
import java.nio.charset.Charset;
import java.util.Locale;
import java.util.Map;
+import org.apache.commons.lang.StringUtils;
/**
* AbstractRepositoryServletTestCase
@@ -180,6 +181,36 @@ public abstract class AbstractRepositoryServletTestCase
}
+ protected String createVersionMetadata(String groupId, String artifactId, String version) {
+ return createVersionMetadata(groupId, artifactId, version, null, null, null);
+ }
+
+ protected String createVersionMetadata(String groupId, String artifactId, String version, String timestamp, String buildNumber, String lastUpdated) {
+ StringBuilder buf = new StringBuilder();
+ buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
+ buf.append("<metadata>\n");
+ buf.append(" <groupId>").append(groupId).append("</groupId>\n");
+ buf.append(" <artifactId>").append(artifactId).append("</artifactId>\n");
+ buf.append(" <version>").append(version).append("</version>\n");
+ boolean hasSnapshot = StringUtils.isNotBlank(timestamp) || StringUtils.isNotBlank(buildNumber);
+ boolean hasLastUpdated = StringUtils.isNotBlank(lastUpdated);
+ if (hasSnapshot || hasLastUpdated) {
+ buf.append(" <versioning>\n");
+ if (hasSnapshot) {
+ buf.append(" <snapshot>\n");
+ buf.append(" <buildNumber>").append(buildNumber).append("</buildNumber>\n");
+ buf.append(" <timestamp>").append(timestamp).append("</timestamp>\n");
+ buf.append(" </snapshot>\n");
+ }
+ if (hasLastUpdated) {
+ buf.append(" <lastUpdated>").append(lastUpdated).append("</lastUpdated>\n");
+ }
+ buf.append(" </versioning>\n");
+ }
+ buf.append("</metadata>");
+ return buf.toString();
+ }
+
public static class TestWebapplicationContext
implements WebApplicationContext
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletNoProxyTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletNoProxyTest.java
index 004d16d26..cb862676a 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletNoProxyTest.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletNoProxyTest.java
@@ -30,6 +30,9 @@ import org.junit.Test;
import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
+import javax.servlet.http.HttpServletResponse;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
/**
* RepositoryServletTest
@@ -534,4 +537,41 @@ public class RepositoryServletNoProxyTest
assertResponseNotFound( response );
}
+ @Test
+ public void testGetNoProxySnapshotRedirectToTimestampedSnapshot()
+ throws Exception
+ {
+ String commonsLangQuery = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
+ String commonsLangMetadata = "commons-lang/commons-lang/2.1-SNAPSHOT/maven-metadata.xml";
+ String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
+ String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+ archivaConfiguration.getConfiguration().getWebapp().getUi().setApplicationUrl("http://localhost");
+
+ File artifactFile = new File( repoRootInternal, commonsLangJar );
+ artifactFile.getParentFile().mkdirs();
+ FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
+
+ File metadataFile = new File( repoRootInternal, commonsLangMetadata );
+ metadataFile.getParentFile().mkdirs();
+ FileUtils.writeStringToFile( metadataFile, createVersionMetadata("commons-lang", "commons-lang",
+ "2.1-SNAPSHOT", "20050821.023400", "1", "20050821.023400"));
+
+ WebRequest webRequest = new GetMethodWebRequest(
+ "http://localhost/repository/internal/" + commonsLangQuery );
+
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ request.setRequestURI( webRequest.getUrl().getPath() );
+ request.addHeader( "User-Agent", "Apache Archiva unit test" );
+ request.setMethod( webRequest.getHttpMethod().name() );
+
+ final MockHttpServletResponse response = execute( request );
+
+ assertEquals( HttpServletResponse.SC_MOVED_TEMPORARILY,
+ response.getStatus() );
+
+ assertEquals( "http://localhost/repository/internal/" + commonsLangJar,
+ response.getHeader("Location") );
+ }
+
}