F
Frank Ratzlow
Hi folks,
I'm working on j2ee application running on JBoss 3.2.2 (Win) and want
to lookup a datasource I configured. The datasource is mapped to an
Oracle 9.0.2 DB.
I configured the datasource within
$JBOSS/server/default/deploy/oracle-ds.xml
-----------------------------
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc
racle:thin
linuxsrv:1521:fr1</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>EKA</user-name>
<password>eka</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
</local-tx-datasource>
</datasources>
-----------------------------
To make the datasource available for the applications CMP-Beans I
configured in jbosscmp-jdbc.xml the following:
-----------------------------
<defaults>
<datasource>java:/OracleDS</datasource>
<datasource-mapping>Oracle9i</datasource-mapping>
<create-table>true</create-table>
<remove-table>false</remove-table>
<entity-command name="oracle-sequence"/>
</defaults>
-----------------------------
For the Beans everything is working fine but when I try to lookup the
datasource by means of a servicelocator I constantly receive an error.
The relevant code looks like this:
-----------------------------
public class ServiceLocator {
private InitialContext ic = null;
public ServiceLocator() {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put("java.naming.factory.url.pkgs",
"org.jboss.naming
rg.jnp.interfaces");
ic = new InitialContext(env);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
}
/**
* This method obtains the datasource itself for a caller
* @return the DataSource corresponding to the name parameter
*/
public DataSource getDataSource(String dataSourceName) throws
ServiceLocatorException {
DataSource dataSource = null;
try {
dataSource = (DataSource)ic.lookup(dataSourceName);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return dataSource;
}
}
-----------------------------
In another class that utilizes the ServiceLocator I do something like
this:
-----------------------------
public class Test {
public static void testGetDatasource() {
ServiceLocator locator = new ServiceLocator();
DataSource dataSource = locator.getDataSource("OracleDS"); // here
it fails!! :-(
}
}
-----------------------------
I also tried "java:/OracleDS", "jdbc/OracleDS" and
"java:/comp/env/jdbc/OracleDS" with no success. The example show in
the Test class throws an exception:
-----------------------------
javax.naming.NameNotFoundException: OracleDS not bound
at org.eka.web.util.ServiceLocator.getDataSource(ServiceLocator.java:260)
at org.eka.web.bean.AuthenticationBeanTest.testAuthenticate(AuthenticationBeanTest.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
-----------------------------
But nevertheless the JBoss log file states:
-----------------------------
2004-01-05 23:36:14,058 DEBUG [org.jboss.deployment.MainDeployer]
Watching new file: file:/D:/OSS/Jboss32/server/default/deploy/oracle-ds.xml
2004-01-05 23:36:14,058 DEBUG [org.jboss.deployment.MainDeployer]
create step for deployment
file:/D:/OSS/Jboss32/server/default/deploy/oracle-ds.xml
2004-01-05 23:36:14,058 DEBUG [org.jboss.deployment.SARDeployer]
Deploying SAR, create step: url
file:/D:/OSS/Jboss32/server/default/deploy/oracle-ds.xml
2004-01-05 23:36:14,058 DEBUG [org.jboss.deployment.SARDeployer]
Registering service UCL=jmx.loading:UCL=15fc672
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceCreator] About
to create bean: jboss.jca:service=LocalTxCM,name=OracleDS with code:
org.jboss.resource.connectionmanager.TxConnectionManager
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceCreator]
Created bean: jboss.jca:service=LocalTxCM,name=OracleDS
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceConfigurator]
TrackConnectionByTx set to true in
jboss.jca:service=LocalTxCM,name=OracleDS
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceConfigurator]
LocalTransactions set to true in
jboss.jca:service=LocalTxCM,name=OracleDS
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceCreator] About
to create bean: jboss.jca:service=ManagedConnectionPool,name=OracleDS
with code: org.jboss.resource.connectionmanager.JBossManagedConnectionPool
..
..
..
-----------------------------
So from this point of view everything seems to be fine but how can I
get access to this configured and recognized datasource?
I cannot see wether I made a configuration mistake or if there is
something wrong with the code (Initial context wrong?!).
I Would be very glad for any hint.
TIA
Frank
(e-mail address removed)
I'm working on j2ee application running on JBoss 3.2.2 (Win) and want
to lookup a datasource I configured. The datasource is mapped to an
Oracle 9.0.2 DB.
I configured the datasource within
$JBOSS/server/default/deploy/oracle-ds.xml
-----------------------------
<datasources>
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>EKA</user-name>
<password>eka</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
</local-tx-datasource>
</datasources>
-----------------------------
To make the datasource available for the applications CMP-Beans I
configured in jbosscmp-jdbc.xml the following:
-----------------------------
<defaults>
<datasource>java:/OracleDS</datasource>
<datasource-mapping>Oracle9i</datasource-mapping>
<create-table>true</create-table>
<remove-table>false</remove-table>
<entity-command name="oracle-sequence"/>
</defaults>
-----------------------------
For the Beans everything is working fine but when I try to lookup the
datasource by means of a servicelocator I constantly receive an error.
The relevant code looks like this:
-----------------------------
public class ServiceLocator {
private InitialContext ic = null;
public ServiceLocator() {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put("java.naming.factory.url.pkgs",
"org.jboss.naming
ic = new InitialContext(env);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
}
/**
* This method obtains the datasource itself for a caller
* @return the DataSource corresponding to the name parameter
*/
public DataSource getDataSource(String dataSourceName) throws
ServiceLocatorException {
DataSource dataSource = null;
try {
dataSource = (DataSource)ic.lookup(dataSourceName);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return dataSource;
}
}
-----------------------------
In another class that utilizes the ServiceLocator I do something like
this:
-----------------------------
public class Test {
public static void testGetDatasource() {
ServiceLocator locator = new ServiceLocator();
DataSource dataSource = locator.getDataSource("OracleDS"); // here
it fails!! :-(
}
}
-----------------------------
I also tried "java:/OracleDS", "jdbc/OracleDS" and
"java:/comp/env/jdbc/OracleDS" with no success. The example show in
the Test class throws an exception:
-----------------------------
javax.naming.NameNotFoundException: OracleDS not bound
at org.eka.web.util.ServiceLocator.getDataSource(ServiceLocator.java:260)
at org.eka.web.bean.AuthenticationBeanTest.testAuthenticate(AuthenticationBeanTest.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
-----------------------------
But nevertheless the JBoss log file states:
-----------------------------
2004-01-05 23:36:14,058 DEBUG [org.jboss.deployment.MainDeployer]
Watching new file: file:/D:/OSS/Jboss32/server/default/deploy/oracle-ds.xml
2004-01-05 23:36:14,058 DEBUG [org.jboss.deployment.MainDeployer]
create step for deployment
file:/D:/OSS/Jboss32/server/default/deploy/oracle-ds.xml
2004-01-05 23:36:14,058 DEBUG [org.jboss.deployment.SARDeployer]
Deploying SAR, create step: url
file:/D:/OSS/Jboss32/server/default/deploy/oracle-ds.xml
2004-01-05 23:36:14,058 DEBUG [org.jboss.deployment.SARDeployer]
Registering service UCL=jmx.loading:UCL=15fc672
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceCreator] About
to create bean: jboss.jca:service=LocalTxCM,name=OracleDS with code:
org.jboss.resource.connectionmanager.TxConnectionManager
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceCreator]
Created bean: jboss.jca:service=LocalTxCM,name=OracleDS
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceConfigurator]
TrackConnectionByTx set to true in
jboss.jca:service=LocalTxCM,name=OracleDS
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceConfigurator]
LocalTransactions set to true in
jboss.jca:service=LocalTxCM,name=OracleDS
2004-01-05 23:36:14,058 DEBUG [org.jboss.system.ServiceCreator] About
to create bean: jboss.jca:service=ManagedConnectionPool,name=OracleDS
with code: org.jboss.resource.connectionmanager.JBossManagedConnectionPool
..
..
..
-----------------------------
So from this point of view everything seems to be fine but how can I
get access to this configured and recognized datasource?
I cannot see wether I made a configuration mistake or if there is
something wrong with the code (Initial context wrong?!).
I Would be very glad for any hint.
TIA
Frank
(e-mail address removed)