Bind Datasource to specific jndi name

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Bind Datasource to specific jndi name

Andreas Karalus-2
hello,

i've configured a datasource like this

<Resource id="operativDS" type="DataSource"> 
    JdbcDriver  oracle.jdbc.driver.OracleDriver
    JdbcUrl      jdbc:oracle:thin:@localhost:1521:orcl
    UserName    scott
    Password    tiger
</Resource>


is it possible to bind the datasource to a specific jndi name? especially, I would like to bind the datasource to "java:/operativDS"

thx in advance,
andreas
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

dblevins
Administrator

On Sep 9, 2008, at 5:53 AM, Andreas Karalus wrote:

>
> hello,
>
> i've configured a datasource like this
>
> <Resource id="operativDS" type="DataSource">
>    JdbcDriver  oracle.jdbc.driver.OracleDriver
>    JdbcUrl      jdbc:oracle:thin:@localhost:1521:orcl
>    UserName    scott
>    Password    tiger
> </Resource>
>
>
> is it possible to bind the datasource to a specific jndi name?  
> especially, I
> would like to bind the datasource to "java:/operativDS"

Everything in the config is bound to something that closely matches  
its path in the openejb.xml file.  So for example:

<openejb>
   <Resource id="operativDS" ...>

Is bound to:

   new InitialContext().lookup("java:openejb/Resource/operativDS");

If you wanted to make it available at a different name, you could  
easily add the link yourself with some code like this after OpenEJB  
has been embedded:

   InitialContext context = new InitialContext();
   context.bind("java:operativDS", new  
javax.naming.LinkRef("java:openejb/Resource/operativDS"));

-David

Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Andreas Karalus-2
Hi David,

thank you for your hint, I tried this, but still got exception:
In the code for intialisation of openejb:

initialContext.bind("java:operativDS", new  javax.naming.LinkRef("java:openejb/Resource/operativDS"));


In the test Code:
// this is ok
DataSource operativDS = (DataSource) initialContext.lookup("java:openejb/operativDS");

// this one fails, but this is the lookup I need
DataSource operativDS = (DataSource) initialContext.lookup("java:/operativDS");


So is there a possibility to bind directly to java: and not to java:openejb? It seems to me like java:openejb is kind of hardcoded?

Regards,
Andreas


David Blevins wrote
On Sep 9, 2008, at 5:53 AM, Andreas Karalus wrote:

>
> hello,
>
> i've configured a datasource like this
>
> <Resource id="operativDS" type="DataSource">
>    JdbcDriver  oracle.jdbc.driver.OracleDriver
>    JdbcUrl      jdbc:oracle:thin:@localhost:1521:orcl
>    UserName    scott
>    Password    tiger
> </Resource>
>
>
> is it possible to bind the datasource to a specific jndi name?  
> especially, I
> would like to bind the datasource to "java:/operativDS"

Everything in the config is bound to something that closely matches  
its path in the openejb.xml file.  So for example:

<openejb>
   <Resource id="operativDS" ...>

Is bound to:

   new InitialContext().lookup("java:openejb/Resource/operativDS");

If you wanted to make it available at a different name, you could  
easily add the link yourself with some code like this after OpenEJB  
has been embedded:

   InitialContext context = new InitialContext();
   context.bind("java:operativDS", new  
javax.naming.LinkRef("java:openejb/Resource/operativDS"));

-David
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

dblevins
Administrator

On Sep 16, 2008, at 3:42 AM, Andreas Karalus wrote:

>
> Hi David,
>
> thank you for your hint, I tried this, but still got exception:
> In the code for intialisation of openejb:
>
> initialContext.bind("java:operativDS", new
> javax.naming.LinkRef("java:openejb/Resource/operativDS"));
>
>
> In the test Code:
> // this is ok
> DataSource operativDS = (DataSource)
> initialContext.lookup("java:openejb/operativDS");
>
> // this one fails, but this is the lookup I need
> DataSource operativDS = (DataSource)
> initialContext.lookup("java:/operativDS");
>
>
> So is there a possibility to bind directly to java: and not to  
> java:openejb?
> It seems to me like java:openejb is kind of hardcoded?

Right, internally we depend on things being at a known place  
(java:openejb).  We could bind things to additional places but we will  
still need to maintain the java:openejb namespace. The use of LinkRef  
should allow you to have all the extra JNDI names you need, we just  
need to figure out what might be happening.

Is it possible you can post the complete initialization stacktrace as  
long as some sample code that shows how you are constructing the  
InitialContext you are using to do the binding/lookup?

-David



Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Kalyan
Hello,
I am also having the exact same issue.
Did you find the solution for this ??

Could you please post what's the approach or how did you fix it.

thanks
Kalyan



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Jean-Louis MONTEIRO
I would need to find how to but as far as I remember you can add other
names.

I'll see if I can find how during the flight

Le jeu. 20 juin 2019 à 18:43, Kalyan <[hidden email]> a écrit :

> Hello,
> I am also having the exact same issue.
> Did you find the solution for this ??
>
> Could you please post what's the approach or how did you fix it.
>
> thanks
> Kalyan
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>
   --
    Jean-Louis Monteiro
    http://twitter.com/jlouismonteiro
    http://www.tomitribe.com
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Kalyan
I really appreciate that.

The problem i have is

I created the datasource as

 p.put("DS_DB", "new://Resource?type=javax.sql.DataSource");
        p.put("DS_DB.JdbcDriver", "oracle.jdbc.OracleDriver");
        p.put("DS_DB.JdbcUrl", "jdbc:oracle:thin:@xxxxxx:1521/rwdb");
        p.put("DS_DB.UserName", "ds_user");
        p.put("DS_DB.Password", "xxxxxxx");
        p.put("DS_DB.LogSql", "true");
        p.put("DS_DB.JtaManaged", "true");


InitialContext initialContext = new InitialContext(p);

            initialContext.bind("java:/DS_DB",new
                    javax.naming.LinkRef("java:openejb:Resource/DS_DB"));

Now i am trying to look up

initialContext.lookup("java:/DS_DB")   : javax.naming.NameNotFoundException:
Name "DS_DB" not found.

But it works when i do

initialContext.lookup("/DS_DB")
initialContext.lookup("java:openejb:Resource/DS_DB")

I am wondering, why it won't work with *java:/DS_DB*

I am using openejb-core-8.0.0-M3 . version.

thanks
Kalyan

   






--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Jean-Louis MONTEIRO
Hi,

Sorry for the delay.
I have looked at the question and there is an alias="name1,name2" attribute
you can use to define different aliases for the same resource.

It is useful when you are migrating from another app server.

That being said, the "java:" namespace in jndi is restricted per spec, so
I'm not sure you will be able to define the name you want.

Give it a try and let us know anyway.
--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com


On Fri, Jun 21, 2019 at 6:01 PM Kalyan <[hidden email]> wrote:

> I really appreciate that.
>
> The problem i have is
>
> I created the datasource as
>
>  p.put("DS_DB", "new://Resource?type=javax.sql.DataSource");
>         p.put("DS_DB.JdbcDriver", "oracle.jdbc.OracleDriver");
>         p.put("DS_DB.JdbcUrl", "jdbc:oracle:thin:@xxxxxx:1521/rwdb");
>         p.put("DS_DB.UserName", "ds_user");
>         p.put("DS_DB.Password", "xxxxxxx");
>         p.put("DS_DB.LogSql", "true");
>         p.put("DS_DB.JtaManaged", "true");
>
>
> InitialContext initialContext = new InitialContext(p);
>
>             initialContext.bind("java:/DS_DB",new
>                     javax.naming.LinkRef("java:openejb:Resource/DS_DB"));
>
> Now i am trying to look up
>
> initialContext.lookup("java:/DS_DB")   :
> javax.naming.NameNotFoundException:
> Name "DS_DB" not found.
>
> But it works when i do
>
> initialContext.lookup("/DS_DB")
> initialContext.lookup("java:openejb:Resource/DS_DB")
>
> I am wondering, why it won't work with *java:/DS_DB*
>
> I am using openejb-core-8.0.0-M3 . version.
>
> thanks
> Kalyan
>
>
>
>
>
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>
   --
    Jean-Louis Monteiro
    http://twitter.com/jlouismonteiro
    http://www.tomitribe.com
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Jean-Louis MONTEIRO
The Java EE platform specification defines the following JNDI contexts:

java:comp - The namespace is scoped to the current component (i.e. EJB)
java:module - Scoped to the current module
java:app - Scoped to the current application
java:global - Scoped to the application server

-
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com


On Mon, Jun 24, 2019 at 10:05 AM Jean-Louis Monteiro <
[hidden email]> wrote:

> Hi,
>
> Sorry for the delay.
> I have looked at the question and there is an alias="name1,name2"
> attribute you can use to define different aliases for the same resource.
>
> It is useful when you are migrating from another app server.
>
> That being said, the "java:" namespace in jndi is restricted per spec, so
> I'm not sure you will be able to define the name you want.
>
> Give it a try and let us know anyway.
> --
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
>
> On Fri, Jun 21, 2019 at 6:01 PM Kalyan <[hidden email]> wrote:
>
>> I really appreciate that.
>>
>> The problem i have is
>>
>> I created the datasource as
>>
>>  p.put("DS_DB", "new://Resource?type=javax.sql.DataSource");
>>         p.put("DS_DB.JdbcDriver", "oracle.jdbc.OracleDriver");
>>         p.put("DS_DB.JdbcUrl", "jdbc:oracle:thin:@xxxxxx:1521/rwdb");
>>         p.put("DS_DB.UserName", "ds_user");
>>         p.put("DS_DB.Password", "xxxxxxx");
>>         p.put("DS_DB.LogSql", "true");
>>         p.put("DS_DB.JtaManaged", "true");
>>
>>
>> InitialContext initialContext = new InitialContext(p);
>>
>>             initialContext.bind("java:/DS_DB",new
>>                     javax.naming.LinkRef("java:openejb:Resource/DS_DB"));
>>
>> Now i am trying to look up
>>
>> initialContext.lookup("java:/DS_DB")   :
>> javax.naming.NameNotFoundException:
>> Name "DS_DB" not found.
>>
>> But it works when i do
>>
>> initialContext.lookup("/DS_DB")
>> initialContext.lookup("java:openejb:Resource/DS_DB")
>>
>> I am wondering, why it won't work with *java:/DS_DB*
>>
>> I am using openejb-core-8.0.0-M3 . version.
>>
>> thanks
>> Kalyan
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> Sent from:
>> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>>
>
   --
    Jean-Louis Monteiro
    http://twitter.com/jlouismonteiro
    http://www.tomitribe.com
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Josef Puff
Please remove me from this list.
I already tried it several times but I’m in til now so I really don’t like
to get more information about this subject.
Can anyone help me to get out?

Von: Monteiro Jean-Louis <[hidden email]>
<[hidden email]>
Antworten: [hidden email] <[hidden email]>
<[hidden email]>
Datum: 24. Juni 2019 at 10:08:54
An: [hidden email] <[hidden email]> <[hidden email]>
Betreff:  Re: Bind Datasource to specific jndi name

The Java EE platform specification defines the following JNDI contexts:

java:comp - The namespace is scoped to the current component (i.e. EJB)
java:module - Scoped to the current module
java:app - Scoped to the current application
java:global - Scoped to the application server

-
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com


On Mon, Jun 24, 2019 at 10:05 AM Jean-Louis Monteiro <
[hidden email]> wrote:

> Hi,
>
> Sorry for the delay.
> I have looked at the question and there is an alias="name1,name2"
> attribute you can use to define different aliases for the same resource.
>
> It is useful when you are migrating from another app server.
>
> That being said, the "java:" namespace in jndi is restricted per spec, so
> I'm not sure you will be able to define the name you want.
>
> Give it a try and let us know anyway.
> --
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
>
> On Fri, Jun 21, 2019 at 6:01 PM Kalyan <[hidden email]> wrote:
>
>> I really appreciate that.
>>
>> The problem i have is
>>
>> I created the datasource as
>>
>> p.put("DS_DB", "new://Resource?type=javax.sql.DataSource");
>> p.put("DS_DB.JdbcDriver", "oracle.jdbc.OracleDriver");
>> p.put("DS_DB.JdbcUrl", "jdbc:oracle:thin:@xxxxxx:1521/rwdb");
>> p.put("DS_DB.UserName", "ds_user");
>> p.put("DS_DB.Password", "xxxxxxx");
>> p.put("DS_DB.LogSql", "true");
>> p.put("DS_DB.JtaManaged", "true");
>>
>>
>> InitialContext initialContext = new InitialContext(p);
>>
>> initialContext.bind("java:/DS_DB",new
>> javax.naming.LinkRef("java:openejb:Resource/DS_DB"));
>>
>> Now i am trying to look up
>>
>> initialContext.lookup("java:/DS_DB") :
>> javax.naming.NameNotFoundException:
>> Name "DS_DB" not found.
>>
>> But it works when i do
>>
>> initialContext.lookup("/DS_DB")
>> initialContext.lookup("java:openejb:Resource/DS_DB")
>>
>> I am wondering, why it won't work with *java:/DS_DB*
>>
>> I am using openejb-core-8.0.0-M3 . version.
>>
>> thanks
>> Kalyan
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> Sent from:
>> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Jean-Louis MONTEIRO
Hi Josef,

We can't unsubscribe you. You have to do it yourself.
Here is the process though.

basically, send an email to [hidden email]

You should receive a confirmation email and then you have to reply to it to
finalize the process.
--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com


On Mon, Jun 24, 2019 at 10:10 AM Josef Puff <[hidden email]> wrote:

> Please remove me from this list.
> I already tried it several times but I’m in til now so I really don’t like
> to get more information about this subject.
> Can anyone help me to get out?
>
> Von: Monteiro Jean-Louis <[hidden email]>
> <[hidden email]>
> Antworten: [hidden email] <[hidden email]>
> <[hidden email]>
> Datum: 24. Juni 2019 at 10:08:54
> An: [hidden email] <[hidden email]>
> <[hidden email]>
> Betreff:  Re: Bind Datasource to specific jndi name
>
> The Java EE platform specification defines the following JNDI contexts:
>
> java:comp - The namespace is scoped to the current component (i.e. EJB)
> java:module - Scoped to the current module
> java:app - Scoped to the current application
> java:global - Scoped to the application server
>
> -
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
>
> On Mon, Jun 24, 2019 at 10:05 AM Jean-Louis Monteiro <
> [hidden email]> wrote:
>
> > Hi,
> >
> > Sorry for the delay.
> > I have looked at the question and there is an alias="name1,name2"
> > attribute you can use to define different aliases for the same resource.
> >
> > It is useful when you are migrating from another app server.
> >
> > That being said, the "java:" namespace in jndi is restricted per spec,
> so
> > I'm not sure you will be able to define the name you want.
> >
> > Give it a try and let us know anyway.
> > --
> > Jean-Louis Monteiro
> > http://twitter.com/jlouismonteiro
> > http://www.tomitribe.com
> >
> >
> > On Fri, Jun 21, 2019 at 6:01 PM Kalyan <[hidden email]> wrote:
> >
> >> I really appreciate that.
> >>
> >> The problem i have is
> >>
> >> I created the datasource as
> >>
> >> p.put("DS_DB", "new://Resource?type=javax.sql.DataSource");
> >> p.put("DS_DB.JdbcDriver", "oracle.jdbc.OracleDriver");
> >> p.put("DS_DB.JdbcUrl", "jdbc:oracle:thin:@xxxxxx:1521/rwdb");
> >> p.put("DS_DB.UserName", "ds_user");
> >> p.put("DS_DB.Password", "xxxxxxx");
> >> p.put("DS_DB.LogSql", "true");
> >> p.put("DS_DB.JtaManaged", "true");
> >>
> >>
> >> InitialContext initialContext = new InitialContext(p);
> >>
> >> initialContext.bind("java:/DS_DB",new
> >> javax.naming.LinkRef("java:openejb:Resource/DS_DB"));
> >>
> >> Now i am trying to look up
> >>
> >> initialContext.lookup("java:/DS_DB") :
> >> javax.naming.NameNotFoundException:
> >> Name "DS_DB" not found.
> >>
> >> But it works when i do
> >>
> >> initialContext.lookup("/DS_DB")
> >> initialContext.lookup("java:openejb:Resource/DS_DB")
> >>
> >> I am wondering, why it won't work with *java:/DS_DB*
> >>
> >> I am using openejb-core-8.0.0-M3 . version.
> >>
> >> thanks
> >> Kalyan
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> --
> >> Sent from:
> >> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
> >>
> >
>
>
   --
    Jean-Louis Monteiro
    http://twitter.com/jlouismonteiro
    http://www.tomitribe.com
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Josef Puff
Thanks I try it

Von: Monteiro Jean-Louis <[hidden email]>
<[hidden email]>
Antworten: Monteiro Jean-Louis <[hidden email]>
<[hidden email]>
Datum: 24. Juni 2019 at 10:15:29
An: Puff Josef <[hidden email]> <[hidden email]>
CC: [hidden email] <[hidden email]> <[hidden email]>
Betreff:  Re: Bind Datasource to specific jndi name

Hi Josef,

We can't unsubscribe you. You have to do it yourself.
Here is the process though.

basically, send an email to [hidden email]

You should receive a confirmation email and then you have to reply to it to
finalize the process.
--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com


On Mon, Jun 24, 2019 at 10:10 AM Josef Puff <[hidden email]> wrote:

> Please remove me from this list.
> I already tried it several times but I’m in til now so I really don’t like
> to get more information about this subject.
> Can anyone help me to get out?
>
> Von: Monteiro Jean-Louis <[hidden email]>
> <[hidden email]>
> Antworten: [hidden email] <[hidden email]>
> <[hidden email]>
> Datum: 24. Juni 2019 at 10:08:54
> An: [hidden email] <[hidden email]>
> <[hidden email]>
> Betreff:  Re: Bind Datasource to specific jndi name
>
> The Java EE platform specification defines the following JNDI contexts:
>
> java:comp - The namespace is scoped to the current component (i.e. EJB)
> java:module - Scoped to the current module
> java:app - Scoped to the current application
> java:global - Scoped to the application server
>
> -
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
>
> On Mon, Jun 24, 2019 at 10:05 AM Jean-Louis Monteiro <
> [hidden email]> wrote:
>
> > Hi,
> >
> > Sorry for the delay.
> > I have looked at the question and there is an alias="name1,name2"
> > attribute you can use to define different aliases for the same resource.
> >
> > It is useful when you are migrating from another app server.
> >
> > That being said, the "java:" namespace in jndi is restricted per spec, so
> > I'm not sure you will be able to define the name you want.
> >
> > Give it a try and let us know anyway.
> > --
> > Jean-Louis Monteiro
> > http://twitter.com/jlouismonteiro
> > http://www.tomitribe.com
> >
> >
> > On Fri, Jun 21, 2019 at 6:01 PM Kalyan <[hidden email]> wrote:
> >
> >> I really appreciate that.
> >>
> >> The problem i have is
> >>
> >> I created the datasource as
> >>
> >> p.put("DS_DB", "new://Resource?type=javax.sql.DataSource");
> >> p.put("DS_DB.JdbcDriver", "oracle.jdbc.OracleDriver");
> >> p.put("DS_DB.JdbcUrl", "jdbc:oracle:thin:@xxxxxx:1521/rwdb");
> >> p.put("DS_DB.UserName", "ds_user");
> >> p.put("DS_DB.Password", "xxxxxxx");
> >> p.put("DS_DB.LogSql", "true");
> >> p.put("DS_DB.JtaManaged", "true");
> >>
> >>
> >> InitialContext initialContext = new InitialContext(p);
> >>
> >> initialContext.bind("java:/DS_DB",new
> >> javax.naming.LinkRef("java:openejb:Resource/DS_DB"));
> >>
> >> Now i am trying to look up
> >>
> >> initialContext.lookup("java:/DS_DB") :
> >> javax.naming.NameNotFoundException:
> >> Name "DS_DB" not found.
> >>
> >> But it works when i do
> >>
> >> initialContext.lookup("/DS_DB")
> >> initialContext.lookup("java:openejb:Resource/DS_DB")
> >>
> >> I am wondering, why it won't work with *java:/DS_DB*
> >>
> >> I am using openejb-core-8.0.0-M3 . version.
> >>
> >> thanks
> >> Kalyan
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> --
> >> Sent from:
> >> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
> >>
> >
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Bind Datasource to specific jndi name

Kalyan
In reply to this post by Jean-Louis MONTEIRO
Thanks Jean-Louis MONTEIRO.
you're correct. Looks like in my case its binding to java:global.
I have done little mapping to match as per the openejb spec.
So that my old application as well the migrated application to openejb will
work.

It works.



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html