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;
}
use of org.eclipse.core.net.proxy.IProxyData in project ecf by eclipse.
the class AbstractRetrieveTestCase method addProxy.
protected void addProxy(final String proxyHost, final int port, final String username, final String password) throws Exception {
IProxyService proxyService = Activator.getDefault().getProxyService();
proxyService.setProxiesEnabled(true);
proxyService.setSystemProxiesEnabled(false);
IProxyData proxyData = new IProxyData() {
public void disable() {
}
public String getHost() {
return proxyHost;
}
public String getPassword() {
return password;
}
public int getPort() {
return port;
}
public String getType() {
return "HTTP";
}
public String getUserId() {
return username;
}
public boolean isRequiresAuthentication() {
return (username != null);
}
public void setHost(String host) {
}
public void setPassword(String password) {
}
public void setPort(int port) {
}
public void setUserid(String userid) {
}
// TODO: What is the current expected target
public String getSource() {
// TODO Auto-generated method stub
return null;
}
public void setSource(String source) {
// TODO Auto-generated method stub
}
};
proxyService.setProxyData(new IProxyData[] { proxyData });
}
use of org.eclipse.core.net.proxy.IProxyData in project portfolio by buchen.
the class ProxyAddon method setupProxy.
private void setupProxy(IProxyService proxyService, String proxyHost, int proxyPort) {
try {
IProxyData[] proxyData = proxyService.getProxyData();
for (IProxyData data : proxyData) {
if (IProxyData.HTTP_PROXY_TYPE.equals(data.getType()) || IProxyData.HTTPS_PROXY_TYPE.equals(data.getType())) {
data.setHost(proxyHost);
data.setPort(proxyHost == null ? -1 : proxyPort);
// $NON-NLS-1$
data.setUserid(proxyHost == null ? null : System.getProperty("name.abuchen.portfolio.proxyUser"));
data.setPassword(proxyHost == null ? null : // $NON-NLS-1$
System.getProperty("name.abuchen.portfolio.proxyPassword"));
}
}
proxyService.setProxyData(proxyData);
proxyService.setSystemProxiesEnabled(false);
proxyService.setProxiesEnabled(true);
} catch (CoreException e) {
PortfolioPlugin.log(e);
}
}
use of org.eclipse.core.net.proxy.IProxyData in project gemoc-studio by eclipse.
the class Activator method prepareProxySettings.
public void prepareProxySettings(String uriString) {
URI uri;
try {
uri = new URI(uriString);
IProxyService proxyService = Activator.getDefault().getProxyService();
IProxyData[] proxyDataForHost = proxyService.select(uri);
for (IProxyData data : proxyDataForHost) {
if (data.getHost() != null) {
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", data.getHost());
}
if (data.getHost() != null) {
System.setProperty("http.proxyPort", String.valueOf(data.getPort()));
}
}
// Close the service and close the service tracker
proxyService = null;
} catch (URISyntaxException e) {
getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, e.getMessage(), e));
}
}
Aggregations