use of org.eclipse.core.net.proxy.IProxyData in project vorto by eclipse.
the class RestClient method getProxyConfiguration.
private ProxyConfiguration getProxyConfiguration() {
IProxyService proxyService = getProxyService();
IProxyData[] proxyDataForHost = proxyService.select(java.net.URI.create(connectionInfo.getUrl()));
CredentialsProvider credsProvider = new BasicCredentialsProvider();
RequestConfig.Builder configBuilder = RequestConfig.custom();
for (IProxyData data : proxyDataForHost) {
if (!Strings.isNullOrEmpty(data.getHost())) {
HttpHost proxyConfig = new HttpHost(data.getHost(), data.getPort(), data.getType());
configBuilder.setProxy(proxyConfig);
if (!Strings.isNullOrEmpty(data.getUserId())) {
credsProvider.setCredentials(new AuthScope(data.getHost(), data.getPort()), new UsernamePasswordCredentials(data.getUserId(), data.getPassword()));
}
}
}
return new ProxyConfiguration(configBuilder.build(), credsProvider);
}
use of org.eclipse.core.net.proxy.IProxyData in project liferay-ide by liferay.
the class RemoteLogStream method openInputStream.
protected static InputStream openInputStream(IServerManagerConnection remote, URL url) throws IOException {
String username = remote.getUsername();
String password = remote.getPassword();
// $NON-NLS-1$
String authString = username + ":" + password;
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
final IProxyService proxyService = LiferayCore.getProxyService();
URLConnection conn = null;
try {
// $NON-NLS-1$ //$NON-NLS-2$
URI uri = new URI("HTTP://" + url.getHost() + ":" + url.getPort());
IProxyData[] proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if (data.getHost() != null) {
// $NON-NLS-1$
System.setProperty("http.proxyHost", data.getHost());
// $NON-NLS-1$
System.setProperty("http.proxyPort", String.valueOf(data.getPort()));
break;
}
}
// $NON-NLS-1$ //$NON-NLS-2$
uri = new URI("SOCKS://" + url.getHost() + ":" + url.getPort());
proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if (data.getHost() != null) {
// $NON-NLS-1$
System.setProperty("socksProxyHost", data.getHost());
// $NON-NLS-1$
System.setProperty("socksProxyPort", String.valueOf(data.getPort()));
break;
}
}
} catch (URISyntaxException e) {
// $NON-NLS-1$
LiferayServerCore.logError("Could not read proxy data", e);
}
conn = url.openConnection();
// $NON-NLS-1$ //$NON-NLS-2$
conn.setRequestProperty("Authorization", "Basic " + authStringEnc);
Authenticator.setDefault(null);
conn.setAllowUserInteraction(false);
return conn.getInputStream();
}
use of org.eclipse.core.net.proxy.IProxyData in project liferay-ide by liferay.
the class SocketUtil method canConnectProxy.
public static IStatus canConnectProxy(Socket socket, String host, String port) {
IProxyService proxyService = LiferayCore.getProxyService();
try {
// $NON-NLS-1$ //$NON-NLS-2$
URI uri = new URI("http://" + host + ":" + port);
IProxyData[] proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if (data.getHost() != null) {
return SocketUtil.canConnect(socket, data.getHost(), String.valueOf(data.getPort()));
}
}
// $NON-NLS-1$ //$NON-NLS-2$
uri = new URI("SOCKS://" + host + ":" + port);
for (IProxyData data : proxyDataForHost) {
if (data.getHost() != null) {
return SocketUtil.canConnect(socket, data.getHost(), String.valueOf(data.getPort()));
}
}
} catch (URISyntaxException e) {
// $NON-NLS-1$
LiferayServerCore.logError("Could not read proxy data", e);
}
return null;
}
use of org.eclipse.core.net.proxy.IProxyData in project tdq-studio-se by Talend.
the class EcosystemProxyAdapter method adapt.
/**
* DOC bZhou Comment method "adapt".
*
* @param httpclient
* @param url
*/
public static void adapt(HttpClient httpclient, String url) {
IProxyService proxyService = EcosPlugin.getDefault().getProxyService();
IProxyData proxyData = null;
try {
IProxyData[] proxyDatas = proxyService.select(new URI(url));
if (proxyDatas != null && proxyDatas.length > 0) {
proxyData = proxyDatas[0];
}
} catch (URISyntaxException e) {
log.error(e, e);
}
if (proxyData == null) {
proxyData = proxyService.getProxyData(IProxyData.HTTP_PROXY_TYPE);
}
if (proxyData != null & StringUtils.isNotEmpty(proxyData.getHost())) {
// use proxy to connect
ProxyHost host = new ProxyHost(proxyData.getHost(), proxyData.getPort());
httpclient.getHostConfiguration().setProxyHost(host);
httpclient.getParams().setAuthenticationPreemptive(true);
String userId = proxyData.getUserId();
if (StringUtils.isNotEmpty(userId)) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userId, proxyData.getPassword());
httpclient.getState().setProxyCredentials(AuthScope.ANY, credentials);
}
}
}
use of org.eclipse.core.net.proxy.IProxyData in project ecf by eclipse.
the class ProxySetupHelper method getProxy.
public static Proxy getProxy(String url) {
Proxy proxy = null;
try {
IProxyService proxyService = Activator.getDefault().getProxyService();
// Only do this if platform service exists
if (proxyService != null && proxyService.isProxiesEnabled()) {
// Setup via proxyService entry
URI uri = new URI(url);
final IProxyData[] proxies = proxyService.select(uri);
IProxyData selectedProxy = selectProxyFromProxies(uri.getScheme(), proxies);
if (selectedProxy != null) {
proxy = new Proxy(((selectedProxy.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) ? Proxy.Type.SOCKS : Proxy.Type.HTTP), new ProxyAddress(selectedProxy.getHost(), selectedProxy.getPort()), selectedProxy.getUserId(), selectedProxy.getPassword());
}
}
} catch (Exception e) {
// If we don't even have the classes for this (i.e. the org.eclipse.core.net plugin not available)
// then we simply log and ignore
Activator.logNoProxyWarning(e);
} catch (NoClassDefFoundError e) {
Activator.logNoProxyWarning(e);
}
return proxy;
}
Aggregations