Я могу подключиться к хранилищу BLOB-объектов Azure с помощью прокси. Теперь я хочу прочитать все изображения из хранилища BLOB-объектов Azure.
// ConnectionString
String storageConnectionString =
"DefaultEndpointsProtocol=https;" +
"AccountName=xxxxxxx;" +
"AccountKey=xxxxxxddfcfdcddrc==";
//Authetication
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new
PasswordAuthentication(proxyName,passowrd.toCharArray());
}});
//Set Proxy Host name and Port
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("xxxxxxxxx", 8080));
OperationContext op = new OperationContext();
op.setProxy(proxy);
// Retrieve storage account from connection-string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Get a reference to a container.
// The container name must be lower case
CloudBlobContainer container = blobClient.getContainerReference("test");
// Create the container if it does not exist with public access.
System.out.println("Creating container: " + container.getName());
// Create the container if it does not exist.
//container.createIfNotExists(BlobContainerPublicAccessType.CONTAINER, new BlobRequestOptions(), op);
// Delete the blob.
//container.deleteIfExists(null, null, op);
LinkedList<String> blobNames = new LinkedList<>();
Iterable<ListBlobItem> blobs = container.listBlobs();
blobNames = new LinkedList<>();
**// the line that hit an error**
for(ListBlobItem blob: blobs) {
blobNames.add(((CloudBlockBlob) blob).getName());
}
System.out.println(blobNames.size());
System.out.println("********Success*********");
Когда я запускаю скрипт выше, у меня возникает следующая проблема:
java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details.java.util.NoSuchElementException: An error occurred while enumerating the result, check the original exception for details.
at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:113)
at com.microsoft.azure.storage.StorageException: An unknown failure occurred : Connection refused: connect
at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:66)
at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:209)
at com.microsoft.azure.storage.core.LazySegmentedIterator.hasNext(LazySegmentedIterator.java:109)
... 1 moreCaused by: java.net.ConnectException: Connection refused: connect
Я не понимаю, почему возникает эта ошибка, но она выдает исключение, и соединение отказано.