use of org.eclipse.core.net.proxy.IProxyService in project liferay-ide by liferay.
the class RemoteConnection method _getHttpClient.
private HttpClient _getHttpClient() {
if (_httpClient != null) {
return _httpClient;
}
DefaultHttpClient newDefaultHttpClient = null;
if ((getUsername() != null) || (getPassword() != null)) {
try {
IProxyService proxyService = LiferayCore.getProxyService();
URI uri = new URI("http://" + getHost() + ":" + getHttpPort());
IProxyData[] proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if ((data.getHost() == null) || (data.getPort() == 0)) {
continue;
}
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", data.getPort(), PlainSocketFactory.getSocketFactory()));
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(20);
DefaultHttpClient newHttpClient = new DefaultHttpClient(cm);
HttpHost proxy = new HttpHost(data.getHost(), data.getPort());
newHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
newDefaultHttpClient = newHttpClient;
break;
}
if (newDefaultHttpClient == null) {
uri = new URI("SOCKS://" + getHost() + ":" + getHttpPort());
proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if (data.getHost() == null) {
continue;
}
DefaultHttpClient newHttpClient = new DefaultHttpClient();
newHttpClient.getParams().setParameter("socks.host", data.getHost());
newHttpClient.getParams().setParameter("socks.port", data.getPort());
SchemeRegistry registry = newHttpClient.getConnectionManager().getSchemeRegistry();
Scheme scheme = new Scheme("socks", data.getPort(), PlainSocketFactory.getSocketFactory());
registry.register(scheme);
newDefaultHttpClient = newHttpClient;
break;
}
}
} catch (URISyntaxException urise) {
LiferayCore.logError("Unable to read proxy data", urise);
}
if (newDefaultHttpClient == null) {
newDefaultHttpClient = new DefaultHttpClient();
}
_httpClient = newDefaultHttpClient;
} else {
_httpClient = new DefaultHttpClient();
}
return _httpClient;
}
use of org.eclipse.core.net.proxy.IProxyService in project eclipse.jdt.ls by eclipse.
the class JavaLanguageServerPlugin method configureProxy.
private void configureProxy() {
// It seems there is no way to set a proxy provider type (manual, native or
// direct) without the Eclipse UI.
// The org.eclipse.core.net plugin removes the http., https. system properties
// when setting its preferences and a proxy provider isn't manual.
// We save these parameters and set them after starting the
// org.eclipse.core.net plugin.
String httpHost = System.getProperty(HTTP_PROXY_HOST);
String httpPort = System.getProperty(HTTP_PROXY_PORT);
String httpUser = System.getProperty(HTTP_PROXY_USER);
String httpPassword = System.getProperty(HTTP_PROXY_PASSWORD);
String httpsHost = System.getProperty(HTTPS_PROXY_HOST);
String httpsPort = System.getProperty(HTTPS_PROXY_PORT);
String httpsUser = System.getProperty(HTTPS_PROXY_USER);
String httpsPassword = System.getProperty(HTTPS_PROXY_PASSWORD);
String httpsNonProxyHosts = System.getProperty(HTTPS_NON_PROXY_HOSTS);
String httpNonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS);
if (StringUtils.isNotBlank(httpUser) || StringUtils.isNotBlank(httpsUser)) {
try {
Platform.getBundle("org.eclipse.core.net").start(Bundle.START_TRANSIENT);
} catch (BundleException e) {
logException(e.getMessage(), e);
}
if (StringUtils.isNotBlank(httpUser) && StringUtils.isNotBlank(httpPassword)) {
Authenticator.setDefault(new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(httpUser, httpPassword.toCharArray());
}
});
}
IProxyService proxyService = getProxyService();
if (proxyService != null) {
ProxySelector.setActiveProvider(MANUAL);
IProxyData[] proxies = proxyService.getProxyData();
for (IProxyData proxy : proxies) {
if ("HTTP".equals(proxy.getType())) {
proxy.setHost(httpHost);
proxy.setPort(httpPort == null ? -1 : Integer.valueOf(httpPort));
proxy.setPassword(httpPassword);
proxy.setUserid(httpUser);
}
if ("HTTPS".equals(proxy.getType())) {
proxy.setHost(httpsHost);
proxy.setPort(httpsPort == null ? -1 : Integer.valueOf(httpsPort));
proxy.setPassword(httpsPassword);
proxy.setUserid(httpsUser);
}
}
try {
proxyService.setProxyData(proxies);
if (httpHost != null) {
System.setProperty(HTTP_PROXY_HOST, httpHost);
}
if (httpPort != null) {
System.setProperty(HTTP_PROXY_PORT, httpPort);
}
if (httpUser != null) {
System.setProperty(HTTP_PROXY_USER, httpUser);
}
if (httpPassword != null) {
System.setProperty(HTTP_PROXY_PASSWORD, httpPassword);
}
if (httpsHost != null) {
System.setProperty(HTTPS_PROXY_HOST, httpsHost);
}
if (httpsPort != null) {
System.setProperty(HTTPS_PROXY_PORT, httpsPort);
}
if (httpsUser != null) {
System.setProperty(HTTPS_PROXY_USER, httpsUser);
}
if (httpsPassword != null) {
System.setProperty(HTTPS_PROXY_PASSWORD, httpsPassword);
}
if (httpsNonProxyHosts != null) {
System.setProperty(HTTPS_NON_PROXY_HOSTS, httpsNonProxyHosts);
}
if (httpNonProxyHosts != null) {
System.setProperty(HTTP_NON_PROXY_HOSTS, httpNonProxyHosts);
}
} catch (CoreException e) {
logException(e.getMessage(), e);
}
}
}
}
use of org.eclipse.core.net.proxy.IProxyService in project ecf by eclipse.
the class Activator method getProxyService.
public IProxyService getProxyService() {
try {
if (proxyServiceTracker == null) {
proxyServiceTracker = new ServiceTracker(this.context, IProxyService.class.getName(), null);
proxyServiceTracker.open();
}
return (IProxyService) proxyServiceTracker.getService();
} catch (Exception e) {
logNoProxyWarning(e);
} catch (NoClassDefFoundError e) {
logNoProxyWarning(e);
}
return null;
}
Aggregations