Class cast exception in context.lookup for datasource.
sishantkumar Jan 14, 2011 7:44 AMHi,
I am trying to look up the JNDI datasource on remote JBoss. My current client is also running on jBoss....
Here is the client piece of code wher i get the error :
private static DataSource getJndiDataSource(String jndiUrl, String dsName){
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", jndiUrl);
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
DataSource dataSource=null;
try {
System.out.println("inside getJndiDataSource try block");
Context ctx = new InitialContext(props);
dataSource = (DataSource)ctx.lookup(dsName);
System.out.println("inside getJndiDataSource after lookup" + dataSource.toString());
} catch (NamingException e) {
StringBuffer msg= new StringBuffer(256);
msg.append(MessageController.getStackTrace(e));
msg.append("\n\nConfig DB Connection is retrieved using JNDI URI "+jndiUrl+" and JNDI DataSource name is "+dsName);
MessageController.log(FQCN, 1234, msg.toString(),
MessageController.MEDIUM);
}
return dataSource;
}
Infact when i try to print the class name from ctx.lookup( ) i am geeting the $Proxy179 as the class name.
But whilelooking for the datasource (dataSource = (DataSource)ctx.lookup(dsName);) . I get the below error:
18:08:36,320 ERROR [STDERR] java.lang.ClassCastException: $Proxy179 cannot be cast to javax.sql.DataSource
18:08:36,320 ERROR [STDERR] at com.yodlee.internal.config.db.ConfigKeysCache.getJndiDataSource(ConfigKeysCache.java:709)
I have tried adding different jars to my JBOSS lib directory like jbossall-client.jar, jnp-client.jar etc...
If i use a stand alone client to look up the data source, it works fine if i add jbossall-client.jar and others.
Kindly help me ...i have been stuck with this issue for last 4 days :-( ...