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 )
{
log.warn(
"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();
final Wagon wagon = wagonFactory.getWagon(
new WagonFactoryRequest( wagonProtocol, remoteRepository.getExtraHeaders() ).networkProxy(
networkProxy ) );
// hardcoded value as it's a check of the remote repo connectivity
wagon.setReadTimeout( 4000 );
wagon.setTimeout( 3000 );
if ( wagon instanceof AbstractHttpClientWagon )
{
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
httpMethodConfiguration.setUsePreemptive( true );
httpMethodConfiguration.setReadTimeout( 4000 );
httpConfiguration.setGet( httpMethodConfiguration );
AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
}
wagon.connect( new Repository( remoteRepository.getId(), remoteRepository.getUrl() ) );
// we only check connectivity as remote repo can be empty
wagon.getFileList( "/" );
return Boolean.TRUE;