JNDI and Equinox [message #91777] |
Mon, 09 July 2007 09:16 |
Eclipse User |
|
|
|
Originally posted by: marcel.ryser.gmx.ch
We're migrating our tomcat web-application to eclipse equinox bundles and
the ServletBridge.
In one of our bundles we use jndi resources defined in the per-context
configuration located at
$TOMCAT_HOME/conf/Catalina/localhost/myapplication.xml. All resources are
DataSources (databases).
This is the code we get our datasources by the InitialContext:
String lookup = "java:/comp/env";
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup(lookup);
DataSource ds = (DataSource) envContext.lookup(profile);
But it seems that there aren't any resources defined when it tries to
lookup. I think this is a
classloader problem. The InitialContext is created by the bundle
classloader and not the tomcat-classloader.
I've surfed around to get some ideas how to fix it. One of those said to
set the classloader like this:
Thread current = Thread.currentThread();
ClassLoader old = current.getContextClassLoader();
try {
current.setContextClassLoader(BridgeServlet.class.getClassLo ader());
InitialContext context = new InitialContext();
DataSource jtaDatasourceInst =
(DataSource)context.lookup("java:/jdbc/WAFPATTERNSDATA");
if(jtaDatasourceInst ==null)
System.out.println("Could not find DataSource");
} catch (Throwable e) {
System.out.println("Could not find DataSource");
} finally {
current.setContextClassLoader(old);
}
But it doesn't work for me. How i get this to work?
|
|
|
|
Powered by
FUDForum. Page generated in 5.04853 seconds