I really want to use container managed transactions with JPA and therefor would go the easy way of having the data source creation within the server.xml and then using the @PersistenceContext within my code.
The problem I currently face - and maybe I am thinking too complicated - is the fact that I get the credentials during runtime in my Cloud Foundry environment as VCAP_SERVICES system environment variable.
This VCAP_SERVICES variable contains a big JSON with the necessary credentials. Therefor I would first have to extract the corresponding JSON within this and pass it then as property.
My initial idea was to use converters for this case returning the values out of the JSON so that they can be used. But it seems like this is not possible within a defined configuration xml file.
What I for sure want to prevent is the "injection" of something doing on my own like having a property file and copying the values from the different environments DEV, TEST, PROD in there as the Cloud Foundry environment is already doing the job for me.
So the question is: How can I get the credentials from the VCAP_SERVICES system environment variable into the server.xml configuration? Remember: I really have to parse the VCAP_SERVICES variable as this is JSON and extract the values.
<?xml version="1.0" encoding="UTF-8"?>
<server description="Config example">
<featureManager>
<feature>javaee-8.0</feature>
<feature>mpMetrics-1.1</feature>
<feature>monitor-1.0</feature>
</featureManager>
<!-- Postgres config-example-db definition -->
<dataSource id="DefaultDataSource" jndiName="jdbc/config-example" jdbcDriverRef="postgresql-driver"
type="javax.sql.ConnectionPoolDataSource" transactional="true">
<properties serverName="config-example-db" portNumber="5432"
databaseName="postgres"
user="${config-example.db.username}"
password="${config-example.db.password}"/>
</dataSource>
<basicRegistry id="basic" realm="MicroProfileMetrics">
<user name="admin" password="adminadmin"/>
<user name="nonadmin" password="guest"/>
</basicRegistry>
<administrator-role>
<user>admin</user>
</administrator-role>
</server>