use of org.eclipse.core.net.proxy.IProxyService 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.IProxyService 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.IProxyService in project portfolio by buchen.
the class ProxyAddon method setupProxyService.
@Inject
public void setupProxyService(@Preference(value = UIConstants.Preferences.PROXY_HOST) String proxyHost, @Preference(value = UIConstants.Preferences.PROXY_PORT) int proxyPort) {
BundleContext bc = FrameworkUtil.getBundle(ProxyAddon.class).getBundleContext();
ServiceReference<IProxyService> serviceReference = bc.getServiceReference(IProxyService.class);
IProxyService proxyService = bc.getService(serviceReference);
setupProxy(proxyService, proxyHost, proxyPort);
bc.ungetService(serviceReference);
}
use of org.eclipse.core.net.proxy.IProxyService 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));
}
}
use of org.eclipse.core.net.proxy.IProxyService in project epp.mpc by eclipse.
the class ProxyAuthenticator method getPasswordAuthentication.
@Override
protected PasswordAuthentication getPasswordAuthentication() {
IProxyService proxyService = ProxyHelper.getProxyService();
if (proxyService != null && proxyService.isProxiesEnabled()) {
URL requestingURL = getRequestingURL();
IProxyData[] proxies;
if (requestingURL == null) {
proxies = proxyService.getProxyData();
} else {
try {
proxies = proxyService.select(requestingURL.toURI());
} catch (URISyntaxException e) {
proxies = proxyService.getProxyData();
}
}
for (IProxyData proxyData : proxies) {
// make sure we don't hand out credentials to the wrong proxy
if (proxyData.isRequiresAuthentication() && proxyData.getPort() == getRequestingPort() && hostMatches(proxyData)) {
String userId = proxyData.getUserId();
String password = proxyData.getPassword();
if (userId != null && password != null) {
return new PasswordAuthentication(userId, password.toCharArray());
}
}
}
}
if (delegate != null) {
// Eclipse UI bundle registers one to query credentials from user
try {
Authenticator.setDefault(delegate);
String requestingHost = getRequestingHost();
InetAddress requestingSite = getRequestingSite();
int requestingPort = getRequestingPort();
String requestingProtocol = getRequestingProtocol();
String requestingPrompt = getRequestingPrompt();
String requestingScheme = getRequestingScheme();
URL requestingURL = getRequestingURL();
RequestorType requestorType = getRequestorType();
if (requestingSite == null) {
try {
requestingSite = InetAddress.getByName(requestingHost);
} catch (Exception ex) {
// ignore
}
}
if (requestingPrompt == null) {
// Help the Eclipse UI password dialog with its prompt
String promptHost = // $NON-NLS-1$
requestingSite == null ? // $NON-NLS-1$
String.format("%s:%s", requestingHost, requestingPort) : requestingHost == null ? requestingSite.getHostName() : requestingHost;
String promptType = requestorType.toString().toLowerCase();
requestingPrompt = MessageFormat.format(Messages.ProxyAuthenticator_prompt, requestingScheme, promptType, promptHost);
}
return Authenticator.requestPasswordAuthentication(requestingHost, requestingSite, requestingPort, requestingProtocol, requestingPrompt, requestingScheme, requestingURL, requestorType);
} finally {
Authenticator.setDefault(this);
}
}
return null;
}
Aggregations