backend layer. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1401841 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.4-M4
@@ -565,6 +565,26 @@ | |||
</description> | |||
<defaultValue>false</defaultValue> | |||
</field> | |||
<field> | |||
<name>extraParameters</name> | |||
<version>1.4.0+</version> | |||
<type>Map</type> | |||
<description>Additionnal request parameters to add to url when requesting remote repositories.</description> | |||
<association xml.mapStyle="inline"> | |||
<type>String</type> | |||
<multiplicity>*</multiplicity> | |||
</association> | |||
</field> | |||
<field> | |||
<name>extraHeaders</name> | |||
<version>1.4.0+</version> | |||
<type>Map</type> | |||
<description>Additionnal http headers to add to url when requesting remote repositories.</description> | |||
<association xml.mapStyle="inline"> | |||
<type>String</type> | |||
<multiplicity>*</multiplicity> | |||
</association> | |||
</field> | |||
</fields> | |||
<codeSegments> | |||
<codeSegment> |
@@ -21,12 +21,14 @@ package org.apache.archiva.admin.model.beans; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import java.io.Serializable; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
/** | |||
* @author Olivier Lamy | |||
* @since 1.4-M1 | |||
*/ | |||
@XmlRootElement ( name = "remoteRepository" ) | |||
@XmlRootElement (name = "remoteRepository") | |||
public class RemoteRepository | |||
extends AbstractRepository | |||
implements Serializable | |||
@@ -64,6 +66,20 @@ public class RemoteRepository | |||
*/ | |||
private boolean downloadRemoteIndexOnStartup = false; | |||
/** | |||
* extraParameters. | |||
* | |||
* @since 1.4-M4 | |||
*/ | |||
private Map<String, String> extraParameters; | |||
/** | |||
* extraHeaders. | |||
* | |||
* @since 1.4-M4 | |||
*/ | |||
private Map<String, String> extraHeaders; | |||
public RemoteRepository() | |||
{ | |||
@@ -196,10 +212,39 @@ public class RemoteRepository | |||
this.downloadRemoteIndexOnStartup = downloadRemoteIndexOnStartup; | |||
} | |||
public Map<String, String> getExtraParameters() | |||
{ | |||
if ( this.extraParameters == null ) | |||
{ | |||
this.extraParameters = new HashMap<String, String>(); | |||
} | |||
return extraParameters; | |||
} | |||
public void setExtraParameters( Map<String, String> extraParameters ) | |||
{ | |||
this.extraParameters = extraParameters; | |||
} | |||
public Map<String, String> getExtraHeaders() | |||
{ | |||
if ( this.extraHeaders == null ) | |||
{ | |||
this.extraHeaders = new HashMap<String, String>(); | |||
} | |||
return extraHeaders; | |||
} | |||
public void setExtraHeaders( Map<String, String> extraHeaders ) | |||
{ | |||
this.extraHeaders = extraHeaders; | |||
} | |||
@Override | |||
public String toString() | |||
{ | |||
final StringBuilder sb = new StringBuilder(); | |||
sb.append( super.toString() ); | |||
sb.append( "RemoteRepository" ); | |||
sb.append( "{url='" ).append( url ).append( '\'' ); | |||
sb.append( ", userName='" ).append( userName ).append( '\'' ); | |||
@@ -211,6 +256,8 @@ public class RemoteRepository | |||
sb.append( ", cronExpression='" ).append( cronExpression ).append( '\'' ); | |||
sb.append( ", remoteDownloadTimeout=" ).append( remoteDownloadTimeout ); | |||
sb.append( ", downloadRemoteIndexOnStartup=" ).append( downloadRemoteIndexOnStartup ); | |||
sb.append( ", extraParameters=" ).append( extraParameters ); | |||
sb.append( ", extraHeaders=" ).append( extraHeaders ); | |||
sb.append( '}' ); | |||
return sb.toString(); | |||
} |
@@ -134,6 +134,8 @@ public class DefaultRemoteRepositoryAdmin | |||
remoteRepository.setDownloadRemoteIndexOnStartup( | |||
repositoryConfiguration.isDownloadRemoteIndexOnStartup() ); | |||
remoteRepository.setDescription( repositoryConfiguration.getDescription() ); | |||
remoteRepository.setExtraHeaders( repositoryConfiguration.getExtraHeaders() ); | |||
remoteRepository.setExtraParameters( repositoryConfiguration.getExtraParameters() ); | |||
remoteRepositories.add( remoteRepository ); | |||
} | |||
return remoteRepositories; | |||
@@ -356,6 +358,8 @@ public class DefaultRemoteRepositoryAdmin | |||
remoteRepositoryConfiguration.setDownloadRemoteIndexOnStartup( | |||
remoteRepository.isDownloadRemoteIndexOnStartup() ); | |||
remoteRepositoryConfiguration.setDescription( remoteRepository.getDescription() ); | |||
remoteRepositoryConfiguration.setExtraHeaders( remoteRepository.getExtraHeaders() ); | |||
remoteRepositoryConfiguration.setExtraParameters( remoteRepository.getExtraParameters() ); | |||
return remoteRepositoryConfiguration; | |||
} | |||
@@ -27,11 +27,12 @@ import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; | |||
import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin; | |||
import org.apache.archiva.admin.model.proxyconnectorrule.ProxyConnectorRuleAdmin; | |||
import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin; | |||
import org.apache.archiva.redback.role.RoleManager; | |||
import org.apache.archiva.redback.users.User; | |||
import org.apache.archiva.redback.users.memory.SimpleUser; | |||
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; | |||
import org.apache.commons.io.FileUtils; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.apache.archiva.redback.role.RoleManager; | |||
import org.apache.archiva.redback.users.memory.SimpleUser; | |||
import org.junit.runner.RunWith; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
@@ -39,20 +40,22 @@ import org.springframework.test.context.ContextConfiguration; | |||
import javax.inject.Inject; | |||
import java.io.File; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; | |||
import java.util.Map; | |||
/** | |||
* @author Olivier Lamy | |||
*/ | |||
@RunWith( ArchivaSpringJUnit4ClassRunner.class ) | |||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) | |||
@RunWith (ArchivaSpringJUnit4ClassRunner.class) | |||
@ContextConfiguration (locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" }) | |||
public abstract class AbstractRepositoryAdminTest | |||
extends TestCase | |||
{ | |||
protected Logger log = LoggerFactory.getLogger( getClass() ); | |||
public static final String APPSERVER_BASE_PATH = AbstractRepositoryAdminTest.fixPath( System.getProperty( "appserver.base" ) ); | |||
public static final String APPSERVER_BASE_PATH = | |||
AbstractRepositoryAdminTest.fixPath( System.getProperty( "appserver.base" ) ); | |||
@Inject | |||
protected MockAuditListener mockAuditListener; | |||
@@ -77,19 +80,20 @@ public abstract class AbstractRepositoryAdminTest | |||
AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" ); | |||
return auditInformation; | |||
} | |||
// make a nice repo path to allow unit test to run | |||
private static String fixPath ( String path ) | |||
// make a nice repo path to allow unit test to run | |||
private static String fixPath( String path ) | |||
{ | |||
String SPACE = " "; | |||
if ( path.contains( SPACE ) ) | |||
{ | |||
LoggerFactory.getLogger( AbstractRepositoryAdminTest.class.getName() ).error( | |||
"You are building and testing with {appserver.base}: \n " + path + " containing space. Consider relocating." ); | |||
LoggerFactory.getLogger( AbstractRepositoryAdminTest.class.getName() ).error( | |||
"You are building and testing with {appserver.base}: \n " + path | |||
+ " containing space. Consider relocating." ); | |||
} | |||
return path.replaceAll( SPACE, "&20"); | |||
return path.replaceAll( SPACE, "&20" ); | |||
} | |||
protected User getFakeUser() | |||
{ | |||
SimpleUser user = new SimpleUser() | |||
@@ -142,7 +146,7 @@ public abstract class AbstractRepositoryAdminTest | |||
return getRemoteRepository( "foo" ); | |||
} | |||
protected RemoteRepository getRemoteRepository(String id) | |||
protected RemoteRepository getRemoteRepository( String id ) | |||
{ | |||
RemoteRepository remoteRepository = new RemoteRepository(); | |||
remoteRepository.setUrl( "http://foo.com/maven-it-rocks" ); | |||
@@ -153,6 +157,12 @@ public abstract class AbstractRepositoryAdminTest | |||
remoteRepository.setId( id ); | |||
remoteRepository.setRemoteDownloadNetworkProxyId( "foo" ); | |||
remoteRepository.setDescription( "cool apache repo" ); | |||
Map<String, String> extraParameters = new HashMap<String, String>(); | |||
extraParameters.put( "foo", "bar" ); | |||
remoteRepository.setExtraParameters( extraParameters ); | |||
Map<String, String> extraHeaders = new HashMap<String, String>(); | |||
extraHeaders.put( "beer", "wine" ); | |||
remoteRepository.setExtraHeaders( extraHeaders ); | |||
return remoteRepository; | |||
} | |||
} |
@@ -75,6 +75,11 @@ public class RemoteRepositoryAdminTest | |||
assertEquals( getRemoteRepository().getName(), repo.getName() ); | |||
assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() ); | |||
assertEquals( getRemoteRepository().getDescription(), repo.getDescription() ); | |||
assertEquals( 1, remoteRepository.getExtraHeaders().size() ); | |||
assertEquals( "wine", remoteRepository.getExtraHeaders().get( "beer" ) ); | |||
assertEquals( 1, remoteRepository.getExtraParameters().size() ); | |||
assertEquals( "bar", remoteRepository.getExtraParameters().get( "foo" ) ); | |||
remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() ); | |||