0

I wrote below code to connect to Azure Blob Storage and list all files present in it.I get the error in eclipse and tried different ways but not helping.

    **Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.String io.netty.util.internal.ObjectUtil.checkNonEmptyAfterTrim(java.lang.String, java.lang.String)'
        at io.netty.handler.codec.http.HttpMethod.<init>(HttpMethod.java:123)
        at io.netty.handler.codec.http.HttpMethod.<clinit>(HttpMethod.java:36)
        at reactor.netty.http.client.HttpClientConfig.<init>(HttpClientConfig.java:334)
        at reactor.netty.http.client.HttpClientConnect.<init>(HttpClientConnect.java:86)
        at reactor.netty.http.client.HttpClient.create(HttpClient.java:392)
        at com.azure.core.http.netty.NettyAsyncHttpClientBuilder.build(NettyAsyncHttpClientBuilder.java:141)
        at com.azure.core.http.netty.NettyAsyncHttpClientProvider.createInstance(NettyAsyncHttpClientProvider.java:52)
        at com.azure.core.implementation.http.HttpClientProviders.createInstance(HttpClientProviders.java:67)
        at com.azure.core.http.HttpClient.createDefault(HttpClient.java:50)
        at com.azure.core.http.HttpClient.createDefault(HttpClient.java:40)
        at com.azure.core.http.HttpPipelineBuilder.build(HttpPipelineBuilder.java:73)
        at com.azure.storage.blob.implementation.util.BuilderHelper.buildPipeline(BuilderHelper.java:138)
        at com.azure.storage.blob.BlobServiceClientBuilder.buildAsyncClient(BlobServiceClientBuilder.java:135)
        at com.azure.storage.blob.BlobServiceClientBuilder.buildClient(BlobServiceClientBuilder.java:114)
        at com.oq.sap.azure.MarketerIndentFile.main(MarketerIndentFile.java:81)**

This is the code. Please check below. I tried to add some jars in the eclipse project but it keeps complaining about the method error. I'm trying to connect to Azure blob container and then download some files using java code. After that I want to perform few more operations.

package com.azure;

import java.io.IOException;
import java.util.Locale;

import com.azure.core.credential.AzureSasCredential;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;

/**
 * This example shows how to start using the Azure Storage Blob SDK for Java.
 */
public class BlobFile{

    /**
     * Entry point into the basic examples for Storage blobs.
     *
     * @param args Unused. Arguments to the program.
     * @throws IOException      If an I/O error occurs
     * @throws RuntimeException If the downloaded data doesn't match the uploaded
     *                          data
     */
    public static void main(String[] args) throws IOException {



        AzureSasCredential sas = new AzureSasCredential("?sv=2020-10-02&si=xxx&sr=c&sig=xxx");

        String endpoint = String.format(Locale.ROOT,
                "https://XYZ.blob.core.windows.net", "ABC");
        String containerName = "container name";
        BlobServiceClient BlobServiceClient = new BlobServiceClientBuilder().endpoint(endpoint).credential(sas).buildClient();

        BlobContainerClient blobContainerClient = BlobServiceClient.getBlobContainerClient(containerName);
        System.out.println("Listing blobs in the container: " + blobContainerClient.getBlobContainerUrl());
        blobContainerClient.listBlobs()
        .forEach(
                blobItem -> System.out.println("This is the blob name: " + blobItem.getName()));

    }
}

My Blob structure looks like below.

Azure Blob Structure

List of jars used in the eclipse project.

List of jars

Talha M
  • 11
  • 1
  • Please check the edited post. Apologies as I am new to the site and was having some difficulty in posting the code. – Talha M May 16 '22 at 10:34
  • which azure storage sdk version are you using? – Maytham Fahmi May 16 '22 at 11:02
  • I am using V12 of java api with the jar azure-storage-blob-12.16.1.jar. Is this the version you are looking for? – Talha M May 16 '22 at 11:36
  • kan you try with 12.16.0 and let me know – Maytham Fahmi May 16 '22 at 11:42
  • Thanks. I tried it but it didn't work and failed with the same error. I'm attaching the list of jars used in the eclipse project in the above post. These were added as per the eclipse error log during execution phase. – Talha M May 16 '22 at 12:28
  • ok, I will give it a shot when I home later :) – Maytham Fahmi May 16 '22 at 12:31
  • Thanks a lot for all your timely responses. – Talha M May 16 '22 at 12:35
  • What's the value of your `endpoint` variable? Also, please share your SAS token. Please obfuscate/change any sensitive information (like account name, sig portion of your SAS token) before sharing. – Gaurav Mantri May 16 '22 at 16:30
  • String endpoint = String.format(Locale.ROOT, "https://accountname.blob.core.windows.net", "abc"); "abc" is my storage name as shown the blob structure image above. SAS token looks like AzureSasCredential sas = new AzureSasCredential("?sv=2020-10-02&si=xxxl&sr=c&sig=xxx"); Please check. – Talha M May 16 '22 at 17:11
  • [Java Mission Control shows many NoSuchMethodError thrown while building blob client](https://github.com/Azure/azure-sdk-for-java/issues/28848) – Ecstasy May 19 '22 at 05:02
  • Thanks. But trying to find if I could get around with older versions of jars. I don't have maven dependencies in eclipse except what is added in the project. – Talha M May 19 '22 at 11:44

0 Answers0