我正在尝试使用java.But的adal4j库连接azure,我必须通过proxy.Following连接是一段代码
String url = "https://login.microsoftonline.com/tenant_id/oauth2/authorize";
authContext = new AuthenticationContext(url,false,
service);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyhostname", 443));
authContext.setProxy(proxy);
ClientCredential clientCred = new ClientCredential(XXXX, xxxx);
Future<AuthenticationResult> future = authContext.acquireToken(
clientCred,
null);
authResult = future.get();另外,我也尝试过
System.setProperty("http.proxyPort", "80");
System.setProperty("http.proxyUser", "xxxx");
System.setProperty("http.proxyPassword", "xxxx");
System.setProperty("http.proxyHost", "xxxxxxx");我一直收到下面的错误
the error is.....java.net.ConnectException: Connection timed out: connect
java.util.concurrent.ExecutionException: java.net.ConnectException: Connection timed out: connect
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at com.toyota.eap.auth.Test.main(Test.java:76)
Caused by: java.net.ConnectException: Connection timed out: connect注意:仅当我们在办公室内有代理时,才会出现此错误。在办公室外,如果我运行这个程序,没有任何问题。
任何关于这个的想法。
谢谢
发布于 2015-11-12 15:36:26
在使用带有代理的Adal4j时,有现有的线程可以回答java.net.ConnectException: Connection timed out的问题。请查看ADAL for Java Proxy、Java proxy issues - Connection Timed Out和How do I make HttpURLConnection use a proxy?。
更多细节可以使用URLConnection类的setConnectTimeout函数(参考http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URLConnection.html)进行解析,如下图和代码所示:

String url = "<url_link for http or https>";
int timeout = 30*1000; // 30 seconds
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("<proxy_host>", <proxy_port>));
// if need to auth for proxy
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication("<user>",
"<password>".toCharArray()));
}
};
Authenticator.setDefault(authenticator);
// open connection using proxy directly for this connection
// if not, setting in the JVM startup argus or using System.setProperty for app global scope
HttpURLConnection conn = new URL(url).openConnection(proxy); // Also HttpsURLConnection
conn.setConnectTimeout(timeout); // set Timeout同时,根据我的经验,如果代理IP和端口位于on-promise网络环境中,您可以在本地环境中使用它,但在Azure上失败。从这个角度来看,我认为你应该首先确认代理是有效的on-promise和Azure。
如果连接可以连接并且需要很长时间,那么按照我上面的参考设置连接超时属性是很有用的。
发布于 2021-11-12 16:47:26
您的代理是https吗?如果是这样,请使用jvm参数https。不是http:
HTTPS -Dhttps.proxyHost=proxy-name-without-https.com -Dhttps.proxyPort=代理端口
例如。-Dhttps.proxyHost=myproxy.com -Dhttps.proxyPort=2021
https://stackoverflow.com/questions/33574796
复制相似问题