1 2 Previous Next 15 Replies Latest reply on Jan 17, 2008 3:19 AM by yanlong11

    can not lookup session bean under Jboss 4.2.2GA and ejb3 (Na

    yanlong11

      Hi

      I have troubles getting ejb3 to work under jboss 4.2.2GA and intellij idea as IDE.

      my application (simple ejb3 example) is successfully deployed, I can see jsp page and open it (no other things in project) but I can never do lookup on my session bean to get some info from bean to jsp page. I always get NameNotboundException with description, that my bean is not bound.

      I have tried several options mentioned in this forum, but never succeeded and I remember, that I had similar problems also some 1 year ago, while playing around.

      thanks

      yanlong

        • 1. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
          jaikiran

          You should have posted the exception stacktrace that you are seeing. That will help in identifying the exact issue.
          Most likely you are looking up the bean using a wrong jndi-name. You will have to look at the JNDIView through your jmx-console to see what exactly is the jndi-name of your bean. I can explain the steps here, but right now i am lazy to write down the steps to debug the NameNotFoundException. You can go through http://jaitechwriteups.blogspot.com/2007/10/why-do-i-get-namenotfoundexception.html and see if it helps.

          • 2. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
            yanlong11

            Hi

            thanks for your quick response.

            actually I have already managed, somehow to get part of this work, unfortunately another error came up.

            removing remotebinding gives same error
            package beans;

            import javax.ejb.Stateless;
            import javax.ejb.Remote;

            import org.jboss.annotation.ejb.RemoteBinding;

            @Stateless(name = "testBean")
            @Remote(test.class)
            @RemoteBinding(jndiBinding="testBean")
            public class testBean {
            public testBean() {
            }

            public String hello() {
            return "Hello from bean";
            }
            }

            this is my bean, test.java is just interface with one method.

            Context ctx = new InitialContext();
            try {
            Object obj = ctx.lookup("testBean");
            testBean bean = (testBean)obj;
            out.print(bean.hello());
            } catch (Exception e) {
            e.printStackTrace();
            }

            above is code from jsp, that is throwing ClassCast exception and now I really have no idea why.

            as for JNDIView, I have there following line for my bean:
            +- testBean (proxy: $Proxy96 implements interface beans.test,interface org.jboss.ejb3.JBossProxy)

            after removing binding, jndi view gives following:
            +- testBean (class: org.jnp.interfaces.NamingContext)
            | +- remote (proxy: $Proxy129 implements interface beans.test,interface org.jboss.ejb3.JBossProxy)


            how should I call hello() from jsp? where am I making mistake? and where can I learm something more from

            thanks a lot for your help.


            • 3. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
              jaikiran

               

              "yanlong11" wrote:

              after removing binding, jndi view gives following:
              +- testBean (class: org.jnp.interfaces.NamingContext)
              | +- remote (proxy: $Proxy129 implements interface beans.test,interface org.jboss.ejb3.JBossProxy)



              If you have removed the @RemoteBinding annotation from your code and this is what the JNDIView shows, then use the following lookup string in your jsp:

              Object obj = ctx.lookup("testBean/remote");
              testBean bean = (testBean)obj;
              out.print(bean.hello());


              • 4. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                yanlong11

                Hi

                trouble is now not Naming, but ClassCastException! it was great hint I have not known, about looking at JNDI console to see real namings.

                testBean bean = (testBean)obj; // this line always fails and causes exception

                any idea about this?

                thanks a lot

                yanlong

                • 5. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3

                  Hi yanlong11,

                  with coding

                  @Remote(test.class)
                  


                  you say, that the remote interface/type should be test.
                  So you need to

                  test bean = (test)obj;
                  


                  in you client.

                  • 6. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                    yanlong11

                    but test.java is

                    public interface test {
                     public String hello();
                    }
                    


                    does that mean, that I have to rewrite code differently?

                    thanks


                    • 7. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                      wolfgangknauf

                      Hi !

                      first of all: I would suggest you annotate the remote interface "test" with "@Remote()", not the bean.

                      next: let the bean class implement the interface.

                      third: I think you cannot cast the lookup result directly to the bean interface.
                      I always used this:

                      InitialContext initialContext = new InitialContext(properties);
                      Object objRemote = initialContext.lookup("testBean/remote");
                      Test testRemote = (Test) PortableRemoteObject.narrow(objRemote, Test.class);


                      Hope this helps

                      Wolfgang

                      • 8. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                        yanlong11

                        :( I must be doing something wrong.

                        I even made very base interface (Calculator.java) like in the example but I am always getting the same error. Class Cast Exception.


                        please give me a hint what I am doing wrong. below all important code. (I had rather included it.)

                        thanks in advance

                        //baseBean.java
                        package beans;

                        public interface baseBean {
                        public String hello();
                        }

                        //baseRemote.java
                        package beans;

                        import javax.ejb.Remote;
                        @Remote
                        public interface baseRemote extends baseBean{
                        //public String hello();
                        }

                        //testBean
                        package beans;
                        import javax.ejb.Stateless;
                        @Stateless(name = "testBean")
                        public class testBean implements baseRemote {
                        public testBean() {
                        }

                        public String hello() {
                        return "Hello from bean";
                        }
                        }

                        //index.jsp

                        <%
                        InitialContext ctx = new InitialContext();
                        try {
                        Object obj = ctx.lookup("testBean/remote");
                        //baseRemote testRemote = (baseRemote) PortableRemoteObject.narrow(obj, baseRemote.class);
                        baseBean bean = (baseBean)obj;
                        out.print(bean.hello());
                        //out.print(testRemote.hello());
                        } catch (Exception e) {
                        e.printStackTrace();
                        }
                        %>

                        • 9. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                          jaikiran

                          yanlong11,

                          There are various reasons why a ClassCastException error will occur. Please post the entire exception stacktrace and also the contents of the JNDI tree.

                          • 10. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                            yanlong11

                            16:53:10,284 ERROR [STDERR] java.lang.ClassCastException: $Proxy91
                            16:53:10,284 ERROR [STDERR] at org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
                            16:53:10,284 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
                            16:53:10,284 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                            16:53:10,284 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
                            16:53:10,284 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
                            16:53:10,284 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
                            16:53:10,284 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                            16:53:10,284 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                            16:53:10,284 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                            16:53:10,284 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                            16:53:10,284 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                            16:53:10,284 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                            16:53:10,294 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                            16:53:10,294 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                            16:53:10,294 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                            16:53:10,294 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                            16:53:10,294 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)

                            +- testBean (class: org.jnp.interfaces.NamingContext)
                            | +- remote (proxy: $Proxy88 implements interface beans.baseRemote,interface org.jboss.ejb3.JBossProxy)
                            +- invokers (class: org.jnp.interfaces.NamingContext)
                            | +- mdudra (class: org.jnp.interfaces.NamingContext)
                            | | +- iiop (class: org.jboss.invocation.iiop.IIOPInvoker)
                            +- TransactionSynchronizationRegistry (class:
                            +- HelloBean (class: org.jnp.interfaces.NamingContext)
                            | +- remote (proxy: $Proxy91 implements interface book.Hello,interface org.jboss.ejb3.JBossProxy)

                            I have added new bean from "mastering ejb3" (Hello bean) but stack-trace was always the same.

                            thank you for your help.

                            yanlong

                            • 11. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                              jaikiran

                              Going by this JNDI tree, your code should be:

                              Hello bean = (Hello) ctx.lookup("HelloBean/remote");
                              bean.hello();


                              Now if this fails with a ClassCastException : $ProxyXX then you will have to tell us how you have packaged your application. Are you deploying the ejbs in a jar and the jsp in a separate war? If yes, then do you have the bean interface (book.Hello) in both the war and the jar?

                              Also, have a look at http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassCastExceptions, specifically the jmx-console approach mentioned over there.

                              • 12. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                                yanlong11

                                I still had class-cast exc even with code you provided.

                                below output from loader-rep as suggested in article you gave link to.

                                I am loading these dynamically with intellij idea IDE

                                thanks

                                yanlong

                                book.HelloBean Information
                                Repository cache version:
                                book.HelloBean(11be075).ClassLoader=org.jboss.mx.loading.UnifiedClassLoader3@1683e80{ url=file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar ,addedOrder=49}
                                ..org.jboss.mx.loading.UnifiedClassLoader3@1683e80{ url=file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar ,addedOrder=49}
                                ....file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar
                                ..org.jboss.system.server.NoAnnotationURLClassLoader@1de3f2d
                                ..sun.misc.Launcher$AppClassLoader@a39137
                                ....file:/C:/Sun/AppServer/jdk/lib/tools.jar
                                ....file:/D:/devel/java/jboss-4.2.2.GA/bin/run.jar
                                ..sun.misc.Launcher$ExtClassLoader@92e78c
                                ....file:/C:/Sun/AppServer/jdk/jre/lib/ext/dnsns.jar
                                ....file:/C:/Sun/AppServer/jdk/jre/lib/ext/localedata.jar
                                ....file:/C:/Sun/AppServer/jdk/jre/lib/ext/sunjce_provider.jar
                                ....file:/C:/Sun/AppServer/jdk/jre/lib/ext/sunpkcs11.jar
                                ++++CodeSource: (file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar )
                                Implemented Interfaces:
                                ++interface book.Hello(1f20541)
                                ++++ClassLoader: org.jboss.mx.loading.UnifiedClassLoader3@1683e80{ url=file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar ,addedOrder=49}
                                ++++CodeSource: (file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar )

                                ### Instance0 found in UCL: org.jboss.mx.loading.UnifiedClassLoader3@1683e80{ url=file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar ,addedOrder=49}




                                book.Hello Information
                                Repository cache version:
                                book.Hello(1f20541).ClassLoader=org.jboss.mx.loading.UnifiedClassLoader3@1683e80{ url=file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar ,addedOrder=49}
                                ..org.jboss.mx.loading.UnifiedClassLoader3@1683e80{ url=file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar ,addedOrder=49}
                                ....file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar
                                ..org.jboss.system.server.NoAnnotationURLClassLoader@1de3f2d
                                ..sun.misc.Launcher$AppClassLoader@a39137
                                ....file:/C:/Sun/AppServer/jdk/lib/tools.jar
                                ....file:/D:/devel/java/jboss-4.2.2.GA/bin/run.jar
                                ..sun.misc.Launcher$ExtClassLoader@92e78c
                                ....file:/C:/Sun/AppServer/jdk/jre/lib/ext/dnsns.jar
                                ....file:/C:/Sun/AppServer/jdk/jre/lib/ext/localedata.jar
                                ....file:/C:/Sun/AppServer/jdk/jre/lib/ext/sunjce_provider.jar
                                ....file:/C:/Sun/AppServer/jdk/jre/lib/ext/sunpkcs11.jar
                                ++++CodeSource: (file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar )
                                Implemented Interfaces:

                                ### Instance0 found in UCL: org.jboss.mx.loading.UnifiedClassLoader3@1683e80{ url=file:/D:/devel/java/jboss-4.2.2.GA/server/all/tmp/deploy/tmp64792EJB.jar ,addedOrder=49}


                                I am deploying war file with jsp and classes and jar file with classes only.
                                web.war
                                -WEB-INF
                                --classes
                                --- ...all classes in packages
                                -index.jsp

                                ejb.jar
                                -beans
                                -book
                                -META-INF

                                beans and book are packages for my sample and book sample.

                                • 13. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                                  yanlong11

                                  Still does not work and same exception. I reminded myself about 2 options.
                                  1. can the cause be, that I have changes default ports? (in configuration)

                                  2. if this would be packaging issue, what is correct way to package jsp application (web.war) that is using ejb beans?

                                  In books and tutorials I can find only simpler examples, but not such ones, where things are combined.

                                  thanks for help

                                  yanlong

                                  • 14. Re: can not lookup session bean under Jboss 4.2.2GA and ejb3
                                    itsme

                                    Hi,

                                    did you try to package both of your archives in one ear?

                                    1 2 Previous Next