【发布时间】:2017-03-21 15:49:20
【问题描述】:
Connecting to Azure storage account thru proxy server Microsoft Azure Storage SDK for Java 告诉我如何使用 OperationContext 指定 proxyHost 和 Port。
我仍然不知道如何指定 proxyUser 和 proxyPassword 属性。
我遇到 StorageException:服务器遇到未知故障:当我尝试以下代码时:
Authenticator.setDefault(
new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
authUser, authPassword.toCharArray());
}
}
);
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);
System.setProperty("https.proxyHost", proxyHost);
System.setProperty("https.proxyPort", proxyPort);
System.setProperty("http.proxyUser", authUser);
System.setProperty("http.proxyPassword", authPassword);
System.setProperty("https.proxyUser", authUser);
System.setProperty("https.proxyPassword", authPassword);
try {
CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient serviceClient = account.createCloudBlobClient();
CloudBlobContainer container = serviceClient.getContainerReference(resourcePrefix);
container.createIfNotExists(null, op);
CloudBlockBlob blob = container.getBlockBlobReference(resourceName);
File sourceFile = new File(resourceName);
blob.upload(new FileInputStream(sourceFile), sourceFile.length());
}
catch (FileNotFoundException fileNotFoundException) {
System.out.print("FileNotFoundException encountered: ");
System.out.println(fileNotFoundException.getMessage());
System.exit(-1);
}
catch (StorageException storageException) {
System.out.print("StorageException encountered: ");
System.out.println(storageException.getMessage());
System.exit(-1);
}
catch (Exception e) {
System.out.print("Exception encountered: ");
System.out.println(e.getMessage());
System.exit(-1);
}
【问题讨论】:
-
几个问题: 1. 为什么要用setProperty设置proxyHost和proxyPort两次? 2. 下面我链接到this question 来演示如何在代理上设置用户名和密码。您提到您遵循了它,但我没有看到 setProperty 代码。当你尝试这个时发生了什么? 3. 为什么要同时制作 System 代理和 OperationContext 代理?
-
我看了你提到的问题和其他类似的帖子。设置 proxyUser 和 proxyPassword 不适用于 URLConnections。根据帖子,您需要我包含的身份验证器代码。我尝试将 proxyUser 设置为 proxyPassword,但它没有用。至于设置 proxyHost 和 proxyPort twicw,我设置 http 和 https 只是为了安全。您对系统代理和操作上下文代理的重复是正确的。我不应该两者都需要。我尝试了各种排列组合 - 只是系统代理,只是操作上下文,两者都 - 没有任何效果。救命!
-
无法在 URL 连接上设置代理用户和密码,但可以使用 System.setProperty 设置,如该链接所示。我在你的代码中没有看到。你能试试吗?
-
好的。再次尝试(请参阅更新的代码)并得到相同的超时错误(遇到StorageException:发生未知故障:操作超时)
标签: java azure sdk azure-storage