Environment variables in JBoss datasource - jboss

I have a JBoss server running and want to deploy a service.
The service connects to a database which is configured in the following xml file
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<datasource jta="false" jndi-name="java:/PMBootStrapDS"
pool-name="PMBootStrapDS" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/i2b2</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgresql-9.2-1002.jdbc4.jar</driver>
<security>
<user-name>i2b2pm</user-name>
<password>demouser</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
</datasources>
To deploy it on different systems easily, I want to bind the database location to an environment variable.
I tried something like this
<connection-url>jdbc:postgresql://${env.MY_DB_LOCATION}/i2b2</connection-url>
but it doesn't work.
Any suggestions on how to solve this issue?

Make sure you have property substitution enabled in your standalone.xml.
Look for the following subsytem in standalone.xml, and make sure the values are set to true
<subsystem xmlns="urn:jboss:domain:ee:1.1">
<spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
<jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
</subsystem>
EDIT: This is only supported for eap6 and jboss 7.1.2 (or later)

Related

Widlfly 20: Web.xml and standalone.xml configs for datasource

I have a ejb-based application deployed initially in jboss AS 5.0 that i'm upgrading to wildfly 20, the problem is that i cant resolve correctly the datasources defined in web.xml in the datasource section in standalone.xml
<resource-ref>
<res-ref-name>Midd2</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<mapped-name>jdbc/SybaseDB</mapped-name>
</resource-ref>
<resource-ref>
<res-ref-name>Midd</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<mapped-name>jdbc/SybaseDS2</mapped-name>
</resource-ref>
My datasources in standalone.xml
<datasource jndi-name="java:/jdbc/SybaseDB" pool-name="SybaseDB">
<connection-url>jdbc:sybase:XXXX.XXXX.XXXX.XXXX/database</connection-url>
<driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class>
<driver>
jconn3.jar
</driver>
<security>
<user-name>x</user-name>
<password>y</password>
</security>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>5</max-pool-size>
</pool>
</datasource>
<datasource jndi-name="java:/jdbc/SybaseDS2" pool-name="SybaseDS2">
<connection-url>jdbc:sybase:XXXX.XXXX.XXXX.XXXX/database</connection-url>
<driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class>
<driver>
jconn3.jar
</driver>
<security>
<user-name>x</user-name>
<password>y</password>
</security>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>5</max-pool-size>
</pool>
</datasource>
But i'm getting
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.naming.context.java.module.Midd.Midd.env.Midd2 is missing [jboss.naming.context.java.module.Midd.Midd.env.jdbc.SybaseDB]",
"jboss.naming.context.java.module.Midd.Midd.env.Midd is missing [jboss.naming.context.java.module.Midd.Midd.env.jdbc.SybaseDS2]"
]
I've read a lot of docs in google but nothing that could help
Have you tried using the annotation to inject the data source?
#Resource(name = "jdbc/SybaseDB")
private DataSource dataSource1;
#Resource(name = "jdbc/SybaseDS2")
private DataSource dataSource2;
Where do you put the jconn3.jar?

Wildfly Default data source class name

I am using WildFly 11, I am trying to understand when we configure a data source with a specific driver and we don't set the data source class name explicitly, which actual implementation of javax.sql.DataSource does WF ends up using ?
<datasource jndi-name="java:jboss/datasources/myDB" pool-name="myDB" enabled="true" use-java-context="true" spy="false">
<connection-url>jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf8&useSSL=false</connection-url>
<driver>mysql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>5</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<background-validation-millis>10000</background-validation-millis>
</validation>
</datasource>
my application certainly works and I can see the interaction with the DB just fine, however I am not sure which actual datasource implementation is in use, I tried to configure a logger against MySQL packages that contains the default data sources, but nothing seems to get logged as a result.
WildFly is using ironjacamar (http://www.ironjacamar.org/) as its datasource implementation.

How/where to get jms jndi configuration values in jboss to configure in cast iron studio

Can anybody help me to configure jms jndi properties in Cast Iron studio for accessing jms queue. I'm using jboss. How/where to get jms jndi properties in jboss? Also it's asking for jndi provider details such as username, password, provider name, value, and connection factory. Where to get these details?
try this
<datasource jndi-name="java:/project name" pool-name="project namre" enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:#databaseIP port service name</connection-url>
<driver>oracle</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>username</user-name>
<password>password</password>
</security>
<statement>
<prepared-statement-cache-size>10</prepared-statement-cache-size>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>

jta=true or xa-datasource in Jboss EAP 7

I'm trying to configure SQLSERVER datasource in standalone.xml. In my project i'm using JTA and i founded configuration with and others with . What is the difference ? I'm using this:
<datasource jta="true" jndi-name="java:jboss/datasources/mydatabase" pool-name="seguDS" enabled="true" use-java-context="true">
<connection-url>jdbc:jtds:sqlserver://192.168.40.16/mydatabase;instance=clust02</connection-url>
<driver>jtds-1.3.1.jar</driver>
<new-connection-sql>select 1</new-connection-sql>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
</pool>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
</validation>
<timeout>
<set-tx-query-timeout>true</set-tx-query-timeout>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>
</timeout>
<statement>
<track-statements>false</track-statements>
</statement>
</datasource>
This works for me but i'm afraid if it correct or i should change to XA-DATASOURCE.
When you create a local-tx datasource in JBoss EAP 6.x or JBoss EAP 7, it defaults "jta" attribute to "true". This would help the local-tx resource to enlist in a global transaction. The "jta" attribute enables JTA integration for non-xa datasources only (https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.1/html-single/Administration_and_Configuration_Guide/index.html#Datasource_Parameters1).
If your application uses global transactions, i.e. it needs a transaction manager to coordinate a distributed transaction across multiple resource managers, then you need XA Datasource.

Orbeon 4.8 Postgres Problems

I cant seem to get orbeon working with postgres.
In WEB-INF/jboss-web.xml I have
<resource-ref>
<res-ref-name>OrbeonDS</res-ref-name>
<jndi-name>java:/comp/env/jdbc/postgresql</jndi-name>
</resource-ref>
Then in WEB-INF/web.xml I have
...
<resource-ref>
<description>DataSource</description>
<res-ref-name>OrbeonDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
My standalone.xml file for jboss contains
<datasource jta="false" jndi-name="java:/comp/env/jdbc/postgresql" pool-name="postgresql" enabled="true" use-java-context="false" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/Orbeon</connection-url>
<driver>postgres</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>myuser</user-name>
<password>mypassword</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
On startup the connection is bound and I have a working connection to the database. Orbeon also starts up ok and I am presented with the main screen. When I click on form runner to view my forms I get the database error popup.
In my log file, the error that appears is
error caught {controller: "oxf:/apps/fr/page-flow.xml", method: "GET", path: "/fr/service/postgresql/form"}
An error has occured
env/jdbc/mysql -- service jboss.naming.context.java.module.orbeon.orbeon.env.jdbc.postgresql
My properties-local.xml also contains the lines
<property as="xs:string" name="oxf.fr.persistence.provider.*.*.*" value="postgresql"/>
<property as="xs:string" name="oxf.fr.persistence.postgresql.datasource" value="postgresql"/>
Any ideas on what I can do to resolve this?
Thanks
I've already used a relational database persistence layer as well, but in tomcat not in Jboss.
Have you installed the JDBC driver as a module?
Follow the instruction from the following link, but using postgresql driver instead of mysql driver. http://wiki.orbeon.com/forms/doc/developer-guide/admin/installing#TOC-Setup-a-JDBC-datasource .
Also, the property oxf.fr.persistence.postgresql.datasource matches the resource name (jdbc/*) that you setup in server.xml. So, if the resource name is for example 'jdbc/postgresql', then oxf.fr.persistence.postgresql.datasource has to be 'postgresql'.