Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » JNDI and Equinox
JNDI and Equinox [message #91777] Mon, 09 July 2007 09:16 Go to next message
Eclipse UserFriend
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?
Re: JNDI and Equinox [message #91975 is a reply to message #91777] Wed, 11 July 2007 17:34 Go to previous message
Simon Kaegi is currently offline Simon KaegiFriend
Messages: 381
Registered: July 2009
Senior Member
Hi Marcel,

That looks like it should work.
If you explicitly set the TCCL on an incoming request thread then your JNDI
request should just be a regular webapp JNDI call.

Some suggestions....
Are you doing the JNDI lookup on an incoming request thread?
On some appservers there's additional thread local information required in
order to access the directory.

Could you try accessing another value in you comp/env? Preferably something
really simple like a String.
I'm wonder if perhaps there's a factory class visibility problem when
creating an instance of the DataSource (?).

-Simon

"Marcel Ryser" <marcel.ryser@gmx.ch> wrote in message
news:87cac9876e1438a9ff32f0faa404dcc1$1@www.eclipse.org...
> 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?
>
Previous Topic:Best practices for dependency management
Next Topic:Location of OSGi classes
Goto Forum:
  


Current Time: Tue May 07 05:09:13 GMT 2024

Powered by FUDForum. Page generated in 5.04853 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top