diff options
author | Martin Stockhammer <martin_s@apache.org> | 2017-05-07 17:26:49 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2017-05-10 21:39:15 +0200 |
commit | 1acc6e7b8439b482e611392700f2decaef54b6e6 (patch) | |
tree | fc98db8d5433006bb83e4389f1dfc7f6ddf8ebdf /archiva-modules/archiva-web/archiva-rest | |
parent | 10b408249ea9d8e2d63054ba95714e3a628ca782 (diff) | |
download | archiva-1acc6e7b8439b482e611392700f2decaef54b6e6.tar.gz archiva-1acc6e7b8439b482e611392700f2decaef54b6e6.zip |
Adding check path to remote repositories
Allow to set a check path for connection checks to the remote repositories.
This is useful for repositories that do not allow to browse the base directory.
Improved the fix for MRM-1933
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest')
-rw-r--r-- | archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java | 182 |
1 files changed, 68 insertions, 114 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java index a6b341aa7..59358dddf 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRemoteRepositoriesService.java @@ -54,8 +54,7 @@ import java.util.Map; @Service( "remoteRepositoriesService#rest" ) public class DefaultRemoteRepositoriesService extends AbstractRestService - implements RemoteRepositoriesService -{ + implements RemoteRepositoriesService { @Inject private RemoteRepositoryAdmin remoteRepositoryAdmin; @@ -70,42 +69,26 @@ public class DefaultRemoteRepositoriesService int checkReadTimeout = 10000; 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 public List<RemoteRepository> getRemoteRepositories() - throws ArchivaRestServiceException - { - try - { + throws ArchivaRestServiceException { + try { List<RemoteRepository> remoteRepositories = remoteRepositoryAdmin.getRemoteRepositories(); return remoteRepositories == null ? Collections.<RemoteRepository>emptyList() : remoteRepositories; - } - catch ( RepositoryAdminException e ) - { - log.error( e.getMessage(), e ); - throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName(), e ); + } catch (RepositoryAdminException e) { + log.error(e.getMessage(), e); + throw new ArchivaRestServiceException(e.getMessage(), e.getFieldName(), e); } } @Override - public RemoteRepository getRemoteRepository( String repositoryId ) - throws ArchivaRestServiceException - { + public RemoteRepository getRemoteRepository(String repositoryId) + throws ArchivaRestServiceException { List<RemoteRepository> remoteRepositories = getRemoteRepositories(); - for ( RemoteRepository repository : remoteRepositories ) - { - if ( StringUtils.equals( repositoryId, repository.getId() ) ) - { + for (RemoteRepository repository : remoteRepositories) { + if (StringUtils.equals(repositoryId, repository.getId())) { return repository; } } @@ -113,109 +96,91 @@ public class DefaultRemoteRepositoriesService } @Override - public Boolean deleteRemoteRepository( String repositoryId ) - throws ArchivaRestServiceException - { - try - { - return remoteRepositoryAdmin.deleteRemoteRepository( repositoryId, getAuditInformation() ); - } - catch ( RepositoryAdminException e ) - { - log.error( e.getMessage(), e ); - throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName(), e ); + public Boolean deleteRemoteRepository(String repositoryId) + throws ArchivaRestServiceException { + try { + return remoteRepositoryAdmin.deleteRemoteRepository(repositoryId, getAuditInformation()); + } catch (RepositoryAdminException e) { + log.error(e.getMessage(), e); + throw new ArchivaRestServiceException(e.getMessage(), e.getFieldName(), e); } } @Override - public Boolean addRemoteRepository( RemoteRepository remoteRepository ) - throws ArchivaRestServiceException - { - try - { - return remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getAuditInformation() ); - } - catch ( RepositoryAdminException e ) - { - log.error( e.getMessage(), e ); - throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName(), e ); + public Boolean addRemoteRepository(RemoteRepository remoteRepository) + throws ArchivaRestServiceException { + try { + return remoteRepositoryAdmin.addRemoteRepository(remoteRepository, getAuditInformation()); + } catch (RepositoryAdminException e) { + log.error(e.getMessage(), e); + throw new ArchivaRestServiceException(e.getMessage(), e.getFieldName(), e); } } @Override - public Boolean updateRemoteRepository( RemoteRepository remoteRepository ) - throws ArchivaRestServiceException - { - try - { - return remoteRepositoryAdmin.updateRemoteRepository( remoteRepository, getAuditInformation() ); - } - catch ( RepositoryAdminException e ) - { - log.error( e.getMessage(), e ); - throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName(), e ); + public Boolean updateRemoteRepository(RemoteRepository remoteRepository) + throws ArchivaRestServiceException { + try { + return remoteRepositoryAdmin.updateRemoteRepository(remoteRepository, getAuditInformation()); + } catch (RepositoryAdminException e) { + log.error(e.getMessage(), e); + throw new ArchivaRestServiceException(e.getMessage(), e.getFieldName(), e); } } @Override - public Boolean checkRemoteConnectivity( String repositoryId ) - throws ArchivaRestServiceException - { - try - { - RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository( repositoryId ); - if ( remoteRepository == null ) - { - log.warn( "ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId ); + public Boolean checkRemoteConnectivity(String repositoryId) + throws ArchivaRestServiceException { + try { + RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository(repositoryId); + if (remoteRepository == null) { + log.warn("ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId); return Boolean.FALSE; } NetworkProxy networkProxy = null; - if ( StringUtils.isNotBlank( remoteRepository.getRemoteDownloadNetworkProxyId() ) ) - { - networkProxy = networkProxyAdmin.getNetworkProxy( remoteRepository.getRemoteDownloadNetworkProxyId() ); - if ( networkProxy == null ) - { + if (StringUtils.isNotBlank(remoteRepository.getRemoteDownloadNetworkProxyId())) { + networkProxy = networkProxyAdmin.getNetworkProxy(remoteRepository.getRemoteDownloadNetworkProxyId()); + if (networkProxy == null) { log.warn( - "your remote repository is configured to download remote index trought a proxy we cannot find id:{}", - remoteRepository.getRemoteDownloadNetworkProxyId() ); + "your remote repository is configured to download remote index trought a proxy we cannot find id:{}", + remoteRepository.getRemoteDownloadNetworkProxyId()); } } - String wagonProtocol = new URL( remoteRepository.getUrl() ).getProtocol(); + String wagonProtocol = new URL(remoteRepository.getUrl()).getProtocol(); final Wagon wagon = - wagonFactory.getWagon( new WagonFactoryRequest( wagonProtocol, remoteRepository.getExtraHeaders() ) // - .networkProxy( networkProxy ) ); + wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()) // + .networkProxy(networkProxy)); // hardcoded value as it's a check of the remote repo connectivity - wagon.setReadTimeout( checkReadTimeout ); - wagon.setTimeout( checkTimeout ); + wagon.setReadTimeout(checkReadTimeout); + wagon.setTimeout(checkTimeout); - if ( wagon instanceof AbstractHttpClientWagon ) - { + if (wagon instanceof AbstractHttpClientWagon) { HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration() // - .setUsePreemptive( true ) // - .setReadTimeout( checkReadTimeout ); - HttpConfiguration httpConfiguration = new HttpConfiguration().setGet( httpMethodConfiguration ); - AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration ); + .setUsePreemptive(true) // + .setReadTimeout(checkReadTimeout); + HttpConfiguration httpConfiguration = new HttpConfiguration().setGet(httpMethodConfiguration); + AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration); } - + ProxyInfo proxyInfo = null; - if ( networkProxy != null ) - { + if (networkProxy != null) { proxyInfo = new ProxyInfo(); - proxyInfo.setType( networkProxy.getProtocol() ); - proxyInfo.setHost( networkProxy.getHost() ); - proxyInfo.setPort( networkProxy.getPort() ); - proxyInfo.setUserName( networkProxy.getUsername() ); - proxyInfo.setPassword( networkProxy.getPassword() ); - } - String url = StringUtils.stripEnd(remoteRepository.getUrl(),"/"); - wagon.connect( new Repository( remoteRepository.getId(), url ), proxyInfo ); + proxyInfo.setType(networkProxy.getProtocol()); + proxyInfo.setHost(networkProxy.getHost()); + proxyInfo.setPort(networkProxy.getPort()); + proxyInfo.setUserName(networkProxy.getUsername()); + proxyInfo.setPassword(networkProxy.getPassword()); + } + String url = StringUtils.stripEnd(remoteRepository.getUrl(), "/"); + wagon.connect(new Repository(remoteRepository.getId(), url), proxyInfo); // MRM-1933, there are certain servers that do not allow browsing - if (remoteConnectivityCheckPaths.containsKey(url)) { - return wagon.resourceExists(remoteConnectivityCheckPaths.get(url)); + if (!(StringUtils.isEmpty(remoteRepository.getCheckPath()) || + "/".equals(remoteRepository.getCheckPath()))) { + return wagon.resourceExists(remoteRepository.getCheckPath()); } else { // we only check connectivity as remote repo can be empty // MRM-1909: Wagon implementation appends a slash already @@ -223,14 +188,10 @@ public class DefaultRemoteRepositoriesService } return Boolean.TRUE; - } - catch ( TransferFailedException e ) - { - log.info( "TransferFailedException :{}", e.getMessage() ); + } catch (TransferFailedException e) { + log.info("TransferFailedException :{}", e.getMessage()); return Boolean.FALSE; - } - catch ( Exception e ) - { + } catch (Exception e) { // This service returns either true or false, Exception cannot be handled by the clients log.debug("Exception occured on connectivity test.", e); log.info("Connection exception: {}", e.getMessage()); @@ -255,11 +216,4 @@ public class DefaultRemoteRepositoriesService this.checkTimeout = checkTimeout; } - public Map<String, String> getRemoteConnectivityCheckPaths() { - return remoteConnectivityCheckPaths; - } - - public void setRemoteConnectivityCheckPaths(Map<String, String> remoteConnectivityCheckPaths) { - this.remoteConnectivityCheckPaths = remoteConnectivityCheckPaths; - } } |