From c72c66c09455f9629be763b3c4cd96aed5dc0872 Mon Sep 17 00:00:00 2001 From: croway Date: Fri, 4 Sep 2026 10:42:07 +0200 Subject: [PATCH] Fix vault example: correct hashicorp property separator and unmarshalled JDBC result camel-hashicorp-vault resolves {{hashicorp:secret:#}} 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 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 6b56be2d6..08a1ea030 100644 --- a/vault/pom.xml +++ b/vault/pom.xml @@ -100,6 +100,10 @@ org.apache.camel.springboot camel-jsonpath-starter + + org.apache.camel.springboot + camel-jackson-starter + diff --git a/vault/readme.adoc b/vault/readme.adoc index 265e9b085..f0cd2ea95 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 2a3c64d3d..98e2a9f71 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 746c96935..1cd144e5f 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 8d7e207d1..ccebf17a2 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