0 Replies Latest reply on Mar 31, 2015 4:30 PM by Anas Alsobeh

    Unable to lookup for DataResource and XADataResource in EAP 6.3.0

    Anas Alsobeh Newbie

      I cannot create data resources and XAdataResouces or bind it to JNDI

       

       

      In addition I got this error

      |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

      datasources/ExampleDS -- service jboss.naming.context.java.jboss.exported.datasources.ExampleDS

        at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:103)

        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)

        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:174)

        at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)

        at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

        at java.lang.Thread.run(Unknown Source)

      ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

      this is a sandalone.xml

      <subsystem xmlns="urn:jboss:domain:datasources:1.2">

                  <datasources>

                      <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">

                          <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>

                          <driver>h2</driver>

                          <security>

                              <user-name>sa</user-name>

                              <password>sa</password>

                          </security>

                      </datasource>

                      <datasource jndi-name="java:/jboss/TradisCustomerJNDI" pool-name="TradisOnlineJNDI" enabled="true" use-java-context="true">

                          <connection-url>jdbc:jtds:sqlserver://129.123.7.41:1433/customer</connection-url>

                          <driver>sqlserver</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>anas</user-name>

                              <password>tedi</password>

                          </security>

                      </datasource>

                      <datasource jndi-name="java:/jboss/TradisTestJNDI" pool-name="TradisTestJNDI" enabled="true" use-java-context="true">

                          <connection-url>jdbc:jtds:sqlserver://129.123.7.41:1433/test</connection-url>

                          <driver>sqlserver.jdbc</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>anas</user-name>

                              <password>tedi</password>

                          </security>

                      </datasource>

                      <datasource jndi-name="java:jboss/datasources/MSSqlDS" pool-name="MSSqlDS" enabled="true" use-java-context="true">

                          <connection-url>jdbc:jtds:sqlserver://localhost:1433/test</connection-url>

                          <driver>sqlserver</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>

                              <use-strict-min>false</use-strict-min>

                              <flush-strategy>FailingConnectionOnly</flush-strategy>

                          </pool>

                          <security>

                              <user-name>anas</user-name>

                              <password>tedi</password>

                          </security>

                      </datasource>

        <xa-datasource jndi-name="java:/MSSQLXADS" pool-name="MSSQLXADS">

        <driver>sqlserverXA</driver>

        <xa-datasource-property name="ServerName">localhost</xa-datasource-property>

        <xa-datasource-property name="DatabaseName">test</xa-datasource-property>

        <xa-datasource-property name="SelectMethod">cursor</xa-datasource-property>

        <security>

         <user-name>anas</user-name>

         <password>tedi</password>

        </security>

        <xa-pool>

         <is-same-rm-override>false</is-same-rm-override>

        </xa-pool>

        <validation>

         <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"></valid-connection-checker>

        </validation>

        </xa-datasource>

        <xa-datasource jndi-name="java:jboss/datasources/ExampleXADS" pool-name="ExampleXADS">

        <driver>h2</driver>

        <xa-datasource-property name="URL">jdbc:h2:mem:test</xa-datasource-property>

        <xa-pool>

        <min-pool-size>10</min-pool-size>

        <max-pool-size>20</max-pool-size>

        <prefill>true</prefill>

        </xa-pool>

        <security>

        <user-name>sa</user-name>

        <password>sa</password>

        </security>

        </xa-datasource>

                      <drivers>

                          <driver name="h2" module="com.h2database.h2">

                              <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>

                          </driver>

                          <driver name="sqlserverXA" module="com.microsoft">

        <xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>

        </driver>

                          <driver name="sqlserver" module="net.sourceforge.jtds">

                              <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>

                          </driver>

                      </drivers>

                  </datasources>

              </subsystem>

       

       

       

       

      This is a code

      private static Properties createContext() {
      Properties properties = new Properties();

       

       

              try

              {

             //if (initialContext == null)

                  {

            
      Class.forName("org.h2.jdbcx.JdbcDataSource");
             
      properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                  properties.put(Context.PROVIDER_URL,"remote://127.0.0.1:4447");
                  properties.put(Context.SECURITY_PRINCIPAL, "anasManagement");
                  properties.put(Context.SECURITY_CREDENTIALS, ".....");
                  properties.put("jboss.naming.client.ejb.context", true);
                  // create a context passing these properties
                  initialContext = new InitialContext(properties);
                  DataSource datasource = (DataSource) initialContext.lookup("java:/datasources/ExampleDS");
                  Connection con =  datasource.getConnection();

                  initialContext.bind("jdbc/DB", datasource);

      ..

      ...

      ...

              jdbcPropertyManager.getJDBCEnvironmentBean().setJndiProperties(jndiProps);

       

       

      ....

      ...

       

      / Register the driver to use

                  DriverManager.registerDriver(new TransactionalDriver());

       

                  dbProperties = new Properties();

                  dbProperties.put(TransactionalDriver.userName, BankClient.user);

                  dbProperties.put(TransactionalDriver.password, BankClient.password);

                  dbProperties.setProperty(TransactionalDriver.dynamicClass,

                          "com.arjuna.ats.internal.jdbc.drivers.PropertyFileDynamicClass");

       

                  arjunaJDBC2Driver = new TransactionalDriver();

                              create_table();

      ....

      ...

      ..

      private void create_table()

          {

              try

              {

                  Connection connection = arjunaJDBC2Driver.connect("jdbc:arjuna:jdbc/DB", dbProperties); //jdbc:arjuna:jboss/datasources/ExampleDS

       

                  Statement stmt = connection.createStatement();  // non-tx statement

                  if (BankClient.clean)

                  {

                      System.out.println("\nDrop the table ");

                      stmt.executeUpdate("DROP TABLE accounts");

                  }

       

                  if (BankClient.clean || BankClient.create)

                  {

                      stmt.executeUpdate("CREATE TABLE accounts (name VARCHAR(10) NOT NULL UNIQUE, value REAL)");

                      

                      if (BankClient.clean)

                       BankClient.clean = false;

                      

                      if (BankClient.create)

                       BankClient.create = false;

                  }

       

                  stmt.close();

                  connection.close();

              }

              catch (SQLException e)

              {

                  e.printStackTrace();

                  System.exit(0);

              }

          }