xa-datasource is not registered correctly
gytis Mar 14, 2013 11:16 AMHello,
I'm writing a quickstart to show integration of JBoss Transactions, IronJacamar and Tomcat. However, I am a little bit stuck with Postgres xa-datasource. It seams that it is not getting registered correctly. I can successfully access database with local datasource, but I get the following exception when using xa-datasource (exception stack trace available here: http://pastebin.com/vmjHLHX6):
{code}
...
Caused by: org.postgresql.util.PSQLException: FATAL: database "IronJacamarTryout;User=postgres;ServerName=127.0.0.1;PortNumber" does not exist
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:471)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:112)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:32)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at org.postgresql.ds.common.BaseDataSource.getConnection(BaseDataSource.java:92)
at org.postgresql.xa.jdbc3.AbstractJdbc3XADataSource.getXAConnection(AbstractJdbc3XADataSource.java:57)
at org.jboss.jca.adapters.jdbc.xa.XAManagedConnectionFactory.getXAManagedConnection(XAManagedConnectionFactory.java:430)
... 43 more
{code}
Datasource registration code looks as following (available on github: https://github.com/Gytis/quickstart/blob/master-JBTM-1479/ArjunaJTS/jca-and-tomcat/src/test/java/org/jboss/narayana/quickstart/jca/common/AbstractTest.java):
{code}
// ...
Embedded embedded = EmbeddedFactory.create();
embedded.startup();
embedded.deploy(getURL(JDBC_RAR_FILE_NAME));
embedded.deploy(getURL(POSTGRES_DS_FILE_NAME));
Context context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("java:/PostgresDS");
Connection connection = dataSource.getConnection("postgres", "postgres");
// ...
{code}
postgres-ds.xml (the one which works) looks as following (available on github: https://github.com/Gytis/quickstart/blob/master-JBTM-1479/ArjunaJTS/jca-and-tomcat/src/test/resources/postgres-ds.xml):
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<datasource jndi-name="PostgresDS" pool-name="PostgresDS">
<connection-url>jdbc:postgresql://127.0.0.1:5432/IronJacamarTryout</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
<validation>
<valid-connection-checker
class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker>
<exception-sorter
class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"></exception-sorter>
</validation>
</datasource>
</datasources>
{code}
And finally postgres-xa-ds.xml (the one which does not work) looks as following (available on github: https://github.com/Gytis/quickstart/blob/master-JBTM-1479/ArjunaJTS/jca-and-tomcat/src/test/resources/postgres-xa-ds.xml)
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<xa-datasource jndi-name="PostgresDS" pool-name="PostgresDS">
<xa-datasource-property name="ServerName">127.0.0.1</xa-datasource-property>
<xa-datasource-property name="PortNumber">5432</xa-datasource-property>
<xa-datasource-property name="DatabaseName">IronJacamarTryout</xa-datasource-property>
<xa-datasource-property name="User">postgres</xa-datasource-property>
<xa-datasource-property name="Password">postgres</xa-datasource-property>
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
<validation>
<valid-connection-checker
class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker>
<exception-sorter
class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"></exception-sorter>
</validation>
</xa-datasource>
</datasources>
{code}
PostgreSQL version used: 9.1
IronJacamar version used: 1.0.15.Final
JDK version used: 1.7
pom.xml: https://github.com/Gytis/quickstart/blob/master-JBTM-1479/ArjunaJTS/jca-and-tomcat/pom.xml
p.s.
username and password does not have to be passed to dataSource.getConnection(), if local datasource is used. However, such invocation will raise an error that password is missing, if xa-datasource is used. (see: datasource registration code).