[BUG] Server failed to authenticate the request. Make sure the value of Authorization header...
Describe the bug An exception occurred when I used azure-sdk-for-javva to create eventhub in China Azure and enable capture.If I had not enabled capture, I could have created eventhub successfully.
Exception or Stack Trace Exception in thread "main" java.lang.RuntimeException: com.microsoft.azure.storage.StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. at rx.exceptions.Exceptions.propagate(Exceptions.java:57) at com.microsoft.azure.management.eventhub.implementation.EventHubImpl$CaptureSettings$4$1.call(EventHubImpl.java:571) at com.microsoft.azure.management.eventhub.implementation.EventHubImpl$CaptureSettings$4$1.call(EventHubImpl.java:564) at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:48) at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:33) at rx.Observable.unsafeSubscribe(Observable.java:10327) at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100) at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:230) at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: com.microsoft.azure.storage.StorageException: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. at com.microsoft.azure.storage.StorageException.translateFromHttpStatus(StorageException.java:175) at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:94) at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:315) at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:175) at com.microsoft.azure.storage.blob.CloudBlobContainer.exists(CloudBlobContainer.java:769) at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:379) at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:326) at com.microsoft.azure.management.eventhub.implementation.EventHubImpl$CaptureSettings$4$1.call(EventHubImpl.java:569) ... 13 more
Code Snippet package CreateEventhub.CreateEventhubDemo; import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.Azure; import com.microsoft.azure.management.eventhub.EventHub; import com.microsoft.azure.management.storage.StorageAccount; import com.microsoft.rest.LogLevel; /**
-
Hello world! * */ public class App { public static Azure azure;
public static void main(String[] args) {
initByApplicationTokenCredentials(); createEventHub();}
public static void initByApplicationTokenCredentials() { ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( "clientid", "tenantid", "client secret" , AzureEnvironment.AZURE_CHINA); azure = Azure.configure() .withLogLevel(LogLevel.BASIC) .authenticate(credentials) .withSubscription("subid"); }
public static void createEventHub() { String namespaceId = "namesapce resource id"; StorageAccount storageAccountInUse = null; for(StorageAccount storageAccount : azure.storageAccounts().list()) { if(storageAccount.name().equals("devaccount1")) { storageAccountInUse = storageAccount; System.out.println("get StorageAccount"); System.out.println(storageAccountInUse.name()); break; } }
EventHub eventHub1 = azure.eventHubs() .define("devnewtopic") .withExistingNamespaceId(namespaceId) .withExistingStorageAccountForCapturedData(storageAccountInUse, "cc-dev-container1") .withDataCaptureEnabled() .withDataCaptureFileNameFormat("mytest/{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}") .withDataCaptureWindowSizeInMB(1) .withDataCaptureWindowSizeInSeconds(60) .withDataCaptureSkipEmptyArchives(true) .withPartitionCount(1) .withRetentionPeriodInDays(3) .create();}
}
Expected behavior Hopefully you can successfully create eventhub and enable capture
Setup (please complete the following information):
- OS: Windows Server 2016
- IDE : Eclipse
- Version of the Library used:
java version "11.0.2"
com.microsoft.azure azure 1.31.0
I was also unable to create eventhub and enable capture using the C# SDK, but it is possible to use the rest API, so I suspect it may be a issue with the SDK. I suspect that the underlying SDK USES Global Azure Storage's endpoint by default.Here are the exceptions thrown in the C# SDK:
@chenzheng1988 Thanks for reporting this. By the StatusDescription(last line) provided from C# SDK, it seems the specified storage account you used is disabled. Can you try with other accounts and check if it would also fail? Meanwhile, I will try to reproduce from my side.
@chenzheng1988 Close this as no response. Please feel free to reopen if you still face same issue.