问题描述

使用Azure Storage Account的共享访问签名(Share Access Signature) 生成的终结点,连接时遇见  The Azure Storage endpoint url is malformed (Azure 存储终结点 URL 格式不正确)

Storage Account SDK in pom.xml:

  1. <dependency>
  2. <groupId>com.azure</groupId>
  3. <artifactId>azure-storage-blob</artifactId>
  4. <version>12.6.0</version>
  5. </dependency>

App.Java 文件中,创建 BlobServiceClient 对象代码:

  1. String endpoint ="BlobEndpoint=https://://************...";
  2. 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

  1. 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'

  2. Azure Blob storage v12 - Java quickstart sample
  3.  
  4. 2022-05-26 10:24:29 ERROR BlobServiceClientBuilder - The Azure Storage endpoint url is malformed.
  5. Exception in thread "main" java.lang.IllegalArgumentException: The Azure Storage endpoint url is malformed.
  6. at com.azure.storage.blob.BlobServiceClientBuilder.endpoint(BlobServiceClientBuilder.java:132)
  7. 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

  1. //使用连接字符串时
    String connectStr ="BlobEndpoint=https://:************.blob.core.chinacloudapi.cn/;...SharedAccessSignature=sv=2020-08-0...&sig=**************";
  2. BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();

  3. //使用SAS终结点
  4. String endpoint ="https://************.blob.core.chinacloudapi.cn/?sv=2020-08-04...&sig=*********************";
  5. BlobServiceClient blobServiceClientbyendpoint = new BlobServiceClientBuilder().endpoint(endpoint).buildClient();

完整的示例代码:

  1. package com.blobs.quickstart;
  2.  
  3. /**
  4. * Azure blob storage v12 SDK quickstart
  5. */
  6. import com.azure.storage.blob.*;
  7. import com.azure.storage.blob.models.*;
  8. import java.io.*;
  9.  
  10. public class App
  11. {
  12. public static void main( String[] args ) throws IOException
  13. {
  14.  
  15. System.out.println("Azure Blob storage v12 - Java quickstart sample\n");
  16.  
  17. // Retrieve the connection string for use with the application. The storage
  18. // connection string is stored in an environment variable on the machine
  19. // running the application called AZURE_STORAGE_CONNECTION_STRING. If the environment variable
  20. // is created after the application is launched in a console or with
  21. // Visual Studio, the shell or application needs to be closed and reloaded
  22. // to take the environment variable into account.
  23.  
  24. //String connectStr ="DefaultEndpointsProtocol=https;AccountName=******;AccountKey=***********************;EndpointSuffix=core.chinacloudapi.cn";// System.getenv("AZURE_STORAGE_CONNECTION_STRING");
  25. 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=*************************";
  26. BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
  27.  
  28. //Create a unique name for the container
  29. String containerName = "lina-" + java.util.UUID.randomUUID();
  30.  
  31. // Create the container and return a container client object
  32. BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);
  33.  
  34. BlobContainerClient containerClient1 = blobServiceClient.getBlobContainerClient("container-name");
  35.  
  36. if(!containerClient1.exists())
  37. {
  38. System.out.println("create containerName");
  39. blobServiceClient.createBlobContainer("container-name");
  40. }
  41.  
  42. System.out.println("create containerName .....");
  43. // // Create a local file in the ./data/ directory for uploading and downloading
  44. // String localPath = "./data/";
  45. // String fileName = "quickstart" + java.util.UUID.randomUUID() + ".txt";
  46. // File localFile = new File(localPath + fileName);
  47.  
  48. // // Write text to the file
  49. // FileWriter writer = new FileWriter(localPath + fileName, true);
  50. // writer.write("Hello, World!");
  51. // writer.close();
  52.  
  53. // // Get a reference to a blob
  54. // BlobClient blobClient = containerClient.getBlobClient(fileName);
  55.  
  56. // System.out.println("\nUploading to Blob storage as blob:\n\t" + blobClient.getBlobUrl());
  57.  
  58. // // Upload the blob
  59. // blobClient.uploadFromFile(localPath + fileName);
  60.  
  61. // System.out.println("\nListing blobs...");
  62.  
  63. // // List the blob(s) in the container.
  64. // for (BlobItem blobItem : containerClient.listBlobs()) {
  65. // System.out.println("\t" + blobItem.getName());
  66. // }
  67.  
  68. // // Download the blob to a local file
  69. // // Append the string "DOWNLOAD" before the .txt extension so that you can see both files.
  70. // String downloadFileName = fileName.replace(".txt", "DOWNLOAD.txt");
  71. // File downloadedFile = new File(localPath + downloadFileName);
  72.  
  73. // System.out.println("\nDownloading blob to\n\t " + localPath + downloadFileName);
  74.  
  75. // blobClient.downloadToFile(localPath + downloadFileName);
  76.  
  77. // // Clean up
  78. // System.out.println("\nPress the Enter key to begin clean up");
  79. // System.console().readLine();
  80.  
  81. // System.out.println("Deleting blob container...");
  82. // containerClient.delete();
  83.  
  84. // System.out.println("Deleting the local source and downloaded files...");
  85. // localFile.delete();
  86. // downloadedFile.delete();
  87.  
  88. System.out.println("Done");
  89. }
  90. }

参考资料

快速入门:使用 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的更多相关文章

  1. 玩转Windows Azure存储服务——网盘

    存储服务是除了计算服务之外最重要的云服务之一.说到云存储,大家可以想到很多产品,例如:AWS S3,Google Drive,百度云盘...而在Windows Azure中,存储服务却是在默默无闻的工 ...

  2. 【Azure 存储服务】代码版 Azure Storage Blob 生成 SAS (Shared Access Signature: 共享访问签名)

    问题描述 在使用Azure存储服务,为了有效的保护Storage的Access Keys.可以使用另一种授权方式访问资源(Shared Access Signature: 共享访问签名), 它的好处可 ...

  3. 解读 Windows Azure 存储服务的账单 – 带宽、事务数量,以及容量

    经常有人询问我们,如何估算 Windows Azure 存储服务的成本,以便了解如何更好地构建一个经济有效的应用程序.本文我们将从带宽.事务数量,以及容量这三种存储成本的角度探讨这一问题. 在使用 W ...

  4. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例

    什么是表存储 Azure 表存储是一项用于在云中存储结构化 NoSQL 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...

  5. 微软开放技术开发了适用于 Windows Azure 移动服务的开源 Android SDK

     发布于 2014-02-10 作者 陈 忠岳 为进一步实现连接微软与非微软技术的目标,微软开放技术有限公司开发了适用于 Windows Azure 移动服务的 Android SDK,由Scot ...

  6. 玩转Windows Azure存储服务——高级存储

    在上一篇我们把Windows Azure的存储服务用作网盘,本篇我们继续挖掘Windows Azure的存储服务——高级存储.高级存储自然要比普通存储高大上的,因为高级存储是SSD存储!其吞吐量和IO ...

  7. 跟我学Windows Azure 五 使用Cloub Service连接Blob Service完成图片的上传

    首先,我们创建一个云服务项目,用来演示我们的blob存储 下来我们修改我们我们云服务的名字 我们需要添加一个空的WebForm的项目 点击完成,我们可以看到我们的解决方案已经添加完成 下来我们需要添加 ...

  8. 【Azure 存储服务】Hadoop集群中使用ADLS(Azure Data Lake Storage)过程中遇见执行PUT操作报错

    问题描述 在Hadoop集中中,使用ADLS 作为数据源,在执行PUT操作(上传文件到ADLS中),遇见 400错误[put: Operation failed: "An HTTP head ...

  9. 【Azure 存储服务】如何把开启NFS 3.0协议的Azure Blob挂载在Linux VM中呢?(NFS: Network File System 网络文件系统)

    问题描述 如何把开启NFS协议的Azure Blob挂载到Linux虚拟机中呢? [答案]:可以使用 NFS 3.0 协议从基于 Linux 的 Azure 虚拟机 (VM) 或在本地运行的 Linu ...

随机推荐

  1. 聊一聊Web端的即时通讯

    聊一聊Web端的即时通讯 Web端实现即时通讯的方法有哪些? - 短轮询 长轮询 iframe流 Flash Socket 轮询 客户端定时向服务器发送Ajax请求,服务器接到请求后马上返回响应信息并 ...

  2. vue常用知识点总结

    感谢本文引用链接的各位大佬们,小菜鸟我只是个搬运工 1.谈一谈你理解的vue是什么样子的? vue是数据.视图分离的一个框架,让数据与视图间不会发生直接联系.MVVM 组件化:把整体拆分为各个可以复用 ...

  3. 初始化properties

    package com.letech.common; import java.io.IOException; import java.util.Properties; public class Con ...

  4. Spring 和 SpringMVC 常用注解和配置(@Autowired、@Resource、@Component、@Repository、@Service、@Controller的区别)

    Spring 常用注解 总结内容 一.Spring部分 1.声明bean的注解 2.注入bean的注解 3.java配置类相关注解 4.切面(AOP)相关注解 5.事务注解 6.@Bean的属性支持 ...

  5. Spring原始注解开发-02

    使用@Repository.@Service.@Controller注解配置,使其更加清晰属于哪一层,因为我是模拟的web层,所有没有使用@Controller注解,后面结合web开发会使用到 1.创 ...

  6. 安装 UE 源码版

    # 安装 UE 源码版 ## 下载安装包 > - 先去 Github 找 UE 官方开源的引擎组(这个需要申请加入) > - 加入后找到开源的源码版项目下载 zip 到本地 > - ...

  7. 时序数据库influxDB介绍

    https://www.jianshu.com/p/68c471bf5533 https://www.cnblogs.com/wzbk/p/10569683.html

  8. Python Json分别存入Mysql、MongoDB数据库,使用Xlwings库转成Excel表格

    将电影数据 data.json 数据通过xlwings库转换成excel表格,存入mysql,mongodb数据库中.python基础语法.xlwings库.mysql库.pymongo库.mongo ...

  9. setAttribute 和 getAttribute 的用法

    setAttribute()   是用于设置自定义属性的方法,有两个参数,第一个是属性名,第二个是属性值, 添加时必须用引号括起来: 此时的box就加上了一个自定义属性名和属性值,可以根据需要赋取 g ...

  10. Python识别图片中的文字

    1 import os,glob 2 def photo_compression(original_imgage,tmp_image_path): 3 '''图片备份.压缩:param origina ...