1 2 Previous Next 26 Replies Latest reply on Mar 15, 2012 4:55 PM by thinksteep Go to original post Branched from an earlier discussion.
      • 15. Re: NameNotFoundException for remote EJB lookup in AS7
        thinksteep

        Hi Jaikiran and Community,

         

        Can we see these binded beans some where in console?  When I navigate to

         

        Console-->

                  Container-->

                                 Naming-->

                                                java:global--->

        I have only

         

                                                          Nameyyyy-->

                                                                  -     yyybusiness

         

        None of Beans showing up here. Should we see all binded beans here? If so, any reason why I am not seeing them here?

         

        Please help. Thank you!

        • 16. Re: NameNotFoundException for remote EJB lookup in AS7
          prasad.deshpande

           

              private Context getInitialContext() throws NamingException {

                  System.out.println("Inside config delegate getInitialContext method");

                  Properties props = new Properties();

                  props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");

                 // props.put(Context.PROVIDER_URL, "jnp://localhost:1099");

                  Context ctx = new InitialContext(props);

                  return ctx;

              }

           

          If you are looking-up from same ear in same JVM, you don't even need to add INTIAL_CONTEXT_FACTORY, you can simply create Context ctx = new InitialContext(); & do a lookup

           

          you'd only need to add all that above code only if you want to lookup from remote JVM (either another instance of jboss or remote client). Within same ear you can simply create InitialContext as I described above & you should find name.

          • 17. Re: NameNotFoundException for remote EJB lookup in AS7
            prasad.deshpande

            public ConfigRemote getConfigRemote() {

                    try {

                        Context initialContext = getInitialContext();

                        Object ref = initialContext.lookup("java:global/app name/modulename/ConfigBean!org.myapp.beans.admin.config.ConfigRemote");

                        return (ConfigRemote) ref;

                    } catch (Exception e) {

                        System.out.println(e);

                        return null;

                    }

             

                }

            I just noticed you have a space " " character in your name, is it a typo mistake or you really have that in your application (.ear) name? If so, that could be a problem... I'm not really sure whether space characters are permitted in naming.. I never came accross any such example before..

             

            Also, you can try this.. from any class in same ear & see if you can get this...

             

             

            public ConfigRemote getConfigRemote() {

                    try {

                        Context initialContext = new InitialContext();

                        Object ref = initialContext.lookup("java:global/app name/modulename/ConfigBean!org.myapp.beans.admin.config.ConfigRemote");

                        return (ConfigRemote) ref;

                    } catch (Exception e) {

                        System.out.println(e);

                        return null;

                    }

             

                }

             

             

            Edited by Jaikiran Pai to remove references to company name(s)

            • 18. Re: NameNotFoundException for remote EJB lookup in AS7
              thinksteep

              Hi Prasad,

               

              Thanks for your reply!

               

              Space character is not typo, it is application name in application.xml. I read in documentation that if application name defined in application.xml, it takes precedence over EAR name. So, having space there is not typo and it is allowed as per spec.

               

              I thought same that space might be causing issue, changed application.xml, removed space there. Still same issue. (I forgot to replace organization name, could you please edit your post and replace with following string? that saves my job)

               

              java:global/Name yyy/yyybusiness/ConfigBean!com.name.yyy.beans.admin.config.ConfigRemote

               

              I am going to try your suggestion (new InitialContext()) as soon as login to work.

               

              Please Please Please edit your post and replace the string for my sake.

               

              Thank you,

               

               

               

              • 19. Re: NameNotFoundException for remote EJB lookup in AS7
                jaikiran

                thinksteep thinksteep wrote:

                 

                 

                Please Please Please edit your post and replace the string for my sake.

                 

                  

                Done.

                • 20. Re: NameNotFoundException for remote EJB lookup in AS7
                  thinksteep

                  Hi Prasad/Jaikiran,

                   

                  Thanks for edit!

                   

                  I just changed my code to use new InitialContext() still no luck, same NameNotFoundException for both global space and app space JNDI. Any other inputs? This is really killing me. It seems overcome all other issues in upgrade except this.

                   

                  I am having other thought that it could be due to new class loading mechanism. Actual beans are in yyybusiness.jar (which is part of EAR) and the client (delegate) is in another jar which is placed inside EAR--->Lib folder. Could it be due to new classloading mechanism, two classloaders loading them and they are not visible for each other? How can make sure this is not the case? Please suggest.

                   

                  Thank you,

                  • 21. Re: NameNotFoundException for remote EJB lookup in AS7
                    prasad.deshpande

                    Do you have jndi.properties somewhere in your server classpath by any chance? Otherwise I can't think of any probability on the top of my head.. Is it possible for you to create a sample ear that reproduces this issue & attach to this post which I can take a look at myself?

                    • 22. Re: NameNotFoundException for remote EJB lookup in AS7
                      thinksteep

                      Hi Prasad,

                       

                      Thanks for your reply!

                       

                      I updated my previous post with some more thoughts. Could you valid any of those make sense? It is big project. Let me see if can create a sample ear with components for this. I am positive that no other JNDI prop files in classpath, let me make sure one more time.

                       

                      Thank you,

                      • 23. Re: NameNotFoundException for remote EJB lookup in AS7
                        prasad.deshpande

                        I am having other thought that it could be due to new class loading mechanism. Actual beans are in yyybusiness.jar (which is part of EAR) and the client (delegate) is in another jar which is placed inside EAR--->Lib folder. Could it be due to new classloading mechanism, two classloaders loading them and they are not visible for each other? How can make sure this is not the case? Please suggest.

                        As long as they both (Bean & the java class from where you are looking up) are in same VM & bound to JNDI, java:global should always find it.. I don't see classloading has anything to do with NameNotFound exception.. obvious doubt goes over InitialContext..

                         

                        I'd suggest try creating a sample helloworld ear that has same structure like your main application & try if you get the same error with that too (which you shouldn't)..

                        • 24. Re: NameNotFoundException for remote EJB lookup in AS7
                          thinksteep

                          Hi Prasad and community,

                           

                          After one and half day long trail and errors I figured that "initialize-in-order" in application.xml with combination of load-on-startup in web.xml and ejb lookup in init() method of servlet causing this issue.

                           

                          With same combination if we do lookup in service method of servlet, it is working fine.

                           

                          As far as I remember Jboss7.1 recommonding "initialize-in-order" tag in applicaiton.xml. We need to do some stuff in init() method while servlet loading, so we need ejb lookup in servlet init() method. Is there any work around for this issue? Please guide us.

                           

                          For your refernce I am adding sample EAR file and source.

                           

                          Thanks for your time and help.

                          • 25. Re: NameNotFoundException for remote EJB lookup in AS7
                            prasad.deshpande

                            If I understand your post above, you want ejb's to be deployed before init() of servlet gets called..

                             

                            logically if you inject an EJB in servlet (as a member variable), then that means your EJB module needs to be deployed before WAR module.. so if you have

                             

                            public class TestServlet extends HttpServlet {

                             

                                @EJB private CallerRemote remote;

                             

                                public void init() {

                                       System.out.println("caller.CallerLocal local = " + remote);

                                       System.out.println("\n\n");

                                        System.out.println("local.testMethod() = " + remote.testMethod("Test"));

                                    } catch (Exception e) {

                                        e.printStackTrace();

                                    }    

                                }

                            }

                            that should work even without initialize-in-order (haven't tried your ear yet..)..

                            • 26. Re: NameNotFoundException for remote EJB lookup in AS7
                              thinksteep

                              Hi Prasad,

                               

                              Thanks for your prompt responses and help on this thread.

                               

                              When we look at server.log, it is indeed showing as ejbs are deployed and binded to namespace before servlet init being called (the order of logging in server.log). That is where I am confused, doesn't that mean ejbs deployed? Am I missing something?

                               

                              Thank you,

                              1 2 Previous Next