You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Jacek Laskowski <ja...@laskowski.net.pl> on 2007/11/19 15:25:36 UTC

Hidding JNDI entries with the command line values

Hi,

Just run across it and couldn't believe what I was looking at - it's
in org.apache.openejb.client.JNDIContext at line 183 (openejb-client
module):

    public Object lookup(String name) throws NamingException {

        if (name == null) throw new InvalidNameException("The name
cannot be null");
        else if (name.equals("")) return new JNDIContext(this);
        else if (name.startsWith("java:")) name =
name.replaceFirst("^java:", "");
        else if (!name.startsWith("/")) name = tail + name;

        String prop = name.replaceFirst("comp/env/", "");
        String value = System.getProperty(prop); // line 183
        if (value != null) {
            return parseEntry(prop, value);
        }

        if (name.equals("comp/ORB")) {
            return getDefaultOrb();
        }

It means that you can specify JNDI entries on the command line of openejb like

  ./bin/openejb
-Djdbc/derby=datasource:org.apache.derby.jdbc.EmbeddedDriver:c:/temp/derby-db\;create=true
start

and whenever you look up the name - jdbc/derby - in JNDI it will
return ClientDataSource for derby not the value bound to the JNDI
tree. Definitely nice to know.

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl

Re: Hidding JNDI entries with the command line values

Posted by David Blevins <da...@visi.com>.
On Nov 19, 2007, at 6:25 AM, Jacek Laskowski wrote:

> Hi,
>
> Just run across it and couldn't believe what I was looking at - it's
> in org.apache.openejb.client.JNDIContext at line 183 (openejb-client
> module):
>
>    public Object lookup(String name) throws NamingException {
>
>        if (name == null) throw new InvalidNameException("The name
> cannot be null");
>        else if (name.equals("")) return new JNDIContext(this);
>        else if (name.startsWith("java:")) name =
> name.replaceFirst("^java:", "");
>        else if (!name.startsWith("/")) name = tail + name;
>
>        String prop = name.replaceFirst("comp/env/", "");
>        String value = System.getProperty(prop); // line 183
>        if (value != null) {
>            return parseEntry(prop, value);
>        }
>
>        if (name.equals("comp/ORB")) {
>            return getDefaultOrb();
>        }
>
> It means that you can specify JNDI entries on the command line of  
> openejb like
>
>  ./bin/openejb
> -Djdbc/derby=datasource:org.apache.derby.jdbc.EmbeddedDriver:c:/temp/ 
> derby-db\;create=true
> start

It works exactly like that, but only for clients connecting over the  
ejbd protocol, not for things in the server itself.  So the above  
wouldn't do much at all, but this would:

   java -Djdbc/ 
derby=datasource:org.apache.derby.jdbc.EmbeddedDriver:c:/temp/derby-db 
\;create=true -jar myApplication.jar

> and whenever you look up the name - jdbc/derby - in JNDI it will
> return ClientDataSource for derby not the value bound to the JNDI
> tree. Definitely nice to know.

Right! It essentially allows an client app (either standalone or of  
the javaee variety) to add or override jndi entries either through the  
command line or via setting system properties in it's vm.

Pretty impressive finding that little gem amongst our copious code.

Along these same lines if you crack open the assembly/openejb- 
standalone/src/main/conf/README.txt and read the "OTHER MEANS OF  
OVERRIDING" you'll find similar features.

-David


-David