diff options
Diffstat (limited to 'archiva-modules/archiva-web')
4 files changed, 95 insertions, 118 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; - } } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties index e8013c5b3..122db4f3d 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties @@ -172,8 +172,9 @@ remoterepository.download.remote.full=Full download ? remoterepository.download.remote.scheduled=Download Remote Index of repository {0} scheduled. remoterepository.delete.confirm=Are you sure to delete Remote Repository {0} ? remoterepository.deleted=Remote repository {0}\u00c2\u00a0deleted. -remoteRepository.extraParametersEntries=Additionnal url parameters -remoteRepository.extraHeadersEntries=Additionnal Http Headers +remoteRepository.extraParametersEntries=Additional url parameters +remoteRepository.extraHeadersEntries=Additional Http Headers +remoteRepository.checkPath=Connection Check Path remoteRepository.timeout.help.title=Download Timeout remoteRepository.timeout.help.content=Timeout in secondes for downloading files from remote repository. remoteRepository.userName.help.title=Username @@ -197,6 +198,11 @@ remoteRepository.extraParametersEntries.help.content=Key/Value pair you want to remoteRepository.extraHeadersEntries.help.title=Extra HTTP Headers remoteRepository.extraHeadersEntries.help.content=Key/Value pair HTTP headers you want to add when asking the remote repository. remoterepository.remotecheck=Remote Check +remoteRepository.checkPath.help.title=Connection Check Path +remoteRepository.checkPath.help.content=Path relative to the repository URL that is used to check the connection to the \ + remote repository. Some repositories may not allow to browse the root directory. So if this path is set, the repository is \ + considered online if the resources exists. + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/admin/repository/maven2/repositories.js b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/admin/repository/maven2/repositories.js index 3a6cb5ff3..abfb373b3 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/admin/repository/maven2/repositories.js +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/archiva/admin/repository/maven2/repositories.js @@ -692,7 +692,7 @@ function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,ko) { RemoteRepository=function(id,name,layout,indexDirectory,url,userName,password,timeout,downloadRemoteIndex,remoteIndexUrl, remoteDownloadNetworkProxyId,cronExpression,remoteDownloadTimeout,downloadRemoteIndexOnStartup, - description,extraParametersEntries,extraHeadersEntries){ + description,extraParametersEntries,extraHeadersEntries,checkPath){ var self=this; @@ -774,6 +774,9 @@ function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,ko) { self.modified(true); }); + this.checkPath=ko.observable(checkPath); + this.checkPath.subscribe(function(newValue){self.modified(true)}); + this.modified=ko.observable(false); } @@ -799,7 +802,7 @@ function(jquery,i18n,jqueryTmpl,bootstrap,jqueryValidate,ko) { return new RemoteRepository(data.id,data.name,data.layout,data.indexDirectory,data.url,data.userName,data.password, data.timeout,data.downloadRemoteIndex,data.remoteIndexUrl,data.remoteDownloadNetworkProxyId, data.cronExpression,data.remoteDownloadTimeout,data.downloadRemoteIndexOnStartup,data.description, - extraParametersEntries,extraHeadersEntries); + extraParametersEntries,extraHeadersEntries,data.checkPath); } mapRemoteRepositories=function(data){ diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html index 3d16cf84f..c23158e95 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/repositories.html @@ -733,6 +733,20 @@ </div> </div> + <div class="control-group"> + <label class="control-label" for="checkPath">${$.i18n.prop('remoteRepository.checkPath')}</label> + + <div class="controls"> + <input type="text" class="input-xxlarge" id="checkPath" name="checkPath" + data-bind="value: remoteRepository.checkPath"/> + <a class="btn btn-warning btn-mini popover-doc" id="remoteRepository-checkPath-info-button" + data-original-title="${$.i18n.prop('remoteRepository.checkPath.help.title')}" + data-content="${$.i18n.prop('remoteRepository.checkPath.help.content')}"> + <i class="icon-question-sign icon-white"></i> + </a> + </div> + </div> + <div class="row-fluid"> <div class="control-group span6"> <strong>${$.i18n.prop('remoteRepository.extraParametersEntries')}</strong> |