Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[equinox-dev] RE: JNDI and OSGI

Hi Simon,

No, I don't mind. I just did what you suggested

               Thread current = Thread.currentThread();
		ClassLoader old = current.getContextClassLoader();
		try {
			current.setContextClassLoader(BridgeServlet.class.getClassLoader());
			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);
		} 

and it works. It doesn't if you don't do the trick with the classloaders.
Now, we have another problem, or I guess we have because I haven't got to
test it. We are using Hibernate and probably hibernate will have the same
problems we have to find a DataSource. So, we will have to use AOP, or some
other trickery, to make it find the DataSource (I'm just guessing).   I'm
new to OSGi and I'm struggling  to adapt a Wicket based WEB development
framework (we are creating) to work in an OSGi environment...
    
Best regards,

Ernesto


Simon Kaegi wrote:
> 
> Hi Ernesto,
> 
> If you wouldn't mind could you describe a bit about what you did?
> Thanks.
> -Simon 
> 
>> -----Original Message-----
>> From: equinox-dev-bounces@xxxxxxxxxxx 
>> [mailto:equinox-dev-bounces@xxxxxxxxxxx] On Behalf Of Ernesto 
>> Reinaldo Barreiro
>> Sent: Tuesday, January 30, 2007 3:18 AM
>> To: Equinox development mailing list
>> Subject: Re: [equinox-dev] JNDI and OSGI
>> 
>> Dear all,
>> 
>> Thanks for your answers.  Following some of your suggestions ("buddy
>> classloading") I got it working. I agree that using this kind 
>> of tricks is not clean but what other options do I have? 
>> Unfortunately, we are forced  to use "real" application 
>> servers, so we cannot go pure  OSGi and we have to use the 
>> BridgeServlet approach.
>> 
>> Best regards,
>> 
>> Ernesto
>> 
>> 
>> Pascal Rapicault wrote:
>> >
>> > I'm pretty ignorant of JNDI and stuffs, but simply hearing the word 
>> > "context class loader" immediatly makes me think about "buddy 
>> > classloading".
>> > Have you explored that path?
>> > I know it is not "osgi" ratified (at least yet).
>> >
>> > PaScaL
>> >
>> >
>> >
>> > *"Simon Kaegi" <simon.kaegi@xxxxxxxxx>* Sent by: 
>> > equinox-dev-bounces@xxxxxxxxxxx
>> >
>> > 01/29/2007 12:51 PM
>> > Please respond to
>> > Equinox development mailing list <equinox-dev@xxxxxxxxxxx>
>> >
>> >
>> > 	
>> > To
>> > 	"Equinox development mailing list" <equinox-dev@xxxxxxxxxxx> cc
>> > 	
>> > Subject
>> > 	Re: [equinox-dev] JNDI and OSGI
>> >
>> >
>> >
>> > 	
>> >
>> >
>> >
>> >
>> >
>> > To add to Neil's comment....
>> >
>> > The newsgroup would probably be better for this.
>> >
>> > JNDI interaction is tough as (at least in the implementations I've 
>> > looked
>> > at) it tends to depend on specific instances of the thread context 
>> > class loader.
>> > I'm guessing JBoss is going to be pretty standard in this regard in 
>> > which case it's NamingManager might be looking for your 
>> webapps class loader.
>> >
>> > This is not pretty and I'd be interested in seeing if we 
>> can come up 
>> > with a general solution to the problem however I can suggest an 
>> > approach if you're desperate. Before creating your 
>> InitialContext and 
>> > whenever making lookup calls set (and then reset) your 
>> thread context 
>> > class loader to the webapps.
>> > You can get the webapp classloader in a variety of ways however the 
>> > easiest might be to import 
>> org.eclipse.equinox.servletbridge and then 
>> > do something like BridgeServlet.class.getClassLoader().
>> >
>> > HTH
>> > -Simon
>> >
>> >
>> > ----- Original Message -----
>> > From: "Neil Bartlett" <njbartlett@xxxxxxxxx>
>> > To: "Equinox development mailing list" <equinox-dev@xxxxxxxxxxx>
>> > Sent: Monday, January 29, 2007 12:33 PM
>> > Subject: Re: [equinox-dev] JNDI and OSGI
>> >
>> >
>> > > Hi Ernesto,
>> > >
>> > > I'm not 100% this is suitable for this list, but then I 
>> don't know 
>> > > where else it should be asked so I'll have a go at 
>> answering anyway.
>> > >
>> > > It sounds like your JNDI InitialContext is trying to make 
>> a remote 
>> > > connection to an external JNDI server via the network. Presumably 
>> > > since your code is running inside JBoss, you actually want to use 
>> > > the JBoss internal JNDI context. Ensure that there are no 
>> > > jndi.properties files anywhere on the classpath. Some vendors 
>> > > "helpfully" include a jndi.properties file in the JARs that they 
>> > > ship, just to make life difficult.
>> > >
>> > > Also ensure that you setup the JNDI data source as an environment 
>> > > reference in the web.xml, and in the jboss_web.xml, and 
>> then use the 
>> > > "java:comp/env" prefix for your JNDI lookup...
>> > >
>> > > Alternatively, you could stop jumping through all these 
>> ridiculous 
>> > > hoops just to use a legacy technology like JNDI, and try 
>> going with 
>> > > an
>> > all-OSGi
>> > > architecture :-)
>> > >
>> > > Regards,
>> > > Neil
>> > >
>> > >
>> > >> Hi,
>> > >>
>> > >> I have a question regarding using JNDI (e.g. to look-up  
>> > >> DataSources) and running equinox via a the servletbridge. I hope 
>> > >> this is the right place to post it (if not my apologies, 
>> and please 
>> > >> tell me where
>> > should I
>> > >> ask).
>> > >>
>> > >> My question is simple. Is it possible to directly access JNDI 
>> > >> resource from a bundle. I'm trying to access a 
>> DataSource defined 
>> > >> in JBoss and I get  a 
>> javax.naming.CommunicationException (with a 
>> > >> nested timeout
>> > >> exception) .
>> > >>
>> > >> Best regards,
>> > >>
>> > >> Ernesto
>> > >> _______________________________________________
>> > >> equinox-dev mailing list
>> > >> equinox-dev@xxxxxxxxxxx
>> > >> https://dev.eclipse.org/mailman/listinfo/equinox-dev
>> > >>
>> > >
>> > >
>> > > _______________________________________________
>> > > equinox-dev mailing list
>> > > equinox-dev@xxxxxxxxxxx
>> > > https://dev.eclipse.org/mailman/listinfo/equinox-dev
>> >
>> > _______________________________________________
>> > equinox-dev mailing list
>> > equinox-dev@xxxxxxxxxxx
>> > https://dev.eclipse.org/mailman/listinfo/equinox-dev
>> >
>> > 
>> ----------------------------------------------------------------------
>> > --
>> >
>> > _______________________________________________
>> > equinox-dev mailing list
>> > equinox-dev@xxxxxxxxxxx
>> > https://dev.eclipse.org/mailman/listinfo/equinox-dev
>> >   
>> 
>> _______________________________________________
>> equinox-dev mailing list
>> equinox-dev@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/equinox-dev
> 
> _______________________________________________
> equinox-dev mailing list
> equinox-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/equinox-dev
> 
> 

-- 
View this message in context: http://www.nabble.com/JNDI-and-OSGI-tf3137001.html#a8717763
Sent from the Equinox - Dev mailing list archive at Nabble.com.



Back to the top