6 Replies Latest reply on Dec 17, 2005 9:49 PM by philc_jboss

    I know, another JNDI lookup issue - local ejb

    philc_jboss

      Wow, I have spent hours searching and reading a dozen other posts like my issue but no resolution. I did not want to ask/post since versions of this issue have been asked before, but again I have tried many many variations and have yet to communicate with my local EJB object (public interface MyBeanLocal extends EJBLocalObject).

      using jboss-4.0.3SP1 and bundled Tomcat

      The error gets thrown at context lookup call.

      error:
      javax.naming.NameNotFoundException: MyBeanLocal not bound

      calling code:

      ...
       Properties props = null;
       MyBeanLocal local = null;
       Object ref = null;
       try
       {
       props = new Properties();
       props.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
       props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interface");
       props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
       // I have tried "localhost:1099", 127.0.0.1, etc as well
      
       Context ctx = new InitialContext(props);
       // *never makes it here, exception NameNotFoundException*
      
       //Object ref = ctx.lookup("MyBeanLocal");
       MyBeanLocalHome home = (MyBeanLocalHome)ctx.lookup("MyBeanLocal");
       local = home.create();
       }
       catch(Exception e)
       {
       logger.error(e.toString());
       }


      ejb-jar.xml:
      ...
       <session>
       <display-name>MyBeanLocal</display-name>
       <ejb-name>MyBeanLocal</ejb-name>
       <local-home>org.ejb.MyBeanLocalHome</local-home>
       <local>org.ejb.MyBeanLocal</local>
       <ejb-class>org.ejb.MyBeanLocalEJB</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
       </session>
      ...
      


      jboss.xml:
      ...
      <enterprise-beans>
       <session>
       <ejb-name>MyBeanLocal</ejb-name>
       <jndi-name>MyBeanLocal</jndi-name>
       </session>
       <secure>false</secure>
      </enterprise-beans>
      ...
      


      jmx-console
      service=JNDIView:
      +- local (class: org.jnp.interfaces.NamingContext)
      | +- MyBeanLocal@800877 (proxy: $Proxy149 implements interface org.ejb.MyBeanLocalHome)

      Any assistance/information is greatly appreciated.

        • 1. Re: I know, another JNDI lookup issue - local ejb
          philc_jboss

          Ok so I finally stumbled across a Wiki entry (still no luck):

          >>>>>>
          Why do I get NameNotFoundException??

          By default JBoss binds ConnectionFactorys/DataSources in the java: namespace. This is only visible inside the same virtual machine and only when using a naming context that is not configured to use a transport.

          Mistake 1 - Not using the java: namespace

          <local-tx-datasource>
          <jndi-name>GenericDS</jndi-name>
          <connection-url>[jdbc: url for use with Driver class]</connection-url>
          <driver-class>[fully qualified class name of java.sql.Driver implementation]</driver-class>
          <user-name>x</user-name>
          y
          </local-tx-datasource>

          WRONG!

          new InitialContext().lookup("GenericDS");

          CORRECT

          new InitialContext().lookup("java:/GenericDS");

          Mistake 2 - Going over a transport

          By using a provider url, you are effectively make your jndi access remote, meaning the java: namespace is not visible.

          Properties props = new Properties();
          ...
          props.put(javax.naming.Context.PROVIDER_URL,"jnp://localhost:1099");
          IntialContext context = new InitialContext(props)
          <<<<<<<<<

          I updated my code to not make mistake 2 (props provider url), and used the "correct" example in mistake 1 - still no luck. This is driving me crazy.

          Please if anyone has overcome the same type of issue please let me know. Thanks.

          • 2. Re: I know, another JNDI lookup issue - local ejb
            philc_jboss

            Ok, I can't imagine there is not an answer to this issue (nobody else has experienced this issue). I guess this is seen as a newbie/configuration addressed in configuration documents that I overlooked. Either way I will continue to try to get this working somehow otherwise I will have to switch back to my previous app server - I was hoping to be able to use JBoss.

            • 3. Re: I know, another JNDI lookup issue - local ejb
              lepe

              Are you doing the lookup inside the JBoss JVM?

              In that case:

              1. Use the in JBoss already existent jndi.properties (dont edit it!) and just do a new InitialContext()

              2. Do the lookup like in your first post - that is dont use the java:/ namespace.

              /L

              • 4. Re: I know, another JNDI lookup issue - local ejb
                philc_jboss

                Reviewing my initial post, I see with the calling code I did not mention that I was calling from a struts action / servlet (Tomcat bundled with JBoss). I know that Tomcat has its' own JNDI Server and from what I read I have to make a global reference.

                I am using the default jndi.properties in my classpath:
                ### JBossNS properties
                java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
                java.naming.provider.url=jnp://localhost:1099
                java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

                Thanks for your reply, I am so frustrated I am sure I have overlooked something (otherwise I would not be having this issue). Discovering resolution is becomming a personal quest. Thanks again.
                -Phil

                • 5. Re: I know, another JNDI lookup issue - local ejb
                  jaikiran

                   

                  "philc_jboss" wrote:

                  jmx-console
                  service=JNDIView:
                  +- local (class: org.jnp.interfaces.NamingContext)
                  | +- MyBeanLocal@800877 (proxy: $Proxy149 implements interface org.ejb.MyBeanLocalHome)



                  This i think should just be MyBeanLocal and NOT MyBeanLocal@800877. I had seen a similar issue being reported in the forums. Currently i am not able to locate the same(I guess it was in EJB/JBOSS forum).

                  • 6. Re: I know, another JNDI lookup issue - local ejb
                    philc_jboss

                    Thanks for your reply jaikiran!! You were correct. I searched for some time through EJB/JBOSS and found another related post. I changed my jboss.xml <jndi-name/> tag to <local-jndi-name/> and a couple other changes and finally got my deployment working :). I still have a class loader issue that I will continue to work with (many people have the same issue and have to set a global flag to "true"), but I don't have other context apps so this is fine for now. Thanks to your reply I was able to head down a path to resolution.
                    Now my jmx-console show the bean deployment as:

                    Global JNDI Namespace

                    +- MyBeanLocalHome (proxy: $Proxy100 implements interface org.blah.ejb.MyBeanLocalHome)