Troubleshooting 'ResourceNotFound' Error Retrieving Container ACL with Azure SDK for JAVA

Lior Shahar 20 Reputation points
2024-05-16T10:37:51.95+00:00

How can I troubleshoot a persistent "ResourceNotFound" error when attempting to execute the "Get Container ACL" operation with the Azure SDK for JAVA? I have assigned the correct resources and read privileges, and tried the following code snippet:

BlobServiceClientBuilder builder = new BlobServiceClientBuilder().connectionString(connectionString);BlobContainerProperties containerProperties = builder.buildClient().getBlobContainerClient(containerName).getProperties();  BlobContainerAccessPolicies accessPolicies = containerProperties.getAccessPolicy(); 
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,778 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,507 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anand Prakash Yadav 6,940 Reputation points Microsoft Vendor
    2024-05-17T10:09:17.4233333+00:00

    Hello Lior Shahar,

    Thank you for posting your query here!

    I understand you are getting "ResourceNotFound" error while attempting to execute the "Get Container ACL" operation with the Azure SDK for Java. There are a few possible reasons for this, please verify the below aspects:

    · Verify and update the connection string. You can find the connection string in the Azure portal, under the "Access keys" section of the storage account. You can also regenerate the account key if it has been compromised or expired.

    · Verify that the account has the necessary permissions to read container properties.

    · If possible, try to change the public access level of the container to ‘Enable from all networks’ and check.

    · Please ensure that you are using an updated version of the Azure SDK for Java.

    Please check with the following code and let us know if it helps:

    import com.azure.storage.blob.BlobContainerClient;
    import com.azure.storage.blob.BlobServiceClient;
    import com.azure.storage.blob.BlobServiceClientBuilder;
    import com.azure.storage.blob.models.BlobContainerAccessPolicies;
    import com.azure.storage.blob.models.BlobContainerProperties;
    import com.azure.storage.blob.models.PublicAccessType;
    public class AzureBlobExample {
        public static void main(String[] args) {
            String connectionString = "<your_connection_string>";
            String containerName = "<your_container_name>";
            // Build the BlobServiceClient
            BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
                .connectionString(connectionString)
                .buildClient();
            // Get the BlobContainerClient
            BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient(containerName);
            // Check if the container exists
            if (blobContainerClient.exists()) {
                try {
                    // Get container properties
                    BlobContainerProperties containerProperties = blobContainerClient.getProperties();
                    System.out.println("Container properties retrieved successfully.");
                    // Get container access policies
                    BlobContainerAccessPolicies accessPolicies = blobContainerClient.getAccessPolicy();
                    PublicAccessType publicAccess = accessPolicies.getBlobAccessType();
                    System.out.println("Public access type: " + publicAccess);
                    accessPolicies.getIdentifiers().forEach(identifier -> {
                        System.out.println("Policy ID: " + identifier.getId());
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                System.err.println("Error: Container not found.");
            }
        }
    }
    
    

    You may also enable logging to get detailed information about the operations being performed and the specific point of failure.

    Do let us know if you have any further queries. I’m happy to assist you further.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


1 additional answer

Sort by: Most helpful
  1. Lior Shahar 20 Reputation points
    2024-05-19T07:09:22.27+00:00

    Thank you for your response and the troubleshooting advice. I followed the recommended steps, but unfortunately, I am still encountering the same issue. Specifically, when I call blobContainerClient.getAccessPolicy(), I continue to receive the same error message: "ResourceNotFound"

    Here is a summary of what I have tried so far based on your advice:

    1. Verified Resource Existence: Double-checked that the container mycontainer exists in the storage account and that it is accessible.
    2. Checked Permissions: Confirmed that the user has the necessary read privileges to access the container's ACL.
    3. Correct URL and Format
    4. API Version: Made sure that the API version used is up-to-date and supported for the operation.

    Despite these efforts, the issue persists. Is there anything else I might be overlooking or additional steps I should take to resolve this error? Any further insights or suggestions would be greatly appreciated.

    Thank you for your continued support!

    0 comments No comments