This is an automated email from the ASF dual-hosted git repository. Croway pushed a commit to branch fix-vault-example in repository https://gitbox.apache.org/repos/asf/camel-spring-boot-examples.git
commit c72c66c09455f9629be763b3c4cd96aed5dc0872 Author: croway <[email protected]> AuthorDate: Fri Sep 4 10:42:07 2026 +0200 Fix vault example: correct hashicorp property separator and unmarshalled JDBC result camel-hashicorp-vault resolves {{hashicorp:secret:<path>#<key>}} using '#' to separate the secret path from the field key, not '/'. The datasource bean used '/', so the placeholders never resolved and the app failed to start against a real Vault. Also aligned the README's secret name (myDatabase) with the path actually used in cars-datasource.yaml (database). Separately, GET /api/cars 500'd with NoTypeConversionAvailableException converting the JDBC SELECT's ArrayList result to InputStream for the text/plain REST response. Marshal the result to JSON (adding camel-jackson-starter) and serve it as application/json instead. Verified end-to-end against real Vault and Postgres containers: app starts, GET returns [], POST inserts a row, GET then returns it. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HseDjsECuZhsCXxxioiD1k --- vault/pom.xml | 4 ++++ vault/readme.adoc | 6 ++++-- vault/src/main/resources/camel/cars-api.yaml | 2 +- vault/src/main/resources/camel/cars-datasource.yaml | 6 +++--- vault/src/main/resources/camel/cars-routes.yaml | 3 +++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/vault/pom.xml b/vault/pom.xml index 6b56be2d..08a1ea03 100644 --- a/vault/pom.xml +++ b/vault/pom.xml @@ -100,6 +100,10 @@ <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-jsonpath-starter</artifactId> </dependency> + <dependency> + <groupId>org.apache.camel.springboot</groupId> + <artifactId>camel-jackson-starter</artifactId> + </dependency> <!-- db driver --> <dependency> diff --git a/vault/readme.adoc b/vault/readme.adoc index 265e9b08..f0cd2ea9 100644 --- a/vault/readme.adoc +++ b/vault/readme.adoc @@ -7,15 +7,17 @@ Run HashiCorp Vault docker run --cap-add=IPC_LOCK -e 'VAULT_DEV_ROOT_TOKEN_ID=myroot' -e 'VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200' -p 8200:8200 hashicorp/vault:1.16.1` -Go to `http://localhost:8200/ui/vault/secrets/secret/kv/list` login with method Token and token `myroot` and create the following secrets: +Go to `http://localhost:8200/ui/vault/secrets/secret/kv/list` login with method Token and token `myroot` and create the following secret: -* a secret named `myDatabase` +* a secret named `database` * a secret data `myPassword` with value `mysecretpassword` * a secret data `myUsername` with value `postgres` * a secret data `myJdbcURL` with value `jdbc:postgresql://localhost:5432/postgres` image::img/secret-database.png[] +NOTE: the screenshot above shows the secret named `myDatabase` from an earlier version of this example; name the secret `database` as described above so it matches the path used in `cars-datasource.yaml`. + Run the database container docker run -p 5432:5432 --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword postgres diff --git a/vault/src/main/resources/camel/cars-api.yaml b/vault/src/main/resources/camel/cars-api.yaml index 2a3c64d3..98e2a9f7 100644 --- a/vault/src/main/resources/camel/cars-api.yaml +++ b/vault/src/main/resources/camel/cars-api.yaml @@ -20,7 +20,7 @@ get: - path: cars to: direct:get - produces: text/plain + produces: application/json post: - path: cars to: direct:create diff --git a/vault/src/main/resources/camel/cars-datasource.yaml b/vault/src/main/resources/camel/cars-datasource.yaml index 746c9693..1cd144e5 100644 --- a/vault/src/main/resources/camel/cars-datasource.yaml +++ b/vault/src/main/resources/camel/cars-datasource.yaml @@ -20,6 +20,6 @@ type: org.springframework.jdbc.datasource.DriverManagerDataSource properties: driverClassName: 'org.postgresql.Driver' - url: '{{hashicorp:secret:database/myJdbcURL}}' - username: '{{hashicorp:secret:database/myUsername}}' - password: '{{hashicorp:secret:database/myPassword}}' + url: '{{hashicorp:secret:database#myJdbcURL}}' + username: '{{hashicorp:secret:database#myUsername}}' + password: '{{hashicorp:secret:database#myPassword}}' diff --git a/vault/src/main/resources/camel/cars-routes.yaml b/vault/src/main/resources/camel/cars-routes.yaml index 8d7e207d..ccebf17a 100644 --- a/vault/src/main/resources/camel/cars-routes.yaml +++ b/vault/src/main/resources/camel/cars-routes.yaml @@ -69,3 +69,6 @@ uri: jdbc parameters: dataSourceName: datasource + - marshal: + json: + library: Jackson
