【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is malformed
问题描述
使用Azure Storage Account的共享访问签名(Share Access Signature) 生成的终结点,连接时遇见 The Azure Storage endpoint url is malformed (Azure 存储终结点 URL 格式不正确)
Storage Account SDK in pom.xml:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.6.0</version>
</dependency>
App.Java 文件中,创建 BlobServiceClient 对象代码:
String endpoint ="BlobEndpoint=https://://************...";
BlobServiceClient blobServiceClientbyendpoint = new BlobServiceClientBuilder().endpoint(endpoint).buildClient();
获取Endpoint的方法为(Azure Portal --> Storage Account --> Share access signature)

当执行Java 代码时,main函数抛出异常:java.lang.IllegalArgumentException: The Azure Storage endpoint url is malformed
PS C:\LBWorkSpace\MyCode\1-Storage Account - Operation Blob by Connection String - Java>
& 'C:\Program Files\Microsoft\jdk-11.0.12.7-hotspot\bin\java.exe'
'-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:59757'
'@C:\Users\AppData\Local\Temp\cp_6ux3xmehddi1mc4fanfjupd3x.argfile'
'com.blobs.quickstart.App'
Azure Blob storage v12 - Java quickstart sample 2022-05-26 10:24:29 ERROR BlobServiceClientBuilder - The Azure Storage endpoint url is malformed.
Exception in thread "main" java.lang.IllegalArgumentException: The Azure Storage endpoint url is malformed.
at com.azure.storage.blob.BlobServiceClientBuilder.endpoint(BlobServiceClientBuilder.java:132)
at com.blobs.quickstart.App.main(App.java:30)
问题分析
消息 [The Azure Storage endpoint url is malformed (Azure 存储终结点 URL 格式不正确)] 说明代码中使用的格式不对,回到生成endopoint的页面查看,原来使用的是连接字符串 Connection String. 与直接使用Access Key中的Connection String是相同的代码方式,而 Endpoint 是指当个连接到Blob Service的URL。

回到代码中,发现新版本把连接方式进行了区分:
- 使用Connection String时,用 new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
- 使用Endpoint时,用 new BlobServiceClientBuilder().endpoint(endpoint).buildClient();
所以,解决 endpoint url malformed 关键就是使用正确的 SAS URL 或者是 Connection String
//使用连接字符串时
String connectStr ="BlobEndpoint=https://:************.blob.core.chinacloudapi.cn/;...SharedAccessSignature=sv=2020-08-0...&sig=**************";
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
//使用SAS终结点
String endpoint ="https://************.blob.core.chinacloudapi.cn/?sv=2020-08-04...&sig=*********************";
BlobServiceClient blobServiceClientbyendpoint = new BlobServiceClientBuilder().endpoint(endpoint).buildClient();
完整的示例代码:
package com.blobs.quickstart; /**
* Azure blob storage v12 SDK quickstart
*/
import com.azure.storage.blob.*;
import com.azure.storage.blob.models.*;
import java.io.*; public class App
{
public static void main( String[] args ) throws IOException
{ System.out.println("Azure Blob storage v12 - Java quickstart sample\n"); // Retrieve the connection string for use with the application. The storage
// connection string is stored in an environment variable on the machine
// running the application called AZURE_STORAGE_CONNECTION_STRING. If the environment variable
// is created after the application is launched in a console or with
// Visual Studio, the shell or application needs to be closed and reloaded
// to take the environment variable into account. //String connectStr ="DefaultEndpointsProtocol=https;AccountName=******;AccountKey=***********************;EndpointSuffix=core.chinacloudapi.cn";// System.getenv("AZURE_STORAGE_CONNECTION_STRING");
String connectStr ="BlobEndpoint=https://******* */.blob.core.chinacloudapi.cn/;QueueEndpoint=https://*******.queue.core.chinacloudapi.cn/;FileEndpoint=https://*******.file.core.chinacloudapi.cn/;TableEndpoint=https://*******.table.core.chinacloudapi.cn/;SharedAccessSignature=sv=2020...&sig=*************************";
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient(); //Create a unique name for the container
String containerName = "lina-" + java.util.UUID.randomUUID(); // Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName); BlobContainerClient containerClient1 = blobServiceClient.getBlobContainerClient("container-name"); if(!containerClient1.exists())
{
System.out.println("create containerName");
blobServiceClient.createBlobContainer("container-name");
} System.out.println("create containerName .....");
// // Create a local file in the ./data/ directory for uploading and downloading
// String localPath = "./data/";
// String fileName = "quickstart" + java.util.UUID.randomUUID() + ".txt";
// File localFile = new File(localPath + fileName); // // Write text to the file
// FileWriter writer = new FileWriter(localPath + fileName, true);
// writer.write("Hello, World!");
// writer.close(); // // Get a reference to a blob
// BlobClient blobClient = containerClient.getBlobClient(fileName); // System.out.println("\nUploading to Blob storage as blob:\n\t" + blobClient.getBlobUrl()); // // Upload the blob
// blobClient.uploadFromFile(localPath + fileName); // System.out.println("\nListing blobs..."); // // List the blob(s) in the container.
// for (BlobItem blobItem : containerClient.listBlobs()) {
// System.out.println("\t" + blobItem.getName());
// } // // Download the blob to a local file
// // Append the string "DOWNLOAD" before the .txt extension so that you can see both files.
// String downloadFileName = fileName.replace(".txt", "DOWNLOAD.txt");
// File downloadedFile = new File(localPath + downloadFileName); // System.out.println("\nDownloading blob to\n\t " + localPath + downloadFileName); // blobClient.downloadToFile(localPath + downloadFileName); // // Clean up
// System.out.println("\nPress the Enter key to begin clean up");
// System.console().readLine(); // System.out.println("Deleting blob container...");
// containerClient.delete(); // System.out.println("Deleting the local source and downloaded files...");
// localFile.delete();
// downloadedFile.delete(); System.out.println("Done");
}
}
参考资料
快速入门:使用 Java v12 SDK 管理 blob: https://docs.azure.cn/zh-cn/storage/blobs/storage-quickstart-blobs-java?tabs=powershell%2Cenvironment-variable-windows
【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is malformed的更多相关文章
- 玩转Windows Azure存储服务——网盘
存储服务是除了计算服务之外最重要的云服务之一.说到云存储,大家可以想到很多产品,例如:AWS S3,Google Drive,百度云盘...而在Windows Azure中,存储服务却是在默默无闻的工 ...
- 【Azure 存储服务】代码版 Azure Storage Blob 生成 SAS (Shared Access Signature: 共享访问签名)
问题描述 在使用Azure存储服务,为了有效的保护Storage的Access Keys.可以使用另一种授权方式访问资源(Shared Access Signature: 共享访问签名), 它的好处可 ...
- 解读 Windows Azure 存储服务的账单 – 带宽、事务数量,以及容量
经常有人询问我们,如何估算 Windows Azure 存储服务的成本,以便了解如何更好地构建一个经济有效的应用程序.本文我们将从带宽.事务数量,以及容量这三种存储成本的角度探讨这一问题. 在使用 W ...
- 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例
什么是表存储 Azure 表存储是一项用于在云中存储结构化 NoSQL 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...
- 微软开放技术开发了适用于 Windows Azure 移动服务的开源 Android SDK
发布于 2014-02-10 作者 陈 忠岳 为进一步实现连接微软与非微软技术的目标,微软开放技术有限公司开发了适用于 Windows Azure 移动服务的 Android SDK,由Scot ...
- 玩转Windows Azure存储服务——高级存储
在上一篇我们把Windows Azure的存储服务用作网盘,本篇我们继续挖掘Windows Azure的存储服务——高级存储.高级存储自然要比普通存储高大上的,因为高级存储是SSD存储!其吞吐量和IO ...
- 跟我学Windows Azure 五 使用Cloub Service连接Blob Service完成图片的上传
首先,我们创建一个云服务项目,用来演示我们的blob存储 下来我们修改我们我们云服务的名字 我们需要添加一个空的WebForm的项目 点击完成,我们可以看到我们的解决方案已经添加完成 下来我们需要添加 ...
- 【Azure 存储服务】Hadoop集群中使用ADLS(Azure Data Lake Storage)过程中遇见执行PUT操作报错
问题描述 在Hadoop集中中,使用ADLS 作为数据源,在执行PUT操作(上传文件到ADLS中),遇见 400错误[put: Operation failed: "An HTTP head ...
- 【Azure 存储服务】如何把开启NFS 3.0协议的Azure Blob挂载在Linux VM中呢?(NFS: Network File System 网络文件系统)
问题描述 如何把开启NFS协议的Azure Blob挂载到Linux虚拟机中呢? [答案]:可以使用 NFS 3.0 协议从基于 Linux 的 Azure 虚拟机 (VM) 或在本地运行的 Linu ...
随机推荐
- 体验js之美第八课-面向对象创建和继承终结篇
概述 到这里我们讲说js面向对象的系列部分的最后一个课程,面向对象必须掌握两个东西一个是对象的创建一个是继承.这节课我们重点说说这两个问题最后我们说下在ES6里面面向对象怎么玩. 1对象的创建 我们第 ...
- python-逆序输出
输入一行字符串,然后对其进行如下处理. 输入格式: 字符串中的元素以空格或者多个空格分隔. 输出格式: 逆序输出字符串中的所有元素.然后输出原列表.然后逆序输出原列表每个元素,中间以1个空格分隔.注意 ...
- 创建可以运行宿主机GPU的容器
1.安装NVIDIA Container Runtime apt-get参考https://blog.csdn.net/li_ellin/article/details/107180516 yum参考 ...
- coolshell-初见
首页:https://coolshell.cn/tag/programmer 我是怎么招聘程序员的 https://coolshell.cn/articles/1870.html 程序员需要具备的基本 ...
- 一个程序的执行时间可以使用time+命令形式来获得
编写程序testtime.c #include <stdio.h> //这个头一定要加 #include<time.h> main() { time_t timep; time ...
- 踩了个DNS解析的坑,但我还是没想通
hello大家好,我是小楼. 最近踩了个DNS解析的小坑,虽然问题解决了,但排查过程比较曲折,最后还是有一点没有想通,整个过程分享给大家. 背景 最近负责的服务要置换机器.置换机器可能很多小伙伴不知道 ...
- partTwo自动出题程序第一阶段
课堂测试1:像二柱子那样,花二十分钟写一个能自动生成30道小学四则运算题目的 "软件" 代码实现 import java.util.Random;//import java.uti ...
- GO语言学习——运算符
运算符 Go 语言内置的运算符有: 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 算术运算符 运算符 描述 + 相加 - 相减 * 相乘 / 相除 % 求余 注意: ++(自增)和--(自 ...
- “如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
"如何实现集中管理.灵活高效的CI/CD"在线研讨会精彩片段分享 片段主讲人:李培(西瓜刀) 大家好,我是李培.前面听文老师讲DevOps,包括CI/CD 的一些理论,也是挺有 ...
- Hadoop(一)Hadoop核心架构与安装
Hadoop是什么 大白话,Hadoop是个存储数据,计算数据的分布式框架.核心组件是HDFS.MapReduce.Yarn. HDFS:分布式存储 MapReduce:分布式计算 Yarn:调度Ma ...