Cannot lookup DataSource from JBoss ...

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:eek:racle:thin:mad: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:eek: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)
 
S

Superdude

If this is a remote client, it will not work, J2EE servers are not
intended for direct connection to a database. Let me know. : )

Frank said:
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:eek:racle:thin:mad: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:eek: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)
 
F

Frank Ratzlow

Superdude said:
If this is a remote client, it will not work, J2EE servers are not
intended for direct connection to a database. Let me know. : )


nope, it's all running in the same VM.

Frank
(e-mail address removed)
 
F

Frank Ratzlow

.... would still be interested in getting a comment on this issue from anyone ...

Frank
 
S

Sudsy

Frank said:
... would still be interested in getting a comment on this issue from anyone ...

Frank

Original query (post) has expired. If you don't find joy here then
I guess you just have to bite the bullet and pay for support from
jbossgroup.com. Sucks, eh? Ya gets what ya pay for...
 
J

John C. Bollinger

Frank said:
... would still be interested in getting a comment on this issue from anyone ...

Frank

And in a previous message:
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>
-----------------------------

and [from the "ServiceLocator" class]
/**
* 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;
}
}
and

-----------------------------
public class Test {

public static void testGetDatasource() {
ServiceLocator locator = new ServiceLocator();
DataSource dataSource = locator.getDataSource("OracleDS"); // here
it fails!! :-(
}
}
-----------------------------



Aren't you looking up the wrong name? It appears that you have assigned
the name "java:/OracleDS", but are looking up just "OracleDS".


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top