0

I'm creating an Azure Function that downloads the XML of a given URL and stores the document in Cosmos DB at predefined times. Currently I develop the application locally in VSC with Java and also using the Cosmos DB Emulator. Within my code I instantiate a CosmosClient-object with the following code:

private static CosmosClient cosmosClient = new CosmosClientBuilder().endpoint("https://localhost:8081") .key("C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==").consistencyLevel(ConsistencyLevel.EVENTUAL).buildClient();

Whenever I run my code the programm executs but after at the end of the buildClient() method a huge amount of threads are created leading to the following error message:

Terminal error message:

enter image description here

I took the URL and the key from the web surface of the emulator so where is my mistake? Do I have to provide additional credentials.

SOLVED: I made the mistake, that I added the Azure Cosmos Emulator certificate to the wrong java keystore as the Azure guide mentioned. My system variables only showed at my user version of the JVM, while I loaded the certificate to the global JVM copy, therefore resulting to a signature failure. A complete solution was provided in this post.

JamaicaBot
  • 13
  • 4
  • huge amount of threads are not created, it is exception stack trace. the authentication has failed and the detailed exception is shown. check your key passed to Cosmos client builder. – Anand Sowmithiran Nov 30 '21 at 12:16
  • have you done [this](https://learn.microsoft.com/en-us/azure/cosmos-db/local-emulator-export-ssl-certificates)? adding Cosmos emulator cert to your java cert trust store. – Anand Sowmithiran Nov 30 '21 at 12:21
  • 1
    see the answer for this SO [question](https://stackoverflow.com/questions/41257366/import-windows-certificates-to-java), it shows example to set the properties `javax.net.ssl.trustStore` and `javax.net.ssl.trustStoreType`. – Anand Sowmithiran Nov 30 '21 at 12:31
  • Please edit your question to contain formatted text, not images of text, for your exception output. This [meta post](https://meta.stackoverflow.com/a/285557/272109) lists many reasons why this is important. – David Makogon Nov 30 '21 at 17:35
  • Thank you @AnandSowmithiran. Your second comment had solved the problem. Although I had already followed and executed the export and import of the certificate, I made the mistake to import the certificate into the wrong default keystore. – JamaicaBot Nov 30 '21 at 21:31
  • @DavidMakogon sorry I corrected my code and can't reproduce the error log. For future post I will copy the error log into my question. Thanks for your advice on that note. – JamaicaBot Nov 30 '21 at 21:32
  • @JamaicaBot ,I have added as answer as well so that others can find it easily, you could accept as answer. – Anand Sowmithiran Dec 01 '21 at 05:20

1 Answers1

0

From within Java azure function, connecting to local Azure CosmosDB Emulator fails in authentication step due to the CA certificate not present in the certificate trust store. By importing the CA cert, and setting the properties javax.net.ssl.trustStore and javax.net.ssl.trustStoreType the authentication step will go through. Details are in this SO answer and here.

Anand Sowmithiran
  • 2,591
  • 2
  • 10
  • 22