-
1. Re: Any known DataSource proxies impl for JBoss
starksm64 Jan 19, 2005 3:01 AM (in response to stevenpeh)4.0.x has a native proxy and all DataSources are available remotely. You need to specify a use-java-context=false to avoid binding the data source under the java: context which is a vm local construct in order to be able to lookup the DataSource from a remote client. The following template binds a DataSource under jdbc/DB1 and is accessible remotely:
<local-tx-datasource> <jndi-name>jdbc/DB1</jndi-name> <use-java-context>false</use-java-context> <connection-url>jdbc:pointbase:server://@pointbase.server@:@pointbase.port@/@pointbase.dbName@,new</connection-url> <driver-class>@pointbase.driver@</driver-class> <user-name>@pointbase.user@</user-name> <password>@pointbase.passwd@</password> </local-tx-datasource>
-
2. Re: Any known DataSource proxies impl for JBoss
stevenpeh Jan 19, 2005 3:03 AM (in response to stevenpeh)Thanks, will give it a try
-
3. Re: Any known DataSource proxies impl for JBoss
jitesh_popat Feb 4, 2005 10:36 AM (in response to stevenpeh)Hi Scott,
Thanks a lot for your reply.
Agreed, I was able to bind the datasource to global JNDI. But while trying to get it from a remote client, I directly do not get back "javax.sql.DataSource" instance, instead I get "javax.naming.Reference" object. Why is this? In case of weblogic I can directly get a DataSource remotely.
Further, after spending lot of effort, I somehow got the DataSourec in a contrived way using the following code (Honestly speaking, this is a cheap copy of org.jboss.resource.adapter.jdbc.remote.DataSourceFactory):
Object obj = context.lookup("jdbc/OracleDS");
javax.naming.Reference ref = (javax.naming.Reference)obj;
BinaryRefAddr proxyAddr = (BinaryRefAddr)ref.get("ProxyData");
byte[] proxyBytes = (byte[])proxyAddr.getContent();
ByteArrayInputStream bi = new ByteArrayInputStream(proxyBytes);
ObjectInputStream ois = new ObjectInputStream(bi);
Object instance = ois.readObject();
if (instance instanceof javax.sql.DataSource){
// System.out.println("I am happy");
ds = (javax.sql.DataSource)instance;
}
However, now when I try to execute a JDBC statement as follows, I get an "java.lang.reflect.UndeclaredThrowableException":
Connection con = ds.getConnection();
Statement st = con.createStatement(); // exception is thrown in this line.
Please help.
Regards,
Jitesh Kumar Popat -
4. Re: Any known DataSource proxies impl for JBoss
starksm64 Feb 4, 2005 5:21 PM (in response to stevenpeh)Any access to the jboss jndi tree requires that the jboss object factories are available in the jndi context configuration as many things in jndi are references to information on how to create the indicated object. This is true of all jndi providers.
-
5. Re: Any known DataSource proxies impl for JBoss
stevenpeh Feb 6, 2005 8:14 PM (in response to stevenpeh)"jitesh_popat" wrote:
Hi Scott,
Thanks a lot for your reply.
Agreed, I was able to bind the datasource to global JNDI. But while trying to get it from a remote client, I directly do not get back "javax.sql.DataSource" instance, instead I get "javax.naming.Reference" object. Why is this? In case of weblogic I can directly get a DataSource remotely.
Further, after spending lot of effort, I somehow got the DataSourec in a contrived way using the following code (Honestly speaking, this is a cheap copy of org.jboss.resource.adapter.jdbc.remote.DataSourceFactory):
Object obj = context.lookup("jdbc/OracleDS");
javax.naming.Reference ref = (javax.naming.Reference)obj;
BinaryRefAddr proxyAddr = (BinaryRefAddr)ref.get("ProxyData");
byte[] proxyBytes = (byte[])proxyAddr.getContent();
ByteArrayInputStream bi = new ByteArrayInputStream(proxyBytes);
ObjectInputStream ois = new ObjectInputStream(bi);
Object instance = ois.readObject();
if (instance instanceof javax.sql.DataSource){
// System.out.println("I am happy");
ds = (javax.sql.DataSource)instance;
}
However, now when I try to execute a JDBC statement as follows, I get an "java.lang.reflect.UndeclaredThrowableException":
Connection con = ds.getConnection();
Statement st = con.createStatement(); // exception is thrown in this line.
Please help.
Regards,
Jitesh Kumar Popat
Hi jitesh,
I was able to get the datasource fairly straightforward as scott pointed out in jboss 4.0. Here's my test code snippet (Oracle 9i db),
Object raw = initialcontext.lookup("ds/myDataSource");
DataSource ds= (DataSource) PortableRemoteObject.narrow(raw,DataSource.class);
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery("select * from test_table");
I doubt this works on anything less than jboss 4.0, if i'm wrong about this someone please correct me. Hope this helps.
Cheers,
Steven Peh -
6. Re: Any known DataSource proxies impl for JBoss
jitesh_popat Feb 7, 2005 1:43 AM (in response to stevenpeh)Thanks Scott, it worked. All I need to do was put the following jar in remote client's classpath:
$jboss-root\server\default\lib\jboss-common-jdbc-wrapper.jar
The said jar contains "org.jboss.resource.adapter.jdbc.remote.DataSourceFactory".
One last thing though...following is the way I am getting the initial context on client side:
---------------
env = new Hashtable();
env.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
env.put(InitialContext.PROVIDER_URL, "jnp://localhost:1099");
env.put(InitialContext.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
try {
context = new InitialContext(env);
....... // rest of the code goes here
-----------
Is there anything else which I can put in "env" so that the jboss object factories are available in the jndi context configuration and I don't need to add the said jar in remote client classpath?