use configured applicationUrl for download urls

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1342819 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-05-25 21:46:38 +00:00
parent 23bd07d564
commit eccbf5b9c1
4 changed files with 146 additions and 112 deletions

View File

@ -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();

View File

@ -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,6 +200,9 @@ public class DefaultManagedRepositoriesService
}
private String createSnippet( ManagedRepository repo )
throws ArchivaRestServiceException
{
try
{
StringBuilder snippet = new StringBuilder();
snippet.append( "<project>\n" );
@ -243,10 +247,12 @@ public class DefaultManagedRepositoriesService
}
snippet.append( " <releases>\n" );
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( "</enabled>\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( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append(
"</enabled>\n" );
snippet.append( " </snapshots>\n" );
snippet.append( " </repository>\n" );
snippet.append( " </repositories>\n" );
@ -267,10 +273,12 @@ public class DefaultManagedRepositoriesService
}
snippet.append( " <releases>\n" );
snippet.append( " <enabled>" ).append( Boolean.valueOf( repo.isReleases() ) ).append( "</enabled>\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( " <enabled>" ).append( Boolean.valueOf( repo.isSnapshots() ) ).append(
"</enabled>\n" );
snippet.append( " </snapshots>\n" );
snippet.append( " </pluginRepository>\n" );
snippet.append( " </pluginRepositories>\n" );
@ -280,4 +288,10 @@ public class DefaultManagedRepositoriesService
return StringEscapeUtils.escapeXml( snippet.toString() );
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
}
}

View File

@ -133,9 +133,6 @@ public class DefaultRepositoriesService
@Inject
private RepositoryContentFactory repositoryFactory;
@Inject
private ArchivaAdministration archivaAdministration;
@Inject
@Named( value = "archivaTaskScheduler#repository" )
private ArchivaTaskScheduler scheduler;

View File

@ -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,6 +243,9 @@ public class DefaultSearchService
* @return
*/
private String getArtifactUrl( Artifact artifact, String version )
throws ArchivaRestServiceException
{
try
{
if ( httpServletRequest == null )
@ -277,6 +283,12 @@ public class DefaultSearchService
return sb.toString();
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
}
}