use of java.net.Proxy in project tdi-studio-se by Talend.
the class DynamicsCRMClient method getAccessToken.
protected AuthenticationResult getAccessToken() throws ServiceUnavailableException {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(clientConfiguration.getAuthoryEndpoint(), false, service);
Proxy proxy = getProxy();
if (proxy != null) {
context.setProxy(proxy);
}
Future<AuthenticationResult> future = context.acquireToken(clientConfiguration.getResource(), clientConfiguration.getClientId(), clientConfiguration.getUserName(), clientConfiguration.getPassword(), null);
result = future.get();
} catch (Exception e) {
throw new ServiceUnavailableException(e.getMessage());
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException("Authenticated failed! Please check your configuration!");
}
return result;
}
use of java.net.Proxy in project tdi-studio-se by Talend.
the class DynamicsCRMClient method getProxy.
/**
* Get the proxy setting if there is proxy for system
*/
private Proxy getProxy() {
String proxyHost = System.getProperty("https.proxyHost");
String proxyPort = System.getProperty("https.proxyPort");
if (proxyHost != null) {
int port = -1;
if (proxyPort != null && proxyPort.length() > 0) {
port = Integer.parseInt(proxyPort);
}
SocketAddress addr = new InetSocketAddress(proxyHost, port);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
return proxy;
}
return null;
}
use of java.net.Proxy in project tdi-studio-se by Talend.
the class DynamicsCRMClient method setHttpclientProxy.
/**
* Setup proxy for httpClient
*/
private void setHttpclientProxy(DefaultHttpClient httpClient) {
Proxy proxy = getProxy();
String proxyUser = System.getProperty("https.proxyUser");
String proxyPwd = System.getProperty("https.proxyPassword");
// set by other components like tSetProxy
if (proxy != null) {
final HttpHost httpHost = new HttpHost(((InetSocketAddress) proxy.address()).getHostName(), ((InetSocketAddress) proxy.address()).getPort());
// Sets usage of HTTP proxy
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpHost);
// TODO Because the proxy of get accesToken can't support authentication. remove this ?
if (proxyUser != null && proxyPwd != null) {
httpClient.getCredentialsProvider().setCredentials(new AuthScope(httpHost), new UsernamePasswordCredentials(proxyUser, proxyPwd));
}
}
}
use of java.net.Proxy in project zm-mailbox by Zimbra.
the class HttpProxyConfig method getProxyConfig.
public static ProxyHostConfiguration getProxyConfig(HostConfiguration hc, String uriStr) {
if (!LC.client_use_system_proxy.booleanValue())
return null;
URI uri = null;
try {
uri = new URI(uriStr);
} catch (URISyntaxException x) {
ZimbraLog.net.info(uriStr, x);
return null;
}
//no need to filter out localhost as the DefaultProxySelector will do that.
List<Proxy> proxies = ProxySelectors.defaultProxySelector().select(uri);
for (Proxy proxy : proxies) {
switch(proxy.type()) {
case DIRECT:
return null;
case HTTP:
InetSocketAddress addr = (InetSocketAddress) proxy.address();
if (ZimbraLog.net.isDebugEnabled()) {
ZimbraLog.net.debug("URI %s to use HTTP proxy %s", safePrint(uri), addr.toString());
}
ProxyHostConfiguration nhc = new ProxyHostConfiguration(hc);
nhc.setProxy(addr.getHostName(), addr.getPort());
if (proxy instanceof AuthProxy) {
nhc.setUsername(((AuthProxy) proxy).getUsername());
nhc.setPassword(((AuthProxy) proxy).getPassword());
}
return nhc;
//socks proxy can be handled at socket factory level
case SOCKS:
default:
continue;
}
}
return null;
}
use of java.net.Proxy in project zm-mailbox by Zimbra.
the class ProxySelectorSocket method connect.
@Override
public void connect(SocketAddress endpoint, int timeout) throws IOException {
Proxy proxy = proxy((InetSocketAddress) endpoint);
switch(proxy.type()) {
case DIRECT:
LOG.debug("Connecting directly to %s", endpoint);
case SOCKS:
LOG.debug("Connecting to %s via SOCKS proxy %s", endpoint, proxy.address());
}
setDelegate(new Socket(proxy));
super.connect(endpoint, timeout);
}
Aggregations