You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by lucky lance <lu...@yahoo.ca> on 2008/02/08 20:32:44 UTC

How to lookup an EJB3 session bean by JNDI?

Hi all,
I deployed an  EJB3  stateless  session  bean  in geronimo 2.0.2.
Then I try to lookup it via the traditional JNDI.
The code
package foo;
@Remote
public interface MyRemote{
    public String getMessage(); 
}

package foo;
@Stateless
public class MyBean implements MyRemote{
    public String getMessage(){
        return "hello world";
    }
}

// The client
InitialContext ctx = new IntialContext();
Object obj = ctx.lookup("foo.MyBean");

It throws a NamingException.
I can not lookup either by the names like,
"MyBean",
"foo/MyBean",
"java:comp/foo.MyBean",
  "java:comp/env/foo.MyBean",
   "java:comp/foo/MyBean",
 "EJBModule/foo/MyBean/1.0/jar/SessionBeans/MyBean",
"EJBModule/foo/MyBean/1.0/jar/SessionBeans/foo.MyBean",
 "EJBModule/foo/MyBean/1.0/jar/SessionBeans/foo/MyBean",
  

The question is how to write the correct jndi name?
Thanks


       
---------------------------------
Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail  

Re: How to lookup an EJB3 session bean by JNDI?

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Fri, Feb 8, 2008 at 1:03 PM, lucky lance <lu...@yahoo.ca> wrote:

> env.put("java.naming.provider.url","iiop://localhost:1050");

What's this? I'm not sure iiop will work. I'm not sure, but just
remove the line at all and run the app with only
Context.INITIAL_CONTEXT_FACTORY (or its stringified version -
java.naming.factory.initial) specified. Let us know how it's worked
out.

Jacek

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

Re: How to lookup an EJB3 session bean by JNDI?

Posted by Tomasz Mazan <wi...@wp.pl>.
lucky lance pisze:
> Thank you for a quick response.
> I am a new learner of Geronimo.
> Actually my client code is,
> Hashtable<String,String> env = new Hashtable<String,String>();         
> env.put("java.naming.factory.initial","org.apache.openejb.client.RemoteInitialContextFactory");
> env.put("java.naming.provider.url","iiop://localhost:1050");
> InitialContext ctx = new InitialContext(env);
>
> Object obj = ctx.lookup(jndiName);
>
> The problem is no matter how I write the jndiName, a NamingException 
> will be thrown complaining it can not find the name. And the similiar 
> code works fine in Glassfish, JBoss, WebSphere 6.1 + EJB3, and .
> My question is whether geronimo supports  the standard way 
> ctx.lookup("foo.MyBean") as well, or what's the proper jndi string?
>
> My result of jndi names,
> Glassfish:  "foo.MyRemote"
> JBoss:      "foo.MyBean/remote"
> Webshpere: "foo.MyRemote" with IBM jvm.
>   "nodes/<hostname>/node/servers/server1/foo\.MyRemote" with Sun jvm.
> Geronimo:   ?
>
> Or is where any setting to enable the remote EJB client
> from the default.
>
> Thanks
> Lance
Hi
1) You can change your log level and you'll find your jndi name
2) For G 2.0.2 it's 'MyBeanRemote' by the default (bean name + type of 
interface)

You can find all this information in wiki -> 
http://cwiki.apache.org/GMOxDEV/client-jndi-names.html

Beniamin

Re: How to lookup an EJB3 session bean by JNDI?

Posted by lucky lance <lu...@yahoo.ca>.
Thank you for a quick response. 
I am a new learner of Geronimo. 
Actually my client code is,
Hashtable<String,String> env = new Hashtable<String,String>();         env.put("java.naming.factory.initial","org.apache.openejb.client.RemoteInitialContextFactory");
env.put("java.naming.provider.url","iiop://localhost:1050");
InitialContext ctx = new InitialContext(env);

Object obj = ctx.lookup(jndiName);

The problem is no matter how I write the jndiName, a NamingException will be thrown complaining it can not find the name. And the similiar code works fine in Glassfish, JBoss, WebSphere 6.1 + EJB3, and .
My question is whether geronimo supports  the standard way ctx.lookup("foo.MyBean") as well, or what's the proper jndi string?

My result of jndi names,
Glassfish:  "foo.MyRemote"
JBoss:      "foo.MyBean/remote"
Webshpere: "foo.MyRemote" with IBM  jvm.
  "nodes/<hostname>/node/servers/server1/foo\.MyRemote" with Sun jvm.
Geronimo:   ?

Or is where any setting to enable the remote EJB client
from the default.

Thanks
Lance

Viet Nguyen <vh...@gmail.com> wrote: I'm assuming that you want to remotely look up the session bean.

If it is so you can use this piece of code:

                Properties props = new Properties();
                props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
                props.setProperty(Context.PROVIDER_URL, "ejbd://" +
+ ":" + 
);
                Context ic = new InitialContext(props);
                myBean = (MyBeanRemote) ic.lookup();

where  can be found in your geronimo-log and  is
whatever your server's IP is.

Hope this helps,
Viet Nguyen




       
---------------------------------
Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail  

Re: How to lookup an EJB3 session bean by JNDI?

Posted by Viet Nguyen <vh...@gmail.com>.
I'm assuming that you want to remotely look up the session bean.

If it is so you can use this piece of code:

                Properties props = new Properties();
                props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
                props.setProperty(Context.PROVIDER_URL, "ejbd://" +
<ip>+ ":" + <port>);
                Context ic = new InitialContext(props);
                myBean = (MyBeanRemote) ic.lookup(<jndi-name>);

where <jndi-name> can be found in your geronimo-log and <ip> is
whatever your server's IP is.

Hope this helps,
Viet Nguyen

On Feb 8, 2008 2:32 PM, lucky lance <lu...@yahoo.ca> wrote:
> Hi all,
> I deployed an  EJB3  stateless  session  bean  in geronimo 2.0.2.
> Then I try to lookup it via the traditional JNDI.
> The code
> package foo;
> @Remote
> public interface MyRemote{
>     public String getMessage();
> }
>
> package foo;
> @Stateless
> public class MyBean implements MyRemote{
>     public String getMessage(){
>        return "hello world";
>     }
> }
>
> // The client
> InitialContext ctx = new IntialContext();
> Object obj = ctx.lookup("foo.MyBean");
>
> It throws a NamingException.
> I can not lookup either by the names like,
> "MyBean",
> "foo/MyBean",
> "java:comp/foo.MyBean",
>  "java:comp/env/foo.MyBean",
>  "java:comp/foo/MyBean",
>  "EJBModule/foo/MyBean/1.0/jar/SessionBeans/MyBean",
> "EJBModule/foo/MyBean/1.0/jar/SessionBeans/foo.MyBean",
>  "EJBModule/foo/MyBean/1.0/jar/SessionBeans/foo/MyBean",
>
>
> The question is how to write the correct jndi name?
> Thanks
>
>
>
>  ________________________________
> Be smarter than spam. See how smart SpamGuard is at giving junk email the
> boot with the All-new Yahoo! Mail