Search in sources :

Example 1 with ActionStatus

use of org.apache.archiva.rest.api.model.ActionStatus in project archiva by apache.

the class DefaultRemoteRepositoriesService method checkRemoteConnectivity.

@Override
public ActionStatus checkRemoteConnectivity(String repositoryId) throws ArchivaRestServiceException {
    try {
        RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository(repositoryId);
        if (remoteRepository == null) {
            log.warn("Remote repository {} does not exist. Connectivity check returns false.", repositoryId);
            return ActionStatus.FAIL;
        }
        NetworkProxy networkProxy = null;
        if (StringUtils.isNotBlank(remoteRepository.getRemoteDownloadNetworkProxyId())) {
            networkProxy = proxyRegistry.getNetworkProxy(remoteRepository.getRemoteDownloadNetworkProxyId());
            if (networkProxy == null) {
                log.warn("A network proxy {} was configured for repository {}. But the proxy with the given id does not exist.", remoteRepository.getRemoteDownloadNetworkProxyId(), repositoryId);
            }
        }
        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(checkReadTimeout);
        wagon.setTimeout(checkTimeout);
        if (wagon instanceof AbstractHttpClientWagon) {
            HttpMethodConfiguration httpMethodConfiguration = // 
            new HttpMethodConfiguration().setUsePreemptive(// 
            true).setReadTimeout(checkReadTimeout);
            HttpConfiguration httpConfiguration = new HttpConfiguration().setGet(httpMethodConfiguration);
            AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
        }
        ProxyInfo proxyInfo = 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(new String(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 (!(StringUtils.isEmpty(remoteRepository.getCheckPath()) || "/".equals(remoteRepository.getCheckPath()))) {
            return new ActionStatus(wagon.resourceExists(remoteRepository.getCheckPath()));
        } else {
            // we only check connectivity as remote repo can be empty
            // MRM-1909: Wagon implementation appends a slash already
            wagon.getFileList("");
        }
        return ActionStatus.SUCCESS;
    } catch (TransferFailedException e) {
        log.info("TransferFailedException :{}", e.getMessage());
        return ActionStatus.FAIL;
    } 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());
        return ActionStatus.FAIL;
    }
}
Also used : AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) HttpMethodConfiguration(org.apache.maven.wagon.shared.http.HttpMethodConfiguration) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) AbstractHttpClientWagon(org.apache.maven.wagon.shared.http.AbstractHttpClientWagon) Wagon(org.apache.maven.wagon.Wagon) HttpConfiguration(org.apache.maven.wagon.shared.http.HttpConfiguration) NetworkProxy(org.apache.archiva.proxy.model.NetworkProxy) URL(java.net.URL) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ActionStatus(org.apache.archiva.rest.api.model.ActionStatus) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Repository(org.apache.maven.wagon.repository.Repository) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) TransferFailedException(org.apache.maven.wagon.TransferFailedException)

Example 2 with ActionStatus

use of org.apache.archiva.rest.api.model.ActionStatus in project archiva by apache.

the class DefaultRepositoriesService method removeScanningTaskFromQueue.

@Override
public ActionStatus removeScanningTaskFromQueue(String repositoryId) {
    RepositoryTask task = new RepositoryTask();
    task.setRepositoryId(repositoryId);
    try {
        return new ActionStatus(repositoryTaskScheduler.unQueueTask(task));
    } catch (TaskQueueException e) {
        log.error("failed to unschedule scanning of repo with id {}", repositoryId, e);
        return ActionStatus.FAIL;
    }
}
Also used : RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) TaskQueueException(org.apache.archiva.components.taskqueue.TaskQueueException) ActionStatus(org.apache.archiva.rest.api.model.ActionStatus)

Aggregations

ActionStatus (org.apache.archiva.rest.api.model.ActionStatus)2 URL (java.net.URL)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)1 TaskQueueException (org.apache.archiva.components.taskqueue.TaskQueueException)1 WagonFactoryRequest (org.apache.archiva.maven.common.proxy.WagonFactoryRequest)1 NetworkProxy (org.apache.archiva.proxy.model.NetworkProxy)1 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)1 RepositoryTask (org.apache.archiva.scheduler.repository.model.RepositoryTask)1 TransferFailedException (org.apache.maven.wagon.TransferFailedException)1 Wagon (org.apache.maven.wagon.Wagon)1 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)1 Repository (org.apache.maven.wagon.repository.Repository)1 AbstractHttpClientWagon (org.apache.maven.wagon.shared.http.AbstractHttpClientWagon)1 HttpConfiguration (org.apache.maven.wagon.shared.http.HttpConfiguration)1 HttpMethodConfiguration (org.apache.maven.wagon.shared.http.HttpMethodConfiguration)1