Discussion:
[jboss-user] [IronJacamar] - xa-datasource is not registered correctly
Gytis Trikleris
2013-03-14 15:16:15 UTC
Permalink
Gytis Trikleris [https://community.jboss.org/people/gytis] created the discussion

"xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/802706#802706

--------------------------------------------------------------
Hello,

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 http://pastebin.com/vmjHLHX6):

...
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




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 https://github.com/Gytis/quickstart/blob/master-JBTM-1479/ArjunaJTS/jca-and-tomcat/src/test/java/org/jboss/narayana/quickstart/jca/common/AbstractTest.java):

// ...
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");
// ...




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 https://github.com/Gytis/quickstart/blob/master-JBTM-1479/ArjunaJTS/jca-and-tomcat/src/test/resources/postgres-ds.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>



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 https://github.com/Gytis/quickstart/blob/master-JBTM-1479/ArjunaJTS/jca-and-tomcat/src/test/resources/postgres-xa-ds.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>



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 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).
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802706#802706]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Jesper Pedersen
2013-03-14 16:23:08 UTC
Permalink
Jesper Pedersen [https://community.jboss.org/people/jesper.pedersen] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/802730#802730

--------------------------------------------------------------
Try

<xa-datasource-property name="ServerName">localhost</xa-datasource-property>
<xa-datasource-property name="PortNumber">5432</xa-datasource-property>
<xa-datasource-property name="DatabaseName">postgresdb</xa-datasource-property>
<security>
   <user-name>admin</user-name>
   <password>admin</password>
</security>


instead
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802730#802730]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Gytis Trikleris
2013-03-14 16:43:45 UTC
Permalink
Gytis Trikleris [https://community.jboss.org/people/gytis] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/802734#802734

--------------------------------------------------------------
If I remove "User" and "Password" properties, I get java.net.UnknownHostException with both your and mine configurations.
However, If I put your suggested configuration and leave "User" and "Password" properties, I get the same exception as in my first post (org.postgresql.util.PSQLException: FATAL: database "postgresdb;User=admin;ServerName=localhost;PortNumber" does not exist). Same situation happens if I keep ServerName, DatabaseName, user-name, and password values as in my first post.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/802734#802734]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Gytis Trikleris
2013-03-18 17:25:07 UTC
Permalink
Gytis Trikleris [https://community.jboss.org/people/gytis] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803309#803309

--------------------------------------------------------------
I did some debugging and there seems to be a problem in the xa-datasource parsing... XAManagedConnectionFactory.setXADataSourceProperties method (see: http://tinyurl.com/d45bvlz http://tinyurl.com/d45bvlz) takes data source properties as a semicolon separated string like this:

DatabaseName=IronJacamarTryout;User=postgres;ServerName=127.0.0.1;PortNumber=5432;Password=postgres;



However, Properties.load method used in XAManagedConnectionFactory.setXADataSourceProperties requires properties to be separated by a new line character (e.g. “\n”). Therefore, above string is loaded as one property instead of five.

I've modified XAManagedConnectionFactory locally and added following line at the beginning of setXADataSourceProperties method and it solved my problem:

xaDataSourceProperties = xaDataSourceProperties.replaceAll(";", "\n");
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803309#803309]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Tom Jenkinson
2013-03-18 17:27:48 UTC
Permalink
Tom Jenkinson [https://community.jboss.org/people/tomjenkinson] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803310#803310

--------------------------------------------------------------
Should gytis create a jira (and patch) for this?

Thanks,
Tom
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803310#803310]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Jesper Pedersen
2013-03-18 17:29:19 UTC
Permalink
Jesper Pedersen [https://community.jboss.org/people/jesper.pedersen] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803311#803311

--------------------------------------------------------------
Ok, thanks for debugging this.

The \n case sounds wrong to me, so I'll need to investigate that.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803311#803311]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Gytis Trikleris
2013-03-18 17:46:59 UTC
Permalink
Gytis Trikleris [https://community.jboss.org/people/gytis] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803317#803317

--------------------------------------------------------------
Here is the quote from documentation ( http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html#load%28java.io.Reader%29 http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html#load%28java.io.Reader%29):
...
Line terminator characters can be included using \r and \n escape sequences. Any white space after the key is skipped; if the first non-white space character after the key is '=' or ':', then it is ignored and any white space characters after it are also skipped. All remaining characters on the line become part of the associated element string; if there are no remaining characters, the element is the empty string "". Once the raw character sequences constituting the key and element are identified, escape processing is performed as described above.


As an example, each of the following three lines specifies the key "Truth" and the associated element value "Beauty":
Truth = Beauty           Truth:Beauty Truth                  :Beauty
As another example, the following three lines specify a single property:

fruits                           apple, banana, pear, \                                    cantaloupe, watermelon, \                                    kiwi, mango
The key is "fruits" and the associated element is:

"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"
...
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803317#803317]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Jesper Pedersen
2013-03-19 15:53:43 UTC
Permalink
Jesper Pedersen [https://community.jboss.org/people/jesper.pedersen] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803637#803637

--------------------------------------------------------------
Fxied, thanks for the report
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803637#803637]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Gytis Trikleris
2013-03-19 16:09:44 UTC
Permalink
Gytis Trikleris [https://community.jboss.org/people/gytis] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803641#803641

--------------------------------------------------------------
When do you plan to make a release with this fix?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803641#803641]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Jesper Pedersen
2013-03-19 16:11:22 UTC
Permalink
Jesper Pedersen [https://community.jboss.org/people/jesper.pedersen] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803644#803644

--------------------------------------------------------------
Snapshots will be available starting tonight - release date depends on which version you are using.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803644#803644]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Gytis Trikleris
2013-03-19 16:26:20 UTC
Permalink
Gytis Trikleris [https://community.jboss.org/people/gytis] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803649#803649

--------------------------------------------------------------
Currently I use 1.0.15.Final, so I guess the one I need is 1.0.16.Final
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803649#803649]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Jesper Pedersen
2013-03-19 16:26:44 UTC
Permalink
Jesper Pedersen [https://community.jboss.org/people/jesper.pedersen] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803650#803650

--------------------------------------------------------------
Likely this week
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803650#803650]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Gytis Trikleris
2013-03-19 17:01:37 UTC
Permalink
Gytis Trikleris [https://community.jboss.org/people/gytis] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/803660#803660

--------------------------------------------------------------
Sounds great. Thanks for your help.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/803660#803660]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Jesper Pedersen
2013-03-26 12:11:15 UTC
Permalink
Jesper Pedersen [https://community.jboss.org/people/jesper.pedersen] created the discussion

"Re: xa-datasource is not registered correctly"

To view the discussion, visit: https://community.jboss.org/message/804825#804825

--------------------------------------------------------------
1.0.16.Final was released
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/804825#804825]

Start a new discussion in IronJacamar at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2098]
Loading...