1

My goal is to monitor the hello directory for any new file creation. Once new file created it should trigger API and upload the file which got created inside the hello directory into azure. I'm getting below exception. Can someone help me on this ?

WatcherRoute.java

 @Service
    public class WatcherRoute extends RouteBuilder {
    
      @Override
      public void configure() {
    
        String accessKey = "key";
        String baseUrl = "base/url";
    
    
        from("file-watch:hello?events=CREATE&antInclude=**/*.txt&recursive=true")
            .to("direct:start","direct:uploadFileToBlob")
            .end();
    
        from("direct:uploadFileToBlob")
            .to("azure-storage-blob://storage-account-name/containerName?blobName=test.txt&accessKey="+getBase64EncodedCipherText(accessKey))
            .end();
    
        from("direct:start")
            .setHeader(Exchange.HTTP_METHOD, constant("GET"))
            .setHeader("Content-Type",constant("application/json"))
            .to(baseUrl)
            .process(logResponse)
            .end();
      }
    
       private String getBase64EncodedCipherText(String cipherText) {
        byte[] cText = cipherText.getBytes();
        return Base64.getEncoder().encodeToString(cText);
      }
    }

Exception Trace:

2021-12-29 09:33:59.604 ERROR 78488 --- [elFileWatchPoll] o.a.c.p.e.DefaultErrorHandler            : Failed delivery for (MessageId: 18CB93B18D0D95B-0000000000000001 on ExchangeId: 18CB93B18D0D95B-0000000000000001). Exhausted after delivery attempt: 1 caught: com.azure.storage.blob.models.BlobStorageException: If you are using a StorageSharedKeyCredential, and the server returned an error message that says 'Signature did not match', you can compare the string to sign with the one generated by the SDK. To log the string to sign, pass in the context key value pair 'Azure-Storage-Log-String-To-Sign': true to the appropriate method call.
If you are using a SAS token, and the server returned an error message that says 'Signature did not match', you can compare the string to sign with the one generated by the SDK. To log the string to sign, pass in the context key value pair 'Azure-Storage-Log-String-To-Sign': true to the appropriate generateSas method call.
Please remember to disable 'Azure-Storage-Log-String-To-Sign' before going to production as this string can potentially contain PII.
Status code 403, "<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:{id}
Time:2021-12-29T15:33:59.4459965Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'example' is not the same as any computed signature. Server used following string to sign: 'GET
TechGeek
  • 480
  • 1
  • 8
  • 22

1 Answers1

0

You can try with using the below solutions:

Solution 1: If you used the primary connection string, try with changing the connection string to secondary

Solution 2: Authentication for Azure Storage is not simply a matter of providing the access key (that is not very secure). You need to create a signature string that represents the given request, sign the string with the HMAC-SHA256 algorithm (using your storage key to sign), and encode the result in base 64. See https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx for the more details.

Solution 3: If you are using shared access signature (SAS) for Authentication ,Check if its expired and recreate it and run again.

For more details refer this SO Thread:

ShrutiJoshi-MT
  • 1,622
  • 1
  • 4
  • 9