mirror of https://github.com/apache/archiva.git
MRM-1933, MRM-1940: Fixing repository check
Remove trailing slashes from the remote repositories Use special check paths for certain servers
This commit is contained in:
parent
b7c191b331
commit
2bf5154f13
|
@ -19,6 +19,8 @@ package org.apache.archiva.admin.model.beans;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -112,7 +114,7 @@ public class RemoteRepository
|
||||||
int timeout )
|
int timeout )
|
||||||
{
|
{
|
||||||
super( id, name, layout );
|
super( id, name, layout );
|
||||||
this.url = url;
|
this.url = StringUtils.stripEnd(url,"/");
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
|
@ -135,7 +137,7 @@ public class RemoteRepository
|
||||||
|
|
||||||
public void setUrl( String url )
|
public void setUrl( String url )
|
||||||
{
|
{
|
||||||
this.url = url;
|
this.url = StringUtils.stripEnd(url,"/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserName()
|
public String getUserName()
|
||||||
|
|
|
@ -38,11 +38,14 @@ import org.apache.maven.wagon.proxy.ProxyInfo;
|
||||||
import org.apache.maven.wagon.repository.Repository;
|
import org.apache.maven.wagon.repository.Repository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
|
@ -67,6 +70,16 @@ public class DefaultRemoteRepositoriesService
|
||||||
int checkReadTimeout = 10000;
|
int checkReadTimeout = 10000;
|
||||||
int checkTimeout = 9000;
|
int checkTimeout = 9000;
|
||||||
|
|
||||||
|
// TODO: make this configurable
|
||||||
|
private Map<String,String> remoteConnectivityCheckPaths = new HashMap<>();
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
// default initialization for known servers
|
||||||
|
remoteConnectivityCheckPaths.put("http://download.oracle.com/maven","com/sleepycat/je/license.txt");
|
||||||
|
remoteConnectivityCheckPaths.put("https://download.oracle.com/maven","com/sleepycat/je/license.txt");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<RemoteRepository> getRemoteRepositories()
|
public List<RemoteRepository> getRemoteRepositories()
|
||||||
throws ArchivaRestServiceException
|
throws ArchivaRestServiceException
|
||||||
|
@ -197,12 +210,17 @@ public class DefaultRemoteRepositoriesService
|
||||||
proxyInfo.setUserName( networkProxy.getUsername() );
|
proxyInfo.setUserName( networkProxy.getUsername() );
|
||||||
proxyInfo.setPassword( networkProxy.getPassword() );
|
proxyInfo.setPassword( networkProxy.getPassword() );
|
||||||
}
|
}
|
||||||
|
String url = StringUtils.stripEnd(remoteRepository.getUrl(),"/");
|
||||||
|
wagon.connect( new Repository( remoteRepository.getId(), url ), proxyInfo );
|
||||||
|
|
||||||
wagon.connect( new Repository( remoteRepository.getId(), remoteRepository.getUrl() ), proxyInfo );
|
// MRM-1933, there are certain servers that do not allow browsing
|
||||||
|
if (remoteConnectivityCheckPaths.containsKey(url)) {
|
||||||
|
return wagon.resourceExists(remoteConnectivityCheckPaths.get(url));
|
||||||
|
} else {
|
||||||
// we only check connectivity as remote repo can be empty
|
// we only check connectivity as remote repo can be empty
|
||||||
// MRM-1909: Wagon implementation appends a slash already
|
// MRM-1909: Wagon implementation appends a slash already
|
||||||
wagon.getFileList( "" );
|
wagon.getFileList("");
|
||||||
|
}
|
||||||
|
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
@ -213,8 +231,10 @@ public class DefaultRemoteRepositoriesService
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
throw new ArchivaRestServiceException( e.getMessage(),
|
// This service returns either true or false, Exception cannot be handled by the clients
|
||||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
|
log.debug("Exception occured on connectivity test.", e);
|
||||||
|
log.info("Connection exception: {}", e.getMessage());
|
||||||
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -234,4 +254,12 @@ public class DefaultRemoteRepositoriesService
|
||||||
public void setCheckTimeout(int checkTimeout) {
|
public void setCheckTimeout(int checkTimeout) {
|
||||||
this.checkTimeout = checkTimeout;
|
this.checkTimeout = checkTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getRemoteConnectivityCheckPaths() {
|
||||||
|
return remoteConnectivityCheckPaths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemoteConnectivityCheckPaths(Map<String, String> remoteConnectivityCheckPaths) {
|
||||||
|
this.remoteConnectivityCheckPaths = remoteConnectivityCheckPaths;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,10 +161,62 @@ public class RemoteRepositoriesServiceTest
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check maven repository
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void checkRemoteConnectivity2()
|
||||||
|
throws Exception {
|
||||||
|
RemoteRepositoriesService service = getRemoteRepositoriesService();
|
||||||
|
|
||||||
|
WebClient.client(service).header("Authorization", authorizationHeader);
|
||||||
|
|
||||||
|
int initialSize = service.getRemoteRepositories().size();
|
||||||
|
|
||||||
|
service.addRemoteRepository(getRemoteMavenRepository());
|
||||||
|
|
||||||
|
assertTrue(service.checkRemoteConnectivity("id-maven1"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check oracle repository that allows not browsing (MRM-1933)
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void checkRemoteConnectivity3()
|
||||||
|
throws Exception {
|
||||||
|
RemoteRepositoriesService service = getRemoteRepositoriesService();
|
||||||
|
|
||||||
|
WebClient.client(service).header("Authorization", authorizationHeader);
|
||||||
|
WebClient.client(service).accept("application/json");
|
||||||
|
|
||||||
|
int initialSize = service.getRemoteRepositories().size();
|
||||||
|
|
||||||
|
service.addRemoteRepository(getRemoteOracleRepository());
|
||||||
|
|
||||||
|
assertTrue(service.checkRemoteConnectivity("id-oracle"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
RemoteRepository getRemoteRepository()
|
RemoteRepository getRemoteRepository()
|
||||||
{
|
{
|
||||||
return new RemoteRepository( "id-new", "new one", "http://foo.com", "default", "foo", "foopassword", 120,
|
return new RemoteRepository( "id-new", "new one", "http://foo.com", "default", "foo", "foopassword", 120,
|
||||||
"cool repo" );
|
"cool repo" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RemoteRepository getRemoteMavenRepository()
|
||||||
|
{
|
||||||
|
return new RemoteRepository( "id-maven1", "Maven1", "http://repo.maven.apache.org/maven2", "default", "foo", "foopassword", 120,
|
||||||
|
"cool repo3" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RemoteRepository getRemoteOracleRepository()
|
||||||
|
{
|
||||||
|
return new RemoteRepository( "id-oracle", "Oracle", "http://download.oracle.com/maven", "default", "foo", "foopassword", 120,
|
||||||
|
"cool repo4" );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue