use of org.apache.maven.wagon.repository.Repository in project intellij-community by JetBrains.
the class Maven3ServerIndexFetcher method connect.
@Override
public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException {
ArtifactRepository artifactRepository = myRepositorySystem.createArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null, null, null);
final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(artifactRepository);
String mirrorUrl = mirrorRepository.getUrl();
String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index";
Repository repository = new Repository(myOriginalRepositoryId, indexUrl);
try {
myWagon = myWagonManager.getWagon(repository);
myWagon.addTransferListener(myListener);
myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol()));
} catch (AuthenticationException e) {
IOException newEx = new IOException("Authentication exception connecting to " + repository);
newEx.initCause(e);
throw newEx;
} catch (WagonException e) {
IOException newEx = new IOException("Wagon exception connecting to " + repository);
newEx.initCause(e);
throw newEx;
}
}
use of org.apache.maven.wagon.repository.Repository in project intellij-community by JetBrains.
the class Maven2ServerIndexFetcher method connect.
public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException {
final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(new DefaultArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null));
String mirrorUrl = mirrorRepository.getUrl();
String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index";
Repository repository = new Repository(myOriginalRepositoryId, indexUrl);
try {
myWagon = myWagonManager.getWagon(repository);
myWagon.addTransferListener(myListener);
myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol()));
} catch (AuthenticationException e) {
IOException newEx = new IOException("Authentication exception connecting to " + repository);
newEx.initCause(e);
throw newEx;
} catch (WagonException e) {
IOException newEx = new IOException("Wagon exception connecting to " + repository);
newEx.initCause(e);
throw newEx;
}
}
use of org.apache.maven.wagon.repository.Repository in project fabric8 by jboss-fuse.
the class ConfigurableHttpWagon method execute.
@Override
protected CloseableHttpResponse execute(HttpUriRequest httpMethod) throws HttpException, IOException {
setHeaders(httpMethod);
String userAgent = getUserAgent(httpMethod);
if (userAgent != null) {
httpMethod.setHeader(HTTP.USER_AGENT, userAgent);
}
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
// WAGON-273: default the cookie-policy to browser compatible
requestConfigBuilder.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);
Repository repo = getRepository();
ProxyInfo proxyInfo = getProxyInfo(repo.getProtocol(), repo.getHost());
if (proxyInfo != null) {
HttpHost proxy = new HttpHost(proxyInfo.getHost(), proxyInfo.getPort());
requestConfigBuilder.setProxy(proxy);
}
HttpMethodConfiguration config = getHttpConfiguration() == null ? null : getHttpConfiguration().getMethodConfiguration(httpMethod);
if (config != null) {
copyConfig(config, requestConfigBuilder);
} else {
requestConfigBuilder.setSocketTimeout(getReadTimeout());
requestConfigBuilder.setConnectTimeout(getTimeout());
}
getLocalContext().setRequestConfig(requestConfigBuilder.build());
if (config != null && config.isUsePreemptive()) {
HttpHost targetHost = new HttpHost(repo.getHost(), repo.getPort(), repo.getProtocol());
AuthScope targetScope = getBasicAuthScope().getScope(targetHost);
if (getCredentialsProvider().getCredentials(targetScope) != null) {
BasicScheme targetAuth = new BasicScheme();
targetAuth.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "BASIC preemptive"));
getAuthCache().put(targetHost, targetAuth);
}
}
if (proxyInfo != null) {
if (proxyInfo.getHost() != null) {
HttpHost proxyHost = new HttpHost(proxyInfo.getHost(), proxyInfo.getPort());
AuthScope proxyScope = getProxyBasicAuthScope().getScope(proxyHost);
String proxyUsername = proxyInfo.getUserName();
String proxyPassword = proxyInfo.getPassword();
String proxyNtlmHost = proxyInfo.getNtlmHost();
String proxyNtlmDomain = proxyInfo.getNtlmDomain();
if (proxyUsername != null && proxyPassword != null) {
Credentials creds;
if (proxyNtlmHost != null || proxyNtlmDomain != null) {
creds = new NTCredentials(proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain);
} else {
creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
}
getCredentialsProvider().setCredentials(proxyScope, creds);
BasicScheme proxyAuth = new BasicScheme();
proxyAuth.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC preemptive"));
getAuthCache().put(proxyHost, proxyAuth);
}
}
}
return client.execute(httpMethod, getLocalContext());
}
use of org.apache.maven.wagon.repository.Repository in project archiva by apache.
the class DefaultRepositoryProxyConnectors method connectToRepository.
/**
* Using wagon, connect to the remote repository.
*
* @param connector the connector configuration to utilize (for obtaining network proxy configuration from)
* @param wagon the wagon instance to establish the connection on.
* @param remoteRepository the remote repository to connect to.
* @return true if the connection was successful. false if not connected.
*/
private boolean connectToRepository(ProxyConnector connector, Wagon wagon, RemoteRepositoryContent remoteRepository) {
boolean connected = false;
final ProxyInfo networkProxy = connector.getProxyId() == null ? null : this.networkProxyMap.get(connector.getProxyId());
if (log.isDebugEnabled()) {
if (networkProxy != null) {
// TODO: move to proxyInfo.toString()
String msg = "Using network proxy " + networkProxy.getHost() + ":" + networkProxy.getPort() + " to connect to remote repository " + remoteRepository.getURL();
if (networkProxy.getNonProxyHosts() != null) {
msg += "; excluding hosts: " + networkProxy.getNonProxyHosts();
}
if (StringUtils.isNotBlank(networkProxy.getUserName())) {
msg += "; as user: " + networkProxy.getUserName();
}
log.debug(msg);
}
}
AuthenticationInfo authInfo = null;
String username = "";
String password = "";
RepositoryCredentials repCred = remoteRepository.getRepository().getLoginCredentials();
if (repCred != null && repCred instanceof PasswordCredentials) {
PasswordCredentials pwdCred = (PasswordCredentials) repCred;
username = pwdCred.getUsername();
password = pwdCred.getPassword() == null ? "" : new String(pwdCred.getPassword());
}
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
log.debug("Using username {} to connect to remote repository {}", username, remoteRepository.getURL());
authInfo = new AuthenticationInfo();
authInfo.setUserName(username);
authInfo.setPassword(password);
}
// Convert seconds to milliseconds
long timeoutInMilliseconds = remoteRepository.getRepository().getTimeout().toMillis();
// Set timeout read and connect
// FIXME olamy having 2 config values
wagon.setReadTimeout((int) timeoutInMilliseconds);
wagon.setTimeout((int) timeoutInMilliseconds);
try {
Repository wagonRepository = new Repository(remoteRepository.getId(), remoteRepository.getURL().toString());
wagon.connect(wagonRepository, authInfo, networkProxy);
connected = true;
} catch (ConnectionException | AuthenticationException e) {
log.warn("Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage());
connected = false;
}
return connected;
}
use of org.apache.maven.wagon.repository.Repository in project archiva by apache.
the class DefaultRemoteRepositoriesService method checkRemoteConnectivity.
@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);
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(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(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 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 Boolean.TRUE;
} catch (TransferFailedException e) {
log.info("TransferFailedException :{}", e.getMessage());
return Boolean.FALSE;
} 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 Boolean.FALSE;
}
}
Aggregations