【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is m

问题描述

使用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

 

原文地址:https://www.cnblogs.com/lulight/p/16314741.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Microsoft云包括了Azure、PowerPlatform、Microsoft365、GitHub、Dynamics365等,虽然许多企业应用程序开发领导者了解在Azure上创建应用程序的价值,但事实是您可以将整个Microsoft云作为应用程序平台.有一篇文章:在Microsoft云上构建应用程序从应用程序开发角度介绍了M
《WindowsAzurePlatform系列文章目录》 我们在使用AzureAPIManagement(APIM)实现服务网关的时候,一般都是面向互联网的。比如场景一:AzureAPIManagement保护AzureVM上部署的ApacheWebService,客户端是来自于Internet的用户。整体的数据流是:用户->I
微软免费使用一年的Azure虚拟机,默认提供了一个64G的磁盘,但是系统却只给分配了32个G,尝试了几次扩大分区,最终都导致系统崩溃了,只能重新开虚拟机,无奈,只好网上找来现成的脚本,自动调整分区大小,只需要输入想调整为多少G即可,终于成功把系统分区扩大了。更改分区大小的脚本:if[[$#-eq
2022年5月25日,Meta公司选择Azure作为战略云供应商,推进人工智能创新,深化PyTorch合作https://azure.microsoft.com/en-us/blog/meta-selects-azure-as-strategic-cloud-provider-to-advance-ai-innovation-and-deepen-pytorch-collaboration/微软致力于负责任地推进人工智能的
上篇请访问这里做一个能对标阿里云的前端APM工具(上)样本多样性问题上一小节中的实施方案是微观的,即单次性的、具体的。但是从宏观上看,我需要保证性能测试是公允的,符合大众预期的。为了达到这种效果,最简单的方式就是保证测试的多样性,让足够多人访问产生足够多的样本来,但这对于一个
一年一度的MicrosoftBuild终于来了,带来了非常非常多的新技术和功能更新。不知道各位小伙伴有没有和我一样熬夜看了开幕式和五个核心主题的全过程呢?接下来我和大家来谈一下作为开发者最应关注的七大方向技术更新。AI能力的提升1.AzureOpenAIService终于来了开发人员可
问题描述使用AzureStorageAccount的共享访问签名(ShareAccessSignature)生成的终结点,连接时遇见  TheAzureStorageendpointurlismalformed(Azure存储终结点URL格式不正确)StorageAccountSDKinpom.xml:<dependency><groupId>com.azure</groupI
Azure提供的负载均衡服务叫LoadBalancer,它工作在ISO七层模型的第四层,通过分析IP层及传输层(TCP/UDP)的流量实现基于"IP+端口"的负载均衡。AzureLoadBalancer的主要功能负载均衡基于ISO四层的负载均衡,请参考下图(此图来自互联网):端口转发通过创建入站NAT规则,
各位好,今天继续来讨论关于Azure平台的技术问题,这次我们来讨论关于监控的话题,各个云平台都会为用户预留获取监控数据的接口,Azure也不例外,拿最基础用法来说,用户可以从AzurePortal中获取所需要的监控信息,比如Azure虚拟机的磁盘IO,CPU百分比,内存等,除此之外,还可以通过定义各种action,针对
在以往我们创建高可用Web应用程序时,负载均衡器是必不可少的组件。我们都使用传统内部服务器的负载均衡器,其中我们的应用程序在N个实例上运行,负载均衡器位于这些服务器的前面,并根据某些预定义的算法和设置向后端服务器分配负载。迁移到云中,我们需要了解如何使用Azure组件实现相同的
AzureEventGrid是一个托管事件路由平台,使我们能够实时响应Azure中托管的应用程序或拥有的任何Azure资源中发生的更改。EventGrid处理来自Azure服务的内置Azure事件以及来自应用程序的自定义事件,并实时发布它们。它可以每秒动态扩展和处理数百万个事件,Azure为生产工作负载提供99.
今天来谈一谈automation中另外一个很关键的内容,也就是updatemanagement,不同于configurationmanagement,updatemanagement主要用于管理windows以及LinuxVM中的补丁内容,当然和configurationmanagement一样,updatemanagement不仅仅可以管理Windows中VM的补丁,也可以管理non-Azure
下边来谈一谈Azure中Alert更多的应用,正常来说,云厂商都会有自己的SLA保证,比如目前来说,在可用性集里的虚拟机,SLA是99.95%,这点可以从商务角度保护客户的一部分利益。但是,从技术上来说,任何云都不可能保证100%的可用性,所以有些时候也会出现一些service的outage,对用户来说,第一时间知晓这
MicrosoftAzure中提供了多种类型和大小的虚拟机,我们将通过本来来了解下微软具体提供了哪些类型和大小的虚拟机,以方便在项目过程中进行评估。类型大小说明常规用途B,Dsv3,Dv3, DSv2,Dv2,Av2, DCCPU 与内存之比平衡。适用于测试和开发、小到中型数据库和低到中等流量Web
假定我们正在运行某个应用程序,此应用程序需要用户在应用程序中提交大量图片文件,那么对于系统管理员来说手动审核这些图片是很消耗时间的,并且对于图片的审核也许并不是即时的。为了解决这一问题,这篇文章将向大家演示如何使用AzureFunction和CognitiveServices来对上传到应用程序的
中国-北京[2018.12.10]2018年12月7日,历时60余天,在超过150+的面试中,21家企业经三轮筛选晋级终审,最终14家企业在激烈的角逐中成功入选微软加速器·北京13期创新企业名单。颉一软件有幸拔得头筹,很快将与MicrosoftAzure开展深度合作,开启全面加速企业级用户数字化转型之路!微软加速器·
假定我们有某个应用程序会将文件存储到AzureBlob中,存储在Blob中的数据保存七天,七天以后需要对其进行删除。这需求可以使用AzurePowerShellRunbook来完成,但是我想看看是否可以用很少甚至没有代码来完成。经过一番探索我发现AzureLogicApp非常适合这种情况。你可以用LogicApp创
接下来继续之前给各位介绍的内容,我们接着来谈下Azureautomation中关于configurationmanagement的内容,上一篇中介绍了关于inventory的应用,通过inventory,可以快速收集Azure与非Azure服务器中的资产信息。除此之外,configurationmanagement中changetracking也是个非常实用的功能,通
安全分层方法 数据几乎所有情况下,攻击者都会攻击以下数据:存储在数据库中的数据存储在虚拟机磁盘上的数据存储在Office365等SaaS应用程序上的数据存储在云存储中的数据存储数据和控制数据访问权限的人员有责任确保数据得到恰当保护。通常情况下,存在相应法规要
生成云应用程序时需要应对的常见挑战是,如何管理代码中用于云服务身份验证的凭据。保护这些凭据是一项重要任务。理想情况下,这些凭据永远不会出现在开发者工作站上,也不会被签入源代码管理系统中。虽然AzureKeyVault可用于安全存储凭据、机密以及其他密钥,但代码需要通过KeyVa