diff options
author | Olivier Lamy <olamy@apache.org> | 2012-05-25 21:46:38 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-05-25 21:46:38 +0000 |
commit | eccbf5b9c1c7511886335a7c7932d85762864060 (patch) | |
tree | a6f475e441cce02e47df419846d1ee9fb5ee6072 /archiva-modules | |
parent | 23bd07d564f18ce27beea333c0328141b104dec7 (diff) | |
download | archiva-eccbf5b9c1c7511886335a7c7932d85762864060.tar.gz archiva-eccbf5b9c1c7511886335a7c7932d85762864060.zip |
use configured applicationUrl for download urls
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1342819 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
4 files changed, 137 insertions, 103 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java index 089d15060..3726b6af5 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java @@ -19,18 +19,20 @@ package org.apache.archiva.rest.services; */ import org.apache.archiva.admin.model.AuditInformation; +import org.apache.archiva.admin.model.RepositoryAdminException; +import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.metadata.repository.RepositorySessionFactory; +import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal; +import org.apache.archiva.redback.rest.services.RedbackRequestInformation; +import org.apache.archiva.redback.users.User; +import org.apache.archiva.redback.users.UserManager; import org.apache.archiva.security.AccessDeniedException; import org.apache.archiva.security.ArchivaSecurityException; import org.apache.archiva.security.PrincipalNotFoundException; import org.apache.archiva.security.UserRepositories; import org.apache.commons.lang.StringUtils; -import org.apache.archiva.redback.users.User; -import org.apache.archiva.redback.users.UserManager; -import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal; -import org.apache.archiva.redback.rest.services.RedbackRequestInformation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; @@ -67,6 +69,9 @@ public abstract class AbstractRestService @Named( value = "repositorySessionFactory" ) protected RepositorySessionFactory repositorySessionFactory; + @Inject + protected ArchivaAdministration archivaAdministration; + @Context protected HttpServletRequest httpServletRequest; @@ -122,7 +127,13 @@ public abstract class AbstractRestService } protected String getBaseUrl( HttpServletRequest req ) + throws RepositoryAdminException { + String applicationUrl = archivaAdministration.getUiConfiguration().getApplicationUrl(); + if ( StringUtils.isNotBlank( applicationUrl ) ) + { + return applicationUrl; + } return req.getScheme() + "://" + req.getServerName() + ( req.getServerPort() == 80 ? "" : ":" + req.getServerPort() ) + req.getContextPath(); diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java index 518311d63..417c7b048 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java @@ -36,6 +36,7 @@ import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import javax.inject.Inject; +import javax.ws.rs.core.Response; import java.io.File; import java.text.SimpleDateFormat; import java.util.Collections; @@ -199,85 +200,98 @@ public class DefaultManagedRepositoriesService } private String createSnippet( ManagedRepository repo ) + throws ArchivaRestServiceException { - StringBuilder snippet = new StringBuilder(); - snippet.append( "<project>\n" ); - snippet.append( " ...\n" ); - snippet.append( " <distributionManagement>\n" ); - - String distRepoName = "repository"; - if ( repo.isSnapshots() ) + try { - distRepoName = "snapshotRepository"; - } + StringBuilder snippet = new StringBuilder(); + snippet.append( "<project>\n" ); + snippet.append( " ...\n" ); + snippet.append( " <distributionManagement>\n" ); - snippet.append( " <" ).append( distRepoName ).append( ">\n" ); - snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" ); - snippet.append( " <url>" ); - snippet.append( getBaseUrl( httpServletRequest ) + "/repository" ); - snippet.append( "/" ).append( repo.getId() ).append( "/" ).append( "</url>\n" ); + String distRepoName = "repository"; + if ( repo.isSnapshots() ) + { + distRepoName = "snapshotRepository"; + } - if ( !"default".equals( repo.getLayout() ) ) - { - snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>" ); - } + snippet.append( " <" ).append( distRepoName ).append( ">\n" ); + snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" ); + snippet.append( " <url>" ); + snippet.append( getBaseUrl( httpServletRequest ) + "/repository" ); + snippet.append( "/" ).append( repo.getId() ).append( "/" ).append( "</url>\n" ); - snippet.append( " </" ).append( distRepoName ).append( ">\n" ); - snippet.append( " </distributionManagement>\n" ); - snippet.append( "\n" ); + if ( !"default".equals( repo.getLayout() ) ) + { + snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>" ); + } - snippet.append( " <repositories>\n" ); - snippet.append( " <repository>\n" ); - snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" ); - snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" ); + snippet.append( " </" ).append( distRepoName ).append( ">\n" ); + snippet.append( " </distributionManagement>\n" ); + snippet.append( "\n" ); - snippet.append( " <url>" ); - snippet.append( getBaseUrl( httpServletRequest ) + "/repository" ); - snippet.append( "/" ).append( repo.getId() ).append( "/" ); + snippet.append( " <repositories>\n" ); + snippet.append( " <repository>\n" ); + snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" ); + snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" ); - snippet.append( "</url>\n" ); + snippet.append( " <url>" ); + snippet.append( getBaseUrl( httpServletRequest ) + "/repository" ); + snippet.append( "/" ).append( repo.getId() ).append( "/" ); - if ( !"default".equals( repo.getLayout() ) ) - { - snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" ); - } + snippet.append( "</url>\n" ); - snippet.append( " <releases>\n" ); - snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( "</enabled>\n" ); - snippet.append( " </releases>\n" ); - snippet.append( " <snapshots>\n" ); - snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append( "</enabled>\n" ); - snippet.append( " </snapshots>\n" ); - snippet.append( " </repository>\n" ); - snippet.append( " </repositories>\n" ); - snippet.append( " <pluginRepositories>\n" ); - snippet.append( " <pluginRepository>\n" ); - snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" ); - snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" ); - - snippet.append( " <url>" ); - snippet.append( getBaseUrl( httpServletRequest ) + "/repository" ); - snippet.append( "/" ).append( repo.getId() ).append( "/" ); - - snippet.append( "</url>\n" ); - - if ( !"default".equals( repo.getLayout() ) ) - { - snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" ); - } - - snippet.append( " <releases>\n" ); - snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( "</enabled>\n" ); - snippet.append( " </releases>\n" ); - snippet.append( " <snapshots>\n" ); - snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append( "</enabled>\n" ); - snippet.append( " </snapshots>\n" ); - snippet.append( " </pluginRepository>\n" ); - snippet.append( " </pluginRepositories>\n" ); + if ( !"default".equals( repo.getLayout() ) ) + { + snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" ); + } - snippet.append( " ...\n" ); - snippet.append( "</project>\n" ); + snippet.append( " <releases>\n" ); + snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( + "</enabled>\n" ); + snippet.append( " </releases>\n" ); + snippet.append( " <snapshots>\n" ); + snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append( + "</enabled>\n" ); + snippet.append( " </snapshots>\n" ); + snippet.append( " </repository>\n" ); + snippet.append( " </repositories>\n" ); + snippet.append( " <pluginRepositories>\n" ); + snippet.append( " <pluginRepository>\n" ); + snippet.append( " <id>" ).append( repo.getId() ).append( "</id>\n" ); + snippet.append( " <name>" ).append( repo.getName() ).append( "</name>\n" ); + + snippet.append( " <url>" ); + snippet.append( getBaseUrl( httpServletRequest ) + "/repository" ); + snippet.append( "/" ).append( repo.getId() ).append( "/" ); + + snippet.append( "</url>\n" ); + + if ( !"default".equals( repo.getLayout() ) ) + { + snippet.append( " <layout>" ).append( repo.getLayout() ).append( "</layout>\n" ); + } - return StringEscapeUtils.escapeXml( snippet.toString() ); + snippet.append( " <releases>\n" ); + snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( + "</enabled>\n" ); + snippet.append( " </releases>\n" ); + snippet.append( " <snapshots>\n" ); + snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append( + "</enabled>\n" ); + snippet.append( " </snapshots>\n" ); + snippet.append( " </pluginRepository>\n" ); + snippet.append( " </pluginRepositories>\n" ); + + snippet.append( " ...\n" ); + snippet.append( "</project>\n" ); + + return StringEscapeUtils.escapeXml( snippet.toString() ); + } + catch ( RepositoryAdminException e ) + { + throw new ArchivaRestServiceException( e.getMessage(), + Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); + } } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index e1d6bc613..4a25b5f87 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -134,9 +134,6 @@ public class DefaultRepositoriesService private RepositoryContentFactory repositoryFactory; @Inject - private ArchivaAdministration archivaAdministration; - - @Inject @Named( value = "archivaTaskScheduler#repository" ) private ArchivaTaskScheduler scheduler; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java index 863e76c12..47f4e8c97 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java @@ -20,6 +20,7 @@ package org.apache.archiva.rest.services; */ import net.sf.beanlib.provider.replicator.BeanReplicator; +import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.indexer.search.RepositorySearch; import org.apache.archiva.indexer.search.RepositorySearchException; import org.apache.archiva.indexer.search.SearchFields; @@ -38,6 +39,7 @@ import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import javax.inject.Inject; +import javax.ws.rs.core.Response; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -202,6 +204,7 @@ public class DefaultSearchService // internal //------------------------------------- protected List<Artifact> getArtifacts( SearchResults searchResults ) + throws ArchivaRestServiceException { if ( searchResults == null || searchResults.isEmpty() ) @@ -240,42 +243,51 @@ public class DefaultSearchService * @return */ private String getArtifactUrl( Artifact artifact, String version ) + throws ArchivaRestServiceException { - - if ( httpServletRequest == null ) - { - return null; - } - if ( StringUtils.isEmpty( artifact.getUrl() ) ) + try { - return null; - } - StringBuilder sb = new StringBuilder( getBaseUrl( httpServletRequest ) ); - sb.append( "/repository" ); + if ( httpServletRequest == null ) + { + return null; + } + if ( StringUtils.isEmpty( artifact.getUrl() ) ) + { + return null; + } + StringBuilder sb = new StringBuilder( getBaseUrl( httpServletRequest ) ); - sb.append( '/' ).append( artifact.getContext() ); + sb.append( "/repository" ); - sb.append( '/' ).append( StringUtils.replaceChars( artifact.getGroupId(), '.', '/' ) ); - sb.append( '/' ).append( artifact.getArtifactId() ); - sb.append( '/' ).append( artifact.getVersion() ); - sb.append( '/' ).append( artifact.getArtifactId() ); - sb.append( '-' ).append( artifact.getVersion() ); - if ( StringUtils.isNotBlank( artifact.getClassifier() ) ) - { - sb.append( '-' ).append( artifact.getClassifier() ); - } - // maven-plugin packaging is a jar - if ( StringUtils.equals( "maven-plugin", artifact.getPackaging() ) ) - { - sb.append( "jar" ); + sb.append( '/' ).append( artifact.getContext() ); + + sb.append( '/' ).append( StringUtils.replaceChars( artifact.getGroupId(), '.', '/' ) ); + sb.append( '/' ).append( artifact.getArtifactId() ); + sb.append( '/' ).append( artifact.getVersion() ); + sb.append( '/' ).append( artifact.getArtifactId() ); + sb.append( '-' ).append( artifact.getVersion() ); + if ( StringUtils.isNotBlank( artifact.getClassifier() ) ) + { + sb.append( '-' ).append( artifact.getClassifier() ); + } + // maven-plugin packaging is a jar + if ( StringUtils.equals( "maven-plugin", artifact.getPackaging() ) ) + { + sb.append( "jar" ); + } + else + { + sb.append( '.' ).append( artifact.getPackaging() ); + } + + return sb.toString(); } - else + catch ( RepositoryAdminException e ) { - sb.append( '.' ).append( artifact.getPackaging() ); + throw new ArchivaRestServiceException( e.getMessage(), + Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); } - - return sb.toString(); } |