use of org.eclipse.core.net.proxy.IProxyService 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.IProxyService in project vorto by eclipse.
the class RestClient method getProxyService.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static IProxyService getProxyService() {
BundleContext bc = Activator.getDefault().getBundle().getBundleContext();
ServiceReference serviceReference = bc.getServiceReference(IProxyService.class.getName());
IProxyService service = (IProxyService) bc.getService(serviceReference);
return service;
}
use of org.eclipse.core.net.proxy.IProxyService in project liferay-ide by liferay.
the class LiferayCore method getProxyService.
public static IProxyService getProxyService() {
Bundle bundle = getDefault().getBundle();
ServiceTracker<Object, Object> proxyTracker = new ServiceTracker<>(bundle.getBundleContext(), IProxyService.class.getName(), null);
proxyTracker.open();
IProxyService proxyService = (IProxyService) proxyTracker.getService();
proxyTracker.close();
return proxyService;
}
use of org.eclipse.core.net.proxy.IProxyService 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.IProxyService 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;
}
Aggregations