は、私は次のコードを使用していますが、常にエラーがあります。JavaのAzure(バージョン1.1.2)でプロキシを設定する方法は?
public static void connect(CloudCredentials credentials, final CloudProxy proxy) throws Exception {
ApplicationTokenCredentials azCredential = new ApplicationTokenCredentials(credentials.getClientID(),
credentials.getTenantID(), credentials.getClientKey(), AzureEnvironment.AZURE);
try {
Configurable config = Azure.configure()
.withConnectionTimeout(30, TimeUnit.SECONDS)
.withReadTimeout(60, TimeUnit.SECONDS);
if (proxy != null) {
config.withProxy(new Proxy(Type.HTTP, new InetSocketAddress(proxy.getProxyHost(), proxy
.getProxyPort())));
if (proxy.getProxyUsername() != null && proxy.getProxyUsername().trim().length() > 0) {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(proxy.getProxyUsername(), proxy.getProxyPassword()
.toCharArray());
}
});
config.withProxyAuthenticator(new JavaNetAuthenticator());
}
}
Authenticated authenticate = config.authenticate(azCredential);
authenticate.withSubscription(credentials.getSubscription()).getCurrentSubscription().displayName();
System.out.println(authenticate);
} catch (Exception e) {
System.out.println(e);
}
}
[pool-1-thread-1] ERROR com.microsoft.aad.adal4j.AuthenticationContext - [Correlation ID: ] Request to acquire token failed. java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required" at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2124) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250) at com.microsoft.aad.adal4j.AdalOAuthRequest.configureHeaderAndExecuteOAuthCall(AdalOAuthRequest.java:140) at com.microsoft.aad.adal4j.AdalOAuthRequest.send(AdalOAuthRequest.java:83) at com.microsoft.aad.adal4j.AdalTokenRequest.executeOAuthRequestAndProcessResponse(AdalTokenRequest.java:80) at com.microsoft.aad.adal4j.AuthenticationContext.acquireTokenCommon(AuthenticationContext.java:818) at com.microsoft.aad.adal4j.AuthenticationContext.access$100(AuthenticationContext.java:66) at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:174) at com.microsoft.aad.adal4j.AuthenticationContext$1.call(AuthenticationContext.java:163) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) java.lang.RuntimeException: java.io.IOException: java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
しかし、私は確信しているプロキシが、それは大丈夫です。私は別のテストコードを持っています。それがうまく機能:
String a = "111";
System.out.print(a.toCharArray());
Authenticator.setDefault(new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("test", "111".toCharArray());
}
});
URLConnection connection;
try {
connection = new URL(
"http://devio.us/~ricky/stackoverflow-protected/nothingtosee.html")
.openConnection(new Proxy(Type.HTTP, new InetSocketAddress("192.168.1.59", 808)));
System.out.println(new BufferedReader(new InputStreamReader(
connection.getInputStream(), "UTF-8")).readLine());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
を私はすべてのJavaプロキシ経由意志を接続するためのプロキシを設定するためにはSystem.setPropertyを使用したくありません。 とAzureのドキュメント私はプロキシ情報を見つけることができません。 誰が私を助けることができますか?どうもありがとうございました。
進歩がありますか?私の答えはあなたを助けますか? –