Search in sources :

Example 1 with IProxyService

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);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) IProxyData(org.eclipse.core.net.proxy.IProxyData) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) IProxyService(org.eclipse.core.net.proxy.IProxyService) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with IProxyService

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;
}
Also used : IProxyService(org.eclipse.core.net.proxy.IProxyService) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with IProxyService

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;
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) Bundle(org.osgi.framework.Bundle) IProxyService(org.eclipse.core.net.proxy.IProxyService)

Example 4 with IProxyService

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();
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IProxyService(org.eclipse.core.net.proxy.IProxyService) URLConnection(java.net.URLConnection)

Example 5 with IProxyService

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;
}
Also used : IProxyData(org.eclipse.core.net.proxy.IProxyData) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IProxyService(org.eclipse.core.net.proxy.IProxyService)

Aggregations

IProxyService (org.eclipse.core.net.proxy.IProxyService)19 IProxyData (org.eclipse.core.net.proxy.IProxyData)11 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 BundleContext (org.osgi.framework.BundleContext)4 HttpHost (org.apache.http.HttpHost)3 CoreException (org.eclipse.core.runtime.CoreException)3 PasswordAuthentication (java.net.PasswordAuthentication)2 ServiceReference (org.osgi.framework.ServiceReference)2 ServiceTracker (org.osgi.util.tracker.ServiceTracker)2 IOException (java.io.IOException)1 Authenticator (java.net.Authenticator)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 UnknownHostException (java.net.UnknownHostException)1 Inject (javax.inject.Inject)1 ProxyHost (org.apache.commons.httpclient.ProxyHost)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 AuthScope (org.apache.http.auth.AuthScope)1