[ 
https://issues.apache.org/jira/browse/CAMEL-27184?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-27184.
---------------------------------
    Resolution: Fixed

Fixed by https://github.com/apache/camel/pull/30548 (merged to main as 
a5fa0ce1b6e6), in 4.24.0. Thanks DakshinJeeva.

_Claude Code on behalf of davsclaus_

> camel-azure-cosmosdb - producer ignores the create*IfNotExists endpoint 
> options
> -------------------------------------------------------------------------------
>
>                 Key: CAMEL-27184
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27184
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-azure
>            Reporter: Claus Ibsen
>            Priority: Major
>             Fix For: 4.24.0
>
>
> h3. Problem
> The endpoint options {{createDatabaseIfNotExists}} and 
> {{createContainerIfNotExists}} have no effect on the producer. Only the 
> headers {{CamelAzureCosmosDbCreateDatabaseIfNotExist}} / 
> {{CamelAzureCosmosDbCreateContainerIfNotExist}} work. The consumer uses the 
> options correctly.
> {{CosmosDbConfigurationOptionsProxy}} reads them as:
> {code:java}
> public boolean isCreateDatabaseIfNotExist(final Exchange exchange) {
>     return getOption(exchange, 
> CosmosDbConstants.CREATE_DATABASE_IF_NOT_EXIST, 
> configuration::isCreateDatabaseIfNotExists,
>             boolean.class);
> }
> {code}
> {{getOption}} falls back to the configuration only when the header value is 
> empty. But {{Message.getHeader(name, boolean.class)}} returns 
> {{Boolean.FALSE}} (not null) for a missing header 
> ({{DefaultMessage.getHeader(String, Class)}}), so the fallback is never used 
> and the producer always gets {{false}} unless the header is set.
> h3. How to reproduce
> {noformat}
> from("direct:start")
>     
> .to("azure-cosmosdb:shop2/orders?operation=createItem&createDatabaseIfNotExists=true"
>         + 
> "&createContainerIfNotExists=true&containerPartitionKeyPath=/region&databaseEndpoint=...&accountKey=...");
> {noformat}
> With the database missing, sending an item fails with {{Collection 'orders' 
> not found in database 'shop2'}}; the database is not created. Setting the two 
> headers to {{true}} instead creates the database, the container and the item.
> The Kamelet {{azure-cosmosdb-sink}} works around this by also setting the two 
> headers.
> h3. Where
> {{components/camel-azure/camel-azure-cosmosdb/src/main/java/org/apache/camel/component/azure/cosmosdb/CosmosDbConfigurationOptionsProxy.java}}
>  - {{isCreateDatabaseIfNotExist}}, {{isCreateContainerIfNotExist}} (used by 
> {{CosmosDbProducer.getContainerOperations}} / {{getDatabaseOperations}}). 
> These are the only two {{boolean.class}} reads in the camel-azure modules.
> h3. Suggested fix
> Read the header as {{Boolean.class}} so that a missing header is null and the 
> endpoint option is used:
> {code:java}
> return getOption(exchange, CosmosDbConstants.CREATE_DATABASE_IF_NOT_EXIST, 
> configuration::isCreateDatabaseIfNotExists,
>         Boolean.class);
> {code}
> (same for the container), plus a unit test with the endpoint option only.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to