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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HseDjsECuZhsCXxxioiD1k
diff --git a/vault/pom.xml b/vault/pom.xml
index 6b56be2..08a1ea0 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 265e9b0..f0cd2ea 100644
--- a/vault/readme.adoc
+++ b/vault/readme.adoc
@@ -7,15 +7,17 @@
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 2a3c64d..98e2a9f 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 746c969..1cd144e 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 8d7e207..ccebf17 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