Local Session Bean lookups and JNDI

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

Local Session Bean lookups and JNDI

Neal Sanche
Hi All,

Well, I'm working through the details for a Struts web app with an EJB
back end, all being compiled with a Maven build script and just putting
all of the pieces in place to have XDoclet 1.2.3 do much of the major
gruntwork for the Struts-config.xml and the ejb-jar.xml and web.xml
also. Lots of details, but most of them are coming together now.

But I'm stuck on the JNDI side of things, it seems. I've discovered the
need for specifying the jndi-name and local-jndi-name for my CMP 2 EJB,
and my Stateless Session Bean inside of openejb-jar.xml and I've
confirmed that my changes are having an effect on the deployed
application by looking at the Debug Console and clicking on my EJBs. I
have also put entries in my web.xml to link them like I used to do with
another container I've used before. But I think maybe there's more to it
in Geronimo? I can't do Local JNDI lookups and instantiate my EJBs like
I used to be able to?

Do I need something in the geronimo-jetty.xml deployment plan file? What
I have in my web.xml looks like this:

   <ejb-local-ref >
      <ejb-ref-name>ejb/PhoneBookEntryLocal</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
     
<local-home>org.acme.phonebook.ejb.PhoneBookEntryLocalHome</local-home>
      <local>org.acme.phonebook.ejb.PhoneBookEntryLocal</local>
      <ejb-link>PhoneBookEntry</ejb-link>
   </ejb-local-ref>
   <ejb-local-ref >
      <ejb-ref-name>ejb/PhoneBookSessionLocal</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
     
<local-home>org.acme.phonebook.ejb.PhoneBookSessionLocalHome</local-home>
      <local>org.acme.phonebook.ejb.PhoneBookSessionLocal</local>
      <ejb-link>PhoneBookSession</ejb-link>
   </ejb-local-ref>

My Debug Console looks something like the following:

JndiNames [PhoneBookEntry]
LocalJndiNames [org.acme.phonebook.ejb/PhoneBookEntryLocalHome]


and

JndiNames [org.acme.phonebook.ejb/PhoneBookSession/Home]
LocalJndiNames [org.acme.phonebook.ejb/PhoneBookSession/LocalHome]


for each of them. Yes, I know, I make strange names for my JNDI
entries... but that's what XDoclet seems to do for me, and as long as I
can get it working, I don't care what it looks like. But, when I try the
following code, Geronimo does this:

    public Collection getEntries() {
        try {
            InitialContext ctx = new InitialContext();
            PhoneBookSessionLocal session =
PhoneBookSessionUtil.getLocalHome().create();
            Collection c = session.listEntries();
            return c;
        } catch (Throwable ex) {
            System.err.println(ex);
            ex.printStackTrace();
        }
       
        return new ArrayList();
    }


javax.naming.NameNotFoundException: org.acme.phonebook.ejb
javax.naming.NameNotFoundException: org.acme.phonebook.ejb
        at
com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
:95)
        at
com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
:103)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at
org.acme.phonebook.ejb.PhoneBookSessionUtil.lookupHome(PhoneBookSessi
onUtil.java:16)
        at
org.acme.phonebook.ejb.PhoneBookSessionUtil.getLocalHome(PhoneBookSes
sionUtil.java:54)
        at org.acme.phonebook.struts.PhoneList.getEntries(PhoneList.java:51)

XDoclet is generating the following method, which I've used for years
without incident:

   public static org.acme.phonebook.ejb.PhoneBookSessionLocalHome
getLocalHome() throws javax.naming.NamingException
   {
      return (org.acme.phonebook.ejb.PhoneBookSessionLocalHome)
lookupHome(null,
org.acme.phonebook.ejb.PhoneBookSessionLocalHome.JNDI_NAME,
org.acme.phonebook.ejb.PhoneBookSessionLocalHome.class);
   }

   private static Object lookupHome(java.util.Hashtable environment,
String jndiName, Class narrowTo) throws javax.naming.NamingException {
      // Obtain initial context
      javax.naming.InitialContext initialContext = new
javax.naming.InitialContext(environment);
      try {
         Object objRef = initialContext.lookup(jndiName);
         // only narrow if necessary
         if (java.rmi.Remote.class.isAssignableFrom(narrowTo))
            return javax.rmi.PortableRemoteObject.narrow(objRef, narrowTo);
         else
            return objRef;
      } finally {
         initialContext.close();
      }
   }

and the constants that it's using are:

   public static final String
COMP_NAME="java:comp/env/ejb/PhoneBookSessionLocal";
   public static final String
JNDI_NAME="org.acme.phonebook.ejb/PhoneBookSession/LocalHome";


I guess I'm feeling a little blind these days, since working with
another container I was always able to simply take a squint at the JNDI
tree through a nice little JMX method. Is there a similar operation I
can do with this Debug Console? Remember I'm using Geronimo HEAD for
most of this (I guess it's time for another maven m:update though).

Thanks for any insights you can give on better using JNDI and bridging
the gap between the Web application and the EJB world.

Thanks.

-Neal


Reply | Threaded
Open this post in threaded view
|

Re: Local Session Bean lookups and JNDI

ammulder
        It sounds like PhoneBookSessionUtil is trying to look up the JNDI
name:

org.acme.phonebook.ejb/PhoneBookSession/LocalHome

        When really, based on the EJB ref you created, it should be
looking up:

java:comp/env/ejb/PhoneBookSessionLocal

        There might be another method or constant in PhoneBookSessionUtil
that you can use to achieve this.  Otherwise, just do this:

PhoneBookSessionLocal session = ((PhoneBookSessionHome)
     ctx.lookup("java:comp/env/ejb/PhoneBookSessionLocal")).create();

        If you get that working, you can forget about the jndi-name and
local-jndi-name (they won't be necessary unless you have an application
client).

Aaron

On Thu, 16 Jun 2005, Neal Sanche wrote:

> Hi All,
>
> Well, I'm working through the details for a Struts web app with an EJB
> back end, all being compiled with a Maven build script and just putting
> all of the pieces in place to have XDoclet 1.2.3 do much of the major
> gruntwork for the Struts-config.xml and the ejb-jar.xml and web.xml
> also. Lots of details, but most of them are coming together now.
>
> But I'm stuck on the JNDI side of things, it seems. I've discovered the
> need for specifying the jndi-name and local-jndi-name for my CMP 2 EJB,
> and my Stateless Session Bean inside of openejb-jar.xml and I've
> confirmed that my changes are having an effect on the deployed
> application by looking at the Debug Console and clicking on my EJBs. I
> have also put entries in my web.xml to link them like I used to do with
> another container I've used before. But I think maybe there's more to it
> in Geronimo? I can't do Local JNDI lookups and instantiate my EJBs like
> I used to be able to?
>
> Do I need something in the geronimo-jetty.xml deployment plan file? What
> I have in my web.xml looks like this:
>
>    <ejb-local-ref >
>       <ejb-ref-name>ejb/PhoneBookEntryLocal</ejb-ref-name>
>       <ejb-ref-type>Entity</ejb-ref-type>
>      
> <local-home>org.acme.phonebook.ejb.PhoneBookEntryLocalHome</local-home>
>       <local>org.acme.phonebook.ejb.PhoneBookEntryLocal</local>
>       <ejb-link>PhoneBookEntry</ejb-link>
>    </ejb-local-ref>
>    <ejb-local-ref >
>       <ejb-ref-name>ejb/PhoneBookSessionLocal</ejb-ref-name>
>       <ejb-ref-type>Session</ejb-ref-type>
>      
> <local-home>org.acme.phonebook.ejb.PhoneBookSessionLocalHome</local-home>
>       <local>org.acme.phonebook.ejb.PhoneBookSessionLocal</local>
>       <ejb-link>PhoneBookSession</ejb-link>
>    </ejb-local-ref>
>
> My Debug Console looks something like the following:
>
> JndiNames [PhoneBookEntry]
> LocalJndiNames [org.acme.phonebook.ejb/PhoneBookEntryLocalHome]
>
>
> and
>
> JndiNames [org.acme.phonebook.ejb/PhoneBookSession/Home]
> LocalJndiNames [org.acme.phonebook.ejb/PhoneBookSession/LocalHome]
>
>
> for each of them. Yes, I know, I make strange names for my JNDI
> entries... but that's what XDoclet seems to do for me, and as long as I
> can get it working, I don't care what it looks like. But, when I try the
> following code, Geronimo does this:
>
>     public Collection getEntries() {
>         try {
>             InitialContext ctx = new InitialContext();
>             PhoneBookSessionLocal session =
> PhoneBookSessionUtil.getLocalHome().create();
>             Collection c = session.listEntries();
>             return c;
>         } catch (Throwable ex) {
>             System.err.println(ex);
>             ex.printStackTrace();
>         }
>        
>         return new ArrayList();
>     }
>
>
> javax.naming.NameNotFoundException: org.acme.phonebook.ejb
> javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>         at
> com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
> :95)
>         at
> com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
> :103)
>         at javax.naming.InitialContext.lookup(InitialContext.java:351)
>         at
> org.acme.phonebook.ejb.PhoneBookSessionUtil.lookupHome(PhoneBookSessi
> onUtil.java:16)
>         at
> org.acme.phonebook.ejb.PhoneBookSessionUtil.getLocalHome(PhoneBookSes
> sionUtil.java:54)
>         at org.acme.phonebook.struts.PhoneList.getEntries(PhoneList.java:51)
>
> XDoclet is generating the following method, which I've used for years
> without incident:
>
>    public static org.acme.phonebook.ejb.PhoneBookSessionLocalHome
> getLocalHome() throws javax.naming.NamingException
>    {
>       return (org.acme.phonebook.ejb.PhoneBookSessionLocalHome)
> lookupHome(null,
> org.acme.phonebook.ejb.PhoneBookSessionLocalHome.JNDI_NAME,
> org.acme.phonebook.ejb.PhoneBookSessionLocalHome.class);
>    }
>
>    private static Object lookupHome(java.util.Hashtable environment,
> String jndiName, Class narrowTo) throws javax.naming.NamingException {
>       // Obtain initial context
>       javax.naming.InitialContext initialContext = new
> javax.naming.InitialContext(environment);
>       try {
>          Object objRef = initialContext.lookup(jndiName);
>          // only narrow if necessary
>          if (java.rmi.Remote.class.isAssignableFrom(narrowTo))
>             return javax.rmi.PortableRemoteObject.narrow(objRef, narrowTo);
>          else
>             return objRef;
>       } finally {
>          initialContext.close();
>       }
>    }
>
> and the constants that it's using are:
>
>    public static final String
> COMP_NAME="java:comp/env/ejb/PhoneBookSessionLocal";
>    public static final String
> JNDI_NAME="org.acme.phonebook.ejb/PhoneBookSession/LocalHome";
>
>
> I guess I'm feeling a little blind these days, since working with
> another container I was always able to simply take a squint at the JNDI
> tree through a nice little JMX method. Is there a similar operation I
> can do with this Debug Console? Remember I'm using Geronimo HEAD for
> most of this (I guess it's time for another maven m:update though).
>
> Thanks for any insights you can give on better using JNDI and bridging
> the gap between the Web application and the EJB world.
>
> Thanks.
>
> -Neal
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Local Session Bean lookups and JNDI

Neal Sanche
Hi Again Aaron,

You're right, that does work, thanks. From that, I'll see if I can
figure out how to back-track and get XDoclet to generate something that
will work in this case. I think I should be able to. But I have a
fallback position anyway.

Cheers.

-Neal

Aaron Mulder wrote:

> It sounds like PhoneBookSessionUtil is trying to look up the JNDI
>name:
>
>org.acme.phonebook.ejb/PhoneBookSession/LocalHome
>
> When really, based on the EJB ref you created, it should be
>looking up:
>
>java:comp/env/ejb/PhoneBookSessionLocal
>
> There might be another method or constant in PhoneBookSessionUtil
>that you can use to achieve this.  Otherwise, just do this:
>
>PhoneBookSessionLocal session = ((PhoneBookSessionHome)
>     ctx.lookup("java:comp/env/ejb/PhoneBookSessionLocal")).create();
>
> If you get that working, you can forget about the jndi-name and
>local-jndi-name (they won't be necessary unless you have an application
>client).
>
>Aaron
>
>On Thu, 16 Jun 2005, Neal Sanche wrote:
>  
>
>>Hi All,
>>
>>Well, I'm working through the details for a Struts web app with an EJB
>>back end, all being compiled with a Maven build script and just putting
>>all of the pieces in place to have XDoclet 1.2.3 do much of the major
>>gruntwork for the Struts-config.xml and the ejb-jar.xml and web.xml
>>also. Lots of details, but most of them are coming together now.
>>
>>But I'm stuck on the JNDI side of things, it seems. I've discovered the
>>need for specifying the jndi-name and local-jndi-name for my CMP 2 EJB,
>>and my Stateless Session Bean inside of openejb-jar.xml and I've
>>confirmed that my changes are having an effect on the deployed
>>application by looking at the Debug Console and clicking on my EJBs. I
>>have also put entries in my web.xml to link them like I used to do with
>>another container I've used before. But I think maybe there's more to it
>>in Geronimo? I can't do Local JNDI lookups and instantiate my EJBs like
>>I used to be able to?
>>
>>Do I need something in the geronimo-jetty.xml deployment plan file? What
>>I have in my web.xml looks like this:
>>
>>   <ejb-local-ref >
>>      <ejb-ref-name>ejb/PhoneBookEntryLocal</ejb-ref-name>
>>      <ejb-ref-type>Entity</ejb-ref-type>
>>      
>><local-home>org.acme.phonebook.ejb.PhoneBookEntryLocalHome</local-home>
>>      <local>org.acme.phonebook.ejb.PhoneBookEntryLocal</local>
>>      <ejb-link>PhoneBookEntry</ejb-link>
>>   </ejb-local-ref>
>>   <ejb-local-ref >
>>      <ejb-ref-name>ejb/PhoneBookSessionLocal</ejb-ref-name>
>>      <ejb-ref-type>Session</ejb-ref-type>
>>      
>><local-home>org.acme.phonebook.ejb.PhoneBookSessionLocalHome</local-home>
>>      <local>org.acme.phonebook.ejb.PhoneBookSessionLocal</local>
>>      <ejb-link>PhoneBookSession</ejb-link>
>>   </ejb-local-ref>
>>
>>My Debug Console looks something like the following:
>>
>>JndiNames [PhoneBookEntry]
>>LocalJndiNames [org.acme.phonebook.ejb/PhoneBookEntryLocalHome]
>>
>>
>>and
>>
>>JndiNames [org.acme.phonebook.ejb/PhoneBookSession/Home]
>>LocalJndiNames [org.acme.phonebook.ejb/PhoneBookSession/LocalHome]
>>
>>
>>for each of them. Yes, I know, I make strange names for my JNDI
>>entries... but that's what XDoclet seems to do for me, and as long as I
>>can get it working, I don't care what it looks like. But, when I try the
>>following code, Geronimo does this:
>>
>>    public Collection getEntries() {
>>        try {
>>            InitialContext ctx = new InitialContext();
>>            PhoneBookSessionLocal session =
>>PhoneBookSessionUtil.getLocalHome().create();
>>            Collection c = session.listEntries();
>>            return c;
>>        } catch (Throwable ex) {
>>            System.err.println(ex);
>>            ex.printStackTrace();
>>        }
>>      
>>        return new ArrayList();
>>    }
>>
>>
>>javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>>javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>>        at
>>com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
>>:95)
>>        at
>>com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
>>:103)
>>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>        at
>>org.acme.phonebook.ejb.PhoneBookSessionUtil.lookupHome(PhoneBookSessi
>>onUtil.java:16)
>>        at
>>org.acme.phonebook.ejb.PhoneBookSessionUtil.getLocalHome(PhoneBookSes
>>sionUtil.java:54)
>>        at org.acme.phonebook.struts.PhoneList.getEntries(PhoneList.java:51)
>>
>>XDoclet is generating the following method, which I've used for years
>>without incident:
>>
>>   public static org.acme.phonebook.ejb.PhoneBookSessionLocalHome
>>getLocalHome() throws javax.naming.NamingException
>>   {
>>      return (org.acme.phonebook.ejb.PhoneBookSessionLocalHome)
>>lookupHome(null,
>>org.acme.phonebook.ejb.PhoneBookSessionLocalHome.JNDI_NAME,
>>org.acme.phonebook.ejb.PhoneBookSessionLocalHome.class);
>>   }
>>
>>   private static Object lookupHome(java.util.Hashtable environment,
>>String jndiName, Class narrowTo) throws javax.naming.NamingException {
>>      // Obtain initial context
>>      javax.naming.InitialContext initialContext = new
>>javax.naming.InitialContext(environment);
>>      try {
>>         Object objRef = initialContext.lookup(jndiName);
>>         // only narrow if necessary
>>         if (java.rmi.Remote.class.isAssignableFrom(narrowTo))
>>            return javax.rmi.PortableRemoteObject.narrow(objRef, narrowTo);
>>         else
>>            return objRef;
>>      } finally {
>>         initialContext.close();
>>      }
>>   }
>>
>>and the constants that it's using are:
>>
>>   public static final String
>>COMP_NAME="java:comp/env/ejb/PhoneBookSessionLocal";
>>   public static final String
>>JNDI_NAME="org.acme.phonebook.ejb/PhoneBookSession/LocalHome";
>>
>>
>>I guess I'm feeling a little blind these days, since working with
>>another container I was always able to simply take a squint at the JNDI
>>tree through a nice little JMX method. Is there a similar operation I
>>can do with this Debug Console? Remember I'm using Geronimo HEAD for
>>most of this (I guess it's time for another maven m:update though).
>>
>>Thanks for any insights you can give on better using JNDI and bridging
>>the gap between the Web application and the EJB world.
>>
>>Thanks.
>>
>>-Neal
>>
>>
>>
>>    
>>

Reply | Threaded
Open this post in threaded view
|

Re: Local Session Bean lookups and JNDI

David Jencks
In reply to this post by ammulder

On Jun 16, 2005, at 9:05 PM, Aaron Mulder wrote:

> It sounds like PhoneBookSessionUtil is trying to look up the JNDI
> name:
>
> org.acme.phonebook.ejb/PhoneBookSession/LocalHome
>
> When really, based on the EJB ref you created, it should be
> looking up:
>
> java:comp/env/ejb/PhoneBookSessionLocal
>
> There might be another method or constant in PhoneBookSessionUtil
> that you can use to achieve this.  Otherwise, just do this:
>
> PhoneBookSessionLocal session = ((PhoneBookSessionHome)
>      ctx.lookup("java:comp/env/ejb/PhoneBookSessionLocal")).create();
>
> If you get that working, you can forget about the jndi-name and
> local-jndi-name (they won't be necessary unless you have an application
> client).

ejb-links work from j2ee app clients also.  jndi-name is only needed if  
you want to use a non-j2ee-app-client.  It is also useful for binding  
in the  corba name service under a different name than the ejb name.

david jencks

>
> Aaron
>
> On Thu, 16 Jun 2005, Neal Sanche wrote:
>> Hi All,
>>
>> Well, I'm working through the details for a Struts web app with an EJB
>> back end, all being compiled with a Maven build script and just  
>> putting
>> all of the pieces in place to have XDoclet 1.2.3 do much of the major
>> gruntwork for the Struts-config.xml and the ejb-jar.xml and web.xml
>> also. Lots of details, but most of them are coming together now.
>>
>> But I'm stuck on the JNDI side of things, it seems. I've discovered  
>> the
>> need for specifying the jndi-name and local-jndi-name for my CMP 2  
>> EJB,
>> and my Stateless Session Bean inside of openejb-jar.xml and I've
>> confirmed that my changes are having an effect on the deployed
>> application by looking at the Debug Console and clicking on my EJBs. I
>> have also put entries in my web.xml to link them like I used to do  
>> with
>> another container I've used before. But I think maybe there's more to  
>> it
>> in Geronimo? I can't do Local JNDI lookups and instantiate my EJBs  
>> like
>> I used to be able to?
>>
>> Do I need something in the geronimo-jetty.xml deployment plan file?  
>> What
>> I have in my web.xml looks like this:
>>
>>    <ejb-local-ref >
>>       <ejb-ref-name>ejb/PhoneBookEntryLocal</ejb-ref-name>
>>       <ejb-ref-type>Entity</ejb-ref-type>
>>
>> <local-home>org.acme.phonebook.ejb.PhoneBookEntryLocalHome</local-
>> home>
>>       <local>org.acme.phonebook.ejb.PhoneBookEntryLocal</local>
>>       <ejb-link>PhoneBookEntry</ejb-link>
>>    </ejb-local-ref>
>>    <ejb-local-ref >
>>       <ejb-ref-name>ejb/PhoneBookSessionLocal</ejb-ref-name>
>>       <ejb-ref-type>Session</ejb-ref-type>
>>
>> <local-home>org.acme.phonebook.ejb.PhoneBookSessionLocalHome</local-
>> home>
>>       <local>org.acme.phonebook.ejb.PhoneBookSessionLocal</local>
>>       <ejb-link>PhoneBookSession</ejb-link>
>>    </ejb-local-ref>
>>
>> My Debug Console looks something like the following:
>>
>> JndiNames [PhoneBookEntry]
>> LocalJndiNames [org.acme.phonebook.ejb/PhoneBookEntryLocalHome]
>>
>>
>> and
>>
>> JndiNames [org.acme.phonebook.ejb/PhoneBookSession/Home]
>> LocalJndiNames [org.acme.phonebook.ejb/PhoneBookSession/LocalHome]
>>
>>
>> for each of them. Yes, I know, I make strange names for my JNDI
>> entries... but that's what XDoclet seems to do for me, and as long as  
>> I
>> can get it working, I don't care what it looks like. But, when I try  
>> the
>> following code, Geronimo does this:
>>
>>     public Collection getEntries() {
>>         try {
>>             InitialContext ctx = new InitialContext();
>>             PhoneBookSessionLocal session =
>> PhoneBookSessionUtil.getLocalHome().create();
>>             Collection c = session.listEntries();
>>             return c;
>>         } catch (Throwable ex) {
>>             System.err.println(ex);
>>             ex.printStackTrace();
>>         }
>>
>>         return new ArrayList();
>>     }
>>
>>
>> javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>> javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>>         at
>> com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
>> :95)
>>         at
>> com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
>> :103)
>>         at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>         at
>> org.acme.phonebook.ejb.PhoneBookSessionUtil.lookupHome(PhoneBookSessi
>> onUtil.java:16)
>>         at
>> org.acme.phonebook.ejb.PhoneBookSessionUtil.getLocalHome(PhoneBookSes
>> sionUtil.java:54)
>>         at  
>> org.acme.phonebook.struts.PhoneList.getEntries(PhoneList.java:51)
>>
>> XDoclet is generating the following method, which I've used for years
>> without incident:
>>
>>    public static org.acme.phonebook.ejb.PhoneBookSessionLocalHome
>> getLocalHome() throws javax.naming.NamingException
>>    {
>>       return (org.acme.phonebook.ejb.PhoneBookSessionLocalHome)
>> lookupHome(null,
>> org.acme.phonebook.ejb.PhoneBookSessionLocalHome.JNDI_NAME,
>> org.acme.phonebook.ejb.PhoneBookSessionLocalHome.class);
>>    }
>>
>>    private static Object lookupHome(java.util.Hashtable environment,
>> String jndiName, Class narrowTo) throws javax.naming.NamingException {
>>       // Obtain initial context
>>       javax.naming.InitialContext initialContext = new
>> javax.naming.InitialContext(environment);
>>       try {
>>          Object objRef = initialContext.lookup(jndiName);
>>          // only narrow if necessary
>>          if (java.rmi.Remote.class.isAssignableFrom(narrowTo))
>>             return javax.rmi.PortableRemoteObject.narrow(objRef,  
>> narrowTo);
>>          else
>>             return objRef;
>>       } finally {
>>          initialContext.close();
>>       }
>>    }
>>
>> and the constants that it's using are:
>>
>>    public static final String
>> COMP_NAME="java:comp/env/ejb/PhoneBookSessionLocal";
>>    public static final String
>> JNDI_NAME="org.acme.phonebook.ejb/PhoneBookSession/LocalHome";
>>
>>
>> I guess I'm feeling a little blind these days, since working with
>> another container I was always able to simply take a squint at the  
>> JNDI
>> tree through a nice little JMX method. Is there a similar operation I
>> can do with this Debug Console? Remember I'm using Geronimo HEAD for
>> most of this (I guess it's time for another maven m:update though).
>>
>> Thanks for any insights you can give on better using JNDI and bridging
>> the gap between the Web application and the EJB world.
>>
>> Thanks.
>>
>> -Neal
>>
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

RE: Local Session Bean lookups and JNDI

NATARAJAN Sasi Kumar
In reply to this post by Neal Sanche
Hai
                      Context ctx = getInitialContext();
                      Object obj = ctx.lookup("SampleNameJNDI");
                      home = (SampleHome)
PortableRemoteObject.narrow(obj,
                        SampleHome.class);
              remote=home.create();

<weblogic-ejb-jar>
  <weblogic-enterprise-bean>
    <ejb-name>statelessSample</ejb-name>
    <enable-call-by-reference>True</enable-call-by-reference>
    <jndi-name>SampleNameJNDI</jndi-name>
  </weblogic-enterprise-bean>
</weblogic-ejb-jar>

Cheers,
Sasikumar



-----Original Message-----
From: Neal Sanche [mailto:[hidden email]]
Sent: Friday, June 17, 2005 10:03 AM
To: [hidden email]
Subject: Re: Local Session Bean lookups and JNDI

Hi Again Aaron,

You're right, that does work, thanks. From that, I'll see if I can
figure out how to back-track and get XDoclet to generate something that
will work in this case. I think I should be able to. But I have a
fallback position anyway.

Cheers.

-Neal

Aaron Mulder wrote:

> It sounds like PhoneBookSessionUtil is trying to look up the
JNDI

>name:
>
>org.acme.phonebook.ejb/PhoneBookSession/LocalHome
>
> When really, based on the EJB ref you created, it should be
>looking up:
>
>java:comp/env/ejb/PhoneBookSessionLocal
>
> There might be another method or constant in
PhoneBookSessionUtil

>that you can use to achieve this.  Otherwise, just do this:
>
>PhoneBookSessionLocal session = ((PhoneBookSessionHome)
>     ctx.lookup("java:comp/env/ejb/PhoneBookSessionLocal")).create();
>
> If you get that working, you can forget about the jndi-name and
>local-jndi-name (they won't be necessary unless you have an application
>client).
>
>Aaron
>
>On Thu, 16 Jun 2005, Neal Sanche wrote:
>  
>
>>Hi All,
>>
>>Well, I'm working through the details for a Struts web app with an EJB

>>back end, all being compiled with a Maven build script and just
putting
>>all of the pieces in place to have XDoclet 1.2.3 do much of the major
>>gruntwork for the Struts-config.xml and the ejb-jar.xml and web.xml
>>also. Lots of details, but most of them are coming together now.
>>
>>But I'm stuck on the JNDI side of things, it seems. I've discovered
the
>>need for specifying the jndi-name and local-jndi-name for my CMP 2
EJB,
>>and my Stateless Session Bean inside of openejb-jar.xml and I've
>>confirmed that my changes are having an effect on the deployed
>>application by looking at the Debug Console and clicking on my EJBs. I

>>have also put entries in my web.xml to link them like I used to do
with
>>another container I've used before. But I think maybe there's more to
it
>>in Geronimo? I can't do Local JNDI lookups and instantiate my EJBs
like
>>I used to be able to?
>>
>>Do I need something in the geronimo-jetty.xml deployment plan file?
What

>>I have in my web.xml looks like this:
>>
>>   <ejb-local-ref >
>>      <ejb-ref-name>ejb/PhoneBookEntryLocal</ejb-ref-name>
>>      <ejb-ref-type>Entity</ejb-ref-type>
>>      
>><local-home>org.acme.phonebook.ejb.PhoneBookEntryLocalHome</local-home
>
>>      <local>org.acme.phonebook.ejb.PhoneBookEntryLocal</local>
>>      <ejb-link>PhoneBookEntry</ejb-link>
>>   </ejb-local-ref>
>>   <ejb-local-ref >
>>      <ejb-ref-name>ejb/PhoneBookSessionLocal</ejb-ref-name>
>>      <ejb-ref-type>Session</ejb-ref-type>
>>      
>><local-home>org.acme.phonebook.ejb.PhoneBookSessionLocalHome</local-ho
me>

>>      <local>org.acme.phonebook.ejb.PhoneBookSessionLocal</local>
>>      <ejb-link>PhoneBookSession</ejb-link>
>>   </ejb-local-ref>
>>
>>My Debug Console looks something like the following:
>>
>>JndiNames [PhoneBookEntry]
>>LocalJndiNames [org.acme.phonebook.ejb/PhoneBookEntryLocalHome]
>>
>>
>>and
>>
>>JndiNames [org.acme.phonebook.ejb/PhoneBookSession/Home]
>>LocalJndiNames
[org.acme.phonebook.ejb/PhoneBookSession/LocalHome]
>>
>>
>>for each of them. Yes, I know, I make strange names for my JNDI
>>entries... but that's what XDoclet seems to do for me, and as long as
I
>>can get it working, I don't care what it looks like. But, when I try
the

>>following code, Geronimo does this:
>>
>>    public Collection getEntries() {
>>        try {
>>            InitialContext ctx = new InitialContext();
>>            PhoneBookSessionLocal session =
>>PhoneBookSessionUtil.getLocalHome().create();
>>            Collection c = session.listEntries();
>>            return c;
>>        } catch (Throwable ex) {
>>            System.err.println(ex);
>>            ex.printStackTrace();
>>        }
>>      
>>        return new ArrayList();
>>    }
>>
>>
>>javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>>javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>>        at
>>com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
>>:95)
>>        at
>>com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
>>:103)
>>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>        at
>>org.acme.phonebook.ejb.PhoneBookSessionUtil.lookupHome(PhoneBookSessi
>>onUtil.java:16)
>>        at
>>org.acme.phonebook.ejb.PhoneBookSessionUtil.getLocalHome(PhoneBookSes
>>sionUtil.java:54)
>>        at
org.acme.phonebook.struts.PhoneList.getEntries(PhoneList.java:51)

>>
>>XDoclet is generating the following method, which I've used for years
>>without incident:
>>
>>   public static org.acme.phonebook.ejb.PhoneBookSessionLocalHome
>>getLocalHome() throws javax.naming.NamingException
>>   {
>>      return (org.acme.phonebook.ejb.PhoneBookSessionLocalHome)
>>lookupHome(null,
>>org.acme.phonebook.ejb.PhoneBookSessionLocalHome.JNDI_NAME,
>>org.acme.phonebook.ejb.PhoneBookSessionLocalHome.class);
>>   }
>>
>>   private static Object lookupHome(java.util.Hashtable environment,
>>String jndiName, Class narrowTo) throws javax.naming.NamingException {
>>      // Obtain initial context
>>      javax.naming.InitialContext initialContext = new
>>javax.naming.InitialContext(environment);
>>      try {
>>         Object objRef = initialContext.lookup(jndiName);
>>         // only narrow if necessary
>>         if (java.rmi.Remote.class.isAssignableFrom(narrowTo))
>>            return javax.rmi.PortableRemoteObject.narrow(objRef,
narrowTo);

>>         else
>>            return objRef;
>>      } finally {
>>         initialContext.close();
>>      }
>>   }
>>
>>and the constants that it's using are:
>>
>>   public static final String
>>COMP_NAME="java:comp/env/ejb/PhoneBookSessionLocal";
>>   public static final String
>>JNDI_NAME="org.acme.phonebook.ejb/PhoneBookSession/LocalHome";
>>
>>
>>I guess I'm feeling a little blind these days, since working with
>>another container I was always able to simply take a squint at the
JNDI
>>tree through a nice little JMX method. Is there a similar operation I
>>can do with this Debug Console? Remember I'm using Geronimo HEAD for
>>most of this (I guess it's time for another maven m:update though).
>>
>>Thanks for any insights you can give on better using JNDI and bridging

>>the gap between the Web application and the EJB world.
>>
>>Thanks.
>>
>>-Neal
>>
>>
>>
>>    
>>

Confidentiality Statement:

This message is intended only for the individual or entity to which it is addressed. It may contain privileged, confidential information which is exempt from disclosure under applicable laws. If you are not the intended recipient, please note that you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information. If you have received this communication in error, please notify us immediately by return email.

Reply | Threaded
Open this post in threaded view
|

Re: Local Session Bean lookups and JNDI

David Jencks
While we might at some future time support deploying portable apps  
using a weblogic plan, I would not be in favor of supporting  
non-compliant jndi access outside of  java:comp/.  We certainly don't  
support it now.

thanks
david jencks

On Jun 17, 2005, at 12:49 AM, NATARAJAN Sasi Kumar wrote:

> Hai
>      Context ctx = getInitialContext();
>      Object obj = ctx.lookup("SampleNameJNDI");
>      home = (SampleHome)
> PortableRemoteObject.narrow(obj,
>        SampleHome.class);
>               remote=home.create();
>
> <weblogic-ejb-jar>
>   <weblogic-enterprise-bean>
>     <ejb-name>statelessSample</ejb-name>
>     <enable-call-by-reference>True</enable-call-by-reference>
>     <jndi-name>SampleNameJNDI</jndi-name>
>   </weblogic-enterprise-bean>
> </weblogic-ejb-jar>
>
> Cheers,
> Sasikumar
>
>
>
> -----Original Message-----
> From: Neal Sanche [mailto:[hidden email]]
> Sent: Friday, June 17, 2005 10:03 AM
> To: [hidden email]
> Subject: Re: Local Session Bean lookups and JNDI
>
> Hi Again Aaron,
>
> You're right, that does work, thanks. From that, I'll see if I can
> figure out how to back-track and get XDoclet to generate something that
> will work in this case. I think I should be able to. But I have a
> fallback position anyway.
>
> Cheers.
>
> -Neal
>
> Aaron Mulder wrote:
>
>> It sounds like PhoneBookSessionUtil is trying to look up the
> JNDI
>> name:
>>
>> org.acme.phonebook.ejb/PhoneBookSession/LocalHome
>>
>> When really, based on the EJB ref you created, it should be
>> looking up:
>>
>> java:comp/env/ejb/PhoneBookSessionLocal
>>
>> There might be another method or constant in
> PhoneBookSessionUtil
>> that you can use to achieve this.  Otherwise, just do this:
>>
>> PhoneBookSessionLocal session = ((PhoneBookSessionHome)
>>     ctx.lookup("java:comp/env/ejb/PhoneBookSessionLocal")).create();
>>
>> If you get that working, you can forget about the jndi-name and
>> local-jndi-name (they won't be necessary unless you have an  
>> application
>> client).
>>
>> Aaron
>>
>> On Thu, 16 Jun 2005, Neal Sanche wrote:
>>
>>
>>> Hi All,
>>>
>>> Well, I'm working through the details for a Struts web app with an  
>>> EJB
>
>>> back end, all being compiled with a Maven build script and just
> putting
>>> all of the pieces in place to have XDoclet 1.2.3 do much of the major
>>> gruntwork for the Struts-config.xml and the ejb-jar.xml and web.xml
>>> also. Lots of details, but most of them are coming together now.
>>>
>>> But I'm stuck on the JNDI side of things, it seems. I've discovered
> the
>>> need for specifying the jndi-name and local-jndi-name for my CMP 2
> EJB,
>>> and my Stateless Session Bean inside of openejb-jar.xml and I've
>>> confirmed that my changes are having an effect on the deployed
>>> application by looking at the Debug Console and clicking on my EJBs.  
>>> I
>
>>> have also put entries in my web.xml to link them like I used to do
> with
>>> another container I've used before. But I think maybe there's more to
> it
>>> in Geronimo? I can't do Local JNDI lookups and instantiate my EJBs
> like
>>> I used to be able to?
>>>
>>> Do I need something in the geronimo-jetty.xml deployment plan file?
> What
>>> I have in my web.xml looks like this:
>>>
>>>   <ejb-local-ref >
>>>      <ejb-ref-name>ejb/PhoneBookEntryLocal</ejb-ref-name>
>>>      <ejb-ref-type>Entity</ejb-ref-type>
>>>
>>> <local-home>org.acme.phonebook.ejb.PhoneBookEntryLocalHome</local-
>>> home
>>
>>>      <local>org.acme.phonebook.ejb.PhoneBookEntryLocal</local>
>>>      <ejb-link>PhoneBookEntry</ejb-link>
>>>   </ejb-local-ref>
>>>   <ejb-local-ref >
>>>      <ejb-ref-name>ejb/PhoneBookSessionLocal</ejb-ref-name>
>>>      <ejb-ref-type>Session</ejb-ref-type>
>>>
>>> <local-home>org.acme.phonebook.ejb.PhoneBookSessionLocalHome</local-
>>> ho
> me>
>>>      <local>org.acme.phonebook.ejb.PhoneBookSessionLocal</local>
>>>      <ejb-link>PhoneBookSession</ejb-link>
>>>   </ejb-local-ref>
>>>
>>> My Debug Console looks something like the following:
>>>
>>> JndiNames [PhoneBookEntry]
>>> LocalJndiNames [org.acme.phonebook.ejb/PhoneBookEntryLocalHome]
>>>
>>>
>>> and
>>>
>>> JndiNames [org.acme.phonebook.ejb/PhoneBookSession/Home]
>>> LocalJndiNames
> [org.acme.phonebook.ejb/PhoneBookSession/LocalHome]
>>>
>>>
>>> for each of them. Yes, I know, I make strange names for my JNDI
>>> entries... but that's what XDoclet seems to do for me, and as long as
> I
>>> can get it working, I don't care what it looks like. But, when I try
> the
>>> following code, Geronimo does this:
>>>
>>>    public Collection getEntries() {
>>>        try {
>>>            InitialContext ctx = new InitialContext();
>>>            PhoneBookSessionLocal session =
>>> PhoneBookSessionUtil.getLocalHome().create();
>>>            Collection c = session.listEntries();
>>>            return c;
>>>        } catch (Throwable ex) {
>>>            System.err.println(ex);
>>>            ex.printStackTrace();
>>>        }
>>>
>>>        return new ArrayList();
>>>    }
>>>
>>>
>>> javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>>> javax.naming.NameNotFoundException: org.acme.phonebook.ejb
>>>        at
>>> com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
>>> :95)
>>>        at
>>> com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java
>>> :103)
>>>        at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>>        at
>>> org.acme.phonebook.ejb.PhoneBookSessionUtil.lookupHome(PhoneBookSessi
>>> onUtil.java:16)
>>>        at
>>> org.acme.phonebook.ejb.PhoneBookSessionUtil.getLocalHome(PhoneBookSes
>>> sionUtil.java:54)
>>>        at
> org.acme.phonebook.struts.PhoneList.getEntries(PhoneList.java:51)
>>>
>>> XDoclet is generating the following method, which I've used for years
>>> without incident:
>>>
>>>   public static org.acme.phonebook.ejb.PhoneBookSessionLocalHome
>>> getLocalHome() throws javax.naming.NamingException
>>>   {
>>>      return (org.acme.phonebook.ejb.PhoneBookSessionLocalHome)
>>> lookupHome(null,
>>> org.acme.phonebook.ejb.PhoneBookSessionLocalHome.JNDI_NAME,
>>> org.acme.phonebook.ejb.PhoneBookSessionLocalHome.class);
>>>   }
>>>
>>>   private static Object lookupHome(java.util.Hashtable environment,
>>> String jndiName, Class narrowTo) throws javax.naming.NamingException  
>>> {
>>>      // Obtain initial context
>>>      javax.naming.InitialContext initialContext = new
>>> javax.naming.InitialContext(environment);
>>>      try {
>>>         Object objRef = initialContext.lookup(jndiName);
>>>         // only narrow if necessary
>>>         if (java.rmi.Remote.class.isAssignableFrom(narrowTo))
>>>            return javax.rmi.PortableRemoteObject.narrow(objRef,
> narrowTo);
>>>         else
>>>            return objRef;
>>>      } finally {
>>>         initialContext.close();
>>>      }
>>>   }
>>>
>>> and the constants that it's using are:
>>>
>>>   public static final String
>>> COMP_NAME="java:comp/env/ejb/PhoneBookSessionLocal";
>>>   public static final String
>>> JNDI_NAME="org.acme.phonebook.ejb/PhoneBookSession/LocalHome";
>>>
>>>
>>> I guess I'm feeling a little blind these days, since working with
>>> another container I was always able to simply take a squint at the
> JNDI
>>> tree through a nice little JMX method. Is there a similar operation I
>>> can do with this Debug Console? Remember I'm using Geronimo HEAD for
>>> most of this (I guess it's time for another maven m:update though).
>>>
>>> Thanks for any insights you can give on better using JNDI and  
>>> bridging
>
>>> the gap between the Web application and the EJB world.
>>>
>>> Thanks.
>>>
>>> -Neal
>>>
>>>
>>>
>>>
>>>
>
> Confidentiality Statement:
>
> This message is intended only for the individual or entity to which it  
> is addressed. It may contain privileged, confidential information  
> which is exempt from disclosure under applicable laws. If you are not  
> the intended recipient, please note that you are strictly prohibited  
> from disseminating or distributing this information (other than to the  
> intended recipient) or copying this information. If you have received  
> this communication in error, please notify us immediately by return  
> email.
>

Reply | Threaded
Open this post in threaded view
|

Re: Local Session Bean lookups and JNDI

ammulder
On Fri, 17 Jun 2005, David Jencks wrote:
> ...
> I would not be in favor of supporting non-compliant jndi access outside
> of java:comp/.  We certainly don't support it now.

        Don't we?  If you give your EJB a jndi-name or a local-jndi-name,
it goes into the "global JNDI tree" right?  I thought server side code
could access it directly there, as an "available-but-not-recommended"
option.  I guess I ought to try it and see.  :)

Aaron
Reply | Threaded
Open this post in threaded view
|

Re: Local Session Bean lookups and JNDI

Dain Sundstrom
On Jun 17, 2005, at 4:41 AM, Aaron Mulder wrote:

> On Fri, 17 Jun 2005, David Jencks wrote:
>
>> ...
>> I would not be in favor of supporting non-compliant jndi access  
>> outside
>> of java:comp/.  We certainly don't support it now.
>>
>
>     Don't we?  If you give your EJB a jndi-name or a local-jndi-name,
> it goes into the "global JNDI tree" right?  I thought server side code
> could access it directly there, as an "available-but-not-recommended"
> option.  I guess I ought to try it and see.  :)

I thought we did also.  I think we have offer this feature, since  
every other J2EE server seems to support it.  If we didn't there  
would be a lot of apps that would need a rewrite.

-dain