Description
openedon Jun 17, 2021
Describe the bug
When I'm configuring my cosmos db connection like this:
azure:
cosmos:
uri: mongodb://username:password@host:port/database?ssl=true
key: primary-key
secondaryKey: secondary-key
database: database
Please note, that port in this case: 10255
as advised in this tutorial: https://docs.microsoft.com/en-us/azure/cosmos-db/connect-mongodb-account#get-the-mongodb-connection-string-by-using-the-quick-start
Exception or Stack Trace
Caused by: java.lang.RuntimeException: Client initialization failed. Check if the endpoint is reachable and if your auth token is valid
at com.azure.cosmos.implementation.RxDocumentClientImpl.initializeGatewayConfigurationReader(RxDocumentClientImpl.java:388)
at com.azure.cosmos.implementation.RxDocumentClientImpl.init(RxDocumentClientImpl.java:415)
at com.azure.cosmos.implementation.AsyncDocumentClient$Builder.build(AsyncDocumentClient.java:241)
at com.azure.cosmos.CosmosAsyncClient.<init>(CosmosAsyncClient.java:123)
at com.azure.cosmos.CosmosClientBuilder.buildAsyncClient(CosmosClientBuilder.java:741)
at com.azure.spring.data.cosmos.CosmosFactory.createCosmosAsyncClient(CosmosFactory.java:70)
at com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration.cosmosAsyncClient(AbstractCosmosConfiguration.java:57)
at com.lendico.kycservice.config.AzureCosmosDbConfig$$EnhancerBySpringCGLIB$$5810af8c.CGLIB$cosmosAsyncClient$3(<generated>)
at com.lendico.kycservice.config.AzureCosmosDbConfig$$EnhancerBySpringCGLIB$$5810af8c$$FastClassBySpringCGLIB$$31264ac5.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at com.lendico.kycservice.config.AzureCosmosDbConfig$$EnhancerBySpringCGLIB$$5810af8c.cosmosAsyncClient(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 155 more
To Reproduce
Use configuration like (in application.yaml):
azure:
cosmos:
uri: mongodb://username:password@host:10255/database?ssl=true
key: primary-key
secondaryKey: secondary-key
database: database
Code Snippet
Add the code snippet that causes the issue.
Expected behavior
I would expect that I still can connect to cosmos db, no matter how I configured url
Two possible options are:
- working
azure:
cosmos:
uri: https://host:443/
key: primary-key
secondaryKey: secondary-key
database: database
- not working
azure:
cosmos:
uri: mongodb://username:password@host:10255/database?ssl=true
key: primary-key
secondaryKey: secondary-key
database: database
Screenshots
If applicable, add screenshots to help explain your problem.
Setup (please complete the following information):
- OS: MacOS Catalina
- IDE: Eclipse
- Library/Libraries:
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot-starter-cosmos</artifactId>
<version>3.4.0</version>
</dependency>
Additional context
I believe that I can see where the problem is (but obviously not 100% sure)
com.azure.cosmos.implementation.RxGatewayStoreModel -> private URI getUri(RxDocumentServiceRequest request) throws URISyntaxException
when uri is created:
return new URI("https",
null,
rootUri.getHost(),
rootUri.getPort(),
ensureSlashPrefixed(path),
null, // Query string not used.
null);
You use https, and if I'm not mistaken - https would require port 443, but in this instance you're retrieving it from root uri which looks like:
mongodb://username:password@host:10255/database?ssl=true
and where port passed is 10255
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added