You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicemix.apache.org by Guillaume Nodet <gn...@gmail.com> on 2007/04/04 11:44:25 UTC

Re: Access to JNDI Resources by java code

I don't really see why one has to specify these properties,
at least when inside ServiceMix standalone, or when using
the InitialContext retreived from the ComponentContext.
Any idea ?

On 4/4/07, Thomas TERMIN <tt...@blue-elephant-systems.com> wrote:
>
> Andrea Zoppello wrote:
> > Hi to all
> >
> > I'm asking if there's a way to access Jndi resources (defined in
> > jndi.xml ) in the java code of a component/endpoint???
>
> That should work.
>
> private String jndiInitialContextFactory =
> "org.apache.xbean.spring.jndi.SpringInitialContextFactory";
>   private String jndiProviderUrl = "classpath:jndi.xml";
>
> Hashtable env = new Hashtable();
>         env.put(Context.INITIAL_CONTEXT_FACTORY,
> this.jndiInitialContextFactory);
>         env.put(Context.PROVIDER_URL, jndiProviderUrl);
>
> Context ctx = new InitialContext(env);
>
> Cheers,
> Thomas
> --
> Thomas Termin
> _______________________________
> blue elephant systems GmbH
> Wollgrasweg 49
> D-70599 Stuttgart
>
> Tel    :  (+49) 0711 - 45 10 17 676
> Fax    :  (+49) 0711 - 45 10 17 573
> WWW    :  http://www.blue-elephant-systems.com
> Email  :  Thomas.Termin@blue-elephant-systems.com
>
> blue elephant systems GmbH
> Firmensitz      : Wollgrasweg 49, D-70599 Stuttgart
> Registergericht : Amtsgericht Stuttgart, HRB 24106
> Geschäftsführer : Holger Dietrich, Thomas Gentsch, Joachim Hoernle
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Architect, LogicBlaze (http://www.logicblaze.com/)
Blog: http://gnodet.blogspot.com/

Re: Access to JNDI Resources by java code

Posted by Andrea Zoppello <zo...@tiscali.it>.
Ok Guillaume,

The following code is working:

EndpointComponentContext aContext = (EndpointComponentContext)getContext();
InitialContext jndiContext = aContext.getNamingContext();
DataSource ds = (DataSource)jndiContext.lookup("java:comp/env/jdbc/metadb");

My problems were due to the fact that i had an error with db connection but
there i was not able to detect this so the datasource were not bound and 
there was
the NameNotFoundException.

Andrea

Guillaume Nodet ha scritto:
> I don't really see why one has to specify these properties,
> at least when inside ServiceMix standalone, or when using
> the InitialContext retreived from the ComponentContext.
> Any idea ?
>
> On 4/4/07, Thomas TERMIN <tt...@blue-elephant-systems.com> wrote:
>>
>> Andrea Zoppello wrote:
>> > Hi to all
>> >
>> > I'm asking if there's a way to access Jndi resources (defined in
>> > jndi.xml ) in the java code of a component/endpoint???
>>
>> That should work.
>>
>> private String jndiInitialContextFactory =
>> "org.apache.xbean.spring.jndi.SpringInitialContextFactory";
>>   private String jndiProviderUrl = "classpath:jndi.xml";
>>
>> Hashtable env = new Hashtable();
>>         env.put(Context.INITIAL_CONTEXT_FACTORY,
>> this.jndiInitialContextFactory);
>>         env.put(Context.PROVIDER_URL, jndiProviderUrl);
>>
>> Context ctx = new InitialContext(env);
>>
>> Cheers,
>> Thomas
>> -- 
>> Thomas Termin
>> _______________________________
>> blue elephant systems GmbH
>> Wollgrasweg 49
>> D-70599 Stuttgart
>>
>> Tel    :  (+49) 0711 - 45 10 17 676
>> Fax    :  (+49) 0711 - 45 10 17 573
>> WWW    :  http://www.blue-elephant-systems.com
>> Email  :  Thomas.Termin@blue-elephant-systems.com
>>
>> blue elephant systems GmbH
>> Firmensitz      : Wollgrasweg 49, D-70599 Stuttgart
>> Registergericht : Amtsgericht Stuttgart, HRB 24106
>> Geschäftsführer : Holger Dietrich, Thomas Gentsch, Joachim Hoernle
>>
>>
>
>


Re: Access to JNDI Resources by java code

Posted by Thomas TERMIN <tt...@blue-elephant-systems.com>.
I've corrected this. :-)

Thomas TERMIN wrote:
> What you mean is that:
> 
> getContext().getNamingContext()
> 
> should work and is also the better way if it is inside of a component.
> 
> I read the mail to fast I guess.
> 
> What also works inside the same vm is just: new InitialContext()
> 
> Cheers,
> Thomas
> 
> Guillaume Nodet wrote:
>> I don't really see why one has to specify these properties,
>> at least when inside ServiceMix standalone, or when using
>> the InitialContext retreived from the ComponentContext.
>> Any idea ?
>>
>> On 4/4/07, Thomas TERMIN <tt...@blue-elephant-systems.com> wrote:
>>> Andrea Zoppello wrote:
>>>> Hi to all
>>>>
>>>> I'm asking if there's a way to access Jndi resources (defined in
>>>> jndi.xml ) in the java code of a component/endpoint???
>>> That should work.
>>>
>>> private String jndiInitialContextFactory =
>>> "org.apache.xbean.spring.jndi.SpringInitialContextFactory";
>>>   private String jndiProviderUrl = "classpath:jndi.xml";
>>>
>>> Hashtable env = new Hashtable();
>>>         env.put(Context.INITIAL_CONTEXT_FACTORY,
>>> this.jndiInitialContextFactory);
>>>         env.put(Context.PROVIDER_URL, jndiProviderUrl);
>>>
>>> Context ctx = new InitialContext(env);
>>>
>>> Cheers,
>>> Thomas
>>> -- 
>>> Thomas Termin
>>> _______________________________
>>> blue elephant systems GmbH
>>> Wollgrasweg 49
>>> D-70599 Stuttgart
>>>
>>> Tel    :  (+49) 0711 - 45 10 17 676
>>> Fax    :  (+49) 0711 - 45 10 17 573
>>> WWW    :  http://www.blue-elephant-systems.com
>>> Email  :  Thomas.Termin@blue-elephant-systems.com
>>>
>>> blue elephant systems GmbH
>>> Firmensitz      : Wollgrasweg 49, D-70599 Stuttgart
>>> Registergericht : Amtsgericht Stuttgart, HRB 24106
>>> Geschäftsführer : Holger Dietrich, Thomas Gentsch, Joachim Hoernle
>>>
>>>
>>
> 
> 


-- 
Thomas Termin
_______________________________
blue elephant systems GmbH
Wollgrasweg 49
D-70599 Stuttgart

Tel    :  (+49) 0711 - 45 10 17 676
Fax    :  (+49) 0711 - 45 10 17 573
WWW    :  http://www.blue-elephant-systems.com
Email  :  Thomas.Termin@blue-elephant-systems.com

blue elephant systems GmbH
Firmensitz      : Wollgrasweg 49, D-70599 Stuttgart
Registergericht : Amtsgericht Stuttgart, HRB 24106
Geschäftsführer : Holger Dietrich, Thomas Gentsch, Joachim Hoernle


Re: Access to JNDI Resources by java code

Posted by Thomas TERMIN <tt...@blue-elephant-systems.com>.
What you mean is that:

getContext().getNamingContext()

should work and is also the better way if it is inside of a component.

I read the mail to fast I guess.

What also works inside the same vm is just: new InitialContext()

Cheers,
Thomas

Guillaume Nodet wrote:
> I don't really see why one has to specify these properties,
> at least when inside ServiceMix standalone, or when using
> the InitialContext retreived from the ComponentContext.
> Any idea ?
> 
> On 4/4/07, Thomas TERMIN <tt...@blue-elephant-systems.com> wrote:
>>
>> Andrea Zoppello wrote:
>> > Hi to all
>> >
>> > I'm asking if there's a way to access Jndi resources (defined in
>> > jndi.xml ) in the java code of a component/endpoint???
>>
>> That should work.
>>
>> private String jndiInitialContextFactory =
>> "org.apache.xbean.spring.jndi.SpringInitialContextFactory";
>>   private String jndiProviderUrl = "classpath:jndi.xml";
>>
>> Hashtable env = new Hashtable();
>>         env.put(Context.INITIAL_CONTEXT_FACTORY,
>> this.jndiInitialContextFactory);
>>         env.put(Context.PROVIDER_URL, jndiProviderUrl);
>>
>> Context ctx = new InitialContext(env);
>>
>> Cheers,
>> Thomas
>> -- 
>> Thomas Termin
>> _______________________________
>> blue elephant systems GmbH
>> Wollgrasweg 49
>> D-70599 Stuttgart
>>
>> Tel    :  (+49) 0711 - 45 10 17 676
>> Fax    :  (+49) 0711 - 45 10 17 573
>> WWW    :  http://www.blue-elephant-systems.com
>> Email  :  Thomas.Termin@blue-elephant-systems.com
>>
>> blue elephant systems GmbH
>> Firmensitz      : Wollgrasweg 49, D-70599 Stuttgart
>> Registergericht : Amtsgericht Stuttgart, HRB 24106
>> Geschäftsführer : Holger Dietrich, Thomas Gentsch, Joachim Hoernle
>>
>>
> 
> 


-- 
Thomas Termin
_______________________________
blue elephant systems GmbH
Wollgrasweg 49
D-70599 Stuttgart

Tel    :  (+49) 0711 - 45 10 17 676
Fax    :  (+49) 0711 - 45 10 17 573
WWW    :  http://www.blue-elephant-systems.com
Email  :  Thomas.Termin@blue-elephant-systems.com

blue elephant systems GmbH
Firmensitz      : Wollgrasweg 49, D-70599 Stuttgart
Registergericht : Amtsgericht Stuttgart, HRB 24106
Geschäftsführer : Holger Dietrich, Thomas Gentsch, Joachim Hoernle