Camel Azure Blob produces Message with BlobContainerItem

Viewed 42

I have a camel route to list all blobs in azure blobstorage. But the exchange body does not has a list of BlobItem but BlobContainerItem resulting in a ClassCastException with my code

ClassCastException: class com.azure.storage.blob.models.BlobContainerItem cannot be cast to class com.azure.storage.blob.models.BlobItem

from("timer://listAllBlobs?fixedRate=true&period=1s")
.to("azure-storage-blob://devstoreaccount1/hotfolder&serviceClient=#blobServiceClient&operation=listBlobs")
.tracing()
.process(exchange -> {
    ArrayList<BlobItem> items = exchange.getIn().getBody(ArrayList.class);
    for (BlobItem blobItem : items) {
        System.out.println(blobItem.getName());
    }
});

With

ArrayList<BlobContainerItem> items = exchange.getIn().getBody(ArrayList.class);
  for (BlobContainerItem blobItem : items) {
    System.out.println(blobItem.getName());
  }

I get the output hotfolder. But that are not the files in it but the container itself.

How to iterate over the blobs correctly?

1 Answers

The problem is the malformed url (? and &). This calls

GET /devstoreaccount1?comp=list HTTP/1.1" 200 -

The correct url is azure-storage-blob://devstoreaccount1/hotfolder?serviceClient=#blobServiceClient&operation=listBlobs Which calls

GET /devstoreaccount1/hotfolder?restype=container&comp=list HTTP/1.1" 200 -

Related