1 2 Previous Next 22 Replies Latest reply on May 7, 2006 8:21 PM by mingliou

    JNDI-problem with Tutorial

    chlfromde

      I try to run the Fibo-example from 1.30 Tutorial.
      (JBoss 4.01, Eclipse 3.01, IDE 1.40, Jdk 1.50, WinXP)

      The lookup for the Ejb-Ref in ComputeServlet.Init() raises an exeception:

      Context context = new InitialContext();
      Object ref = context.lookup("java:/comp/env/ejb/Fibo");

      bang!

      javax.servlet.ServletException: Could not dereference object
      tutorial.web.ComputeServlet.init(ComputeServlet.java:67)
      org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
      org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
      org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
      org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
      org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
      org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
      java.lang.Thread.run(Thread.java:595)


      All DD's seem to be fine (see below) and there are no errors during deployment. I modified the code, using
      context.list() to browse "java:/comp/env/"; the entry for Fibo is present.

      Is this an security-issue, missing rights for the servlet to access the ejb ?
      (exceptions namespace: org.jboss.web.tomcat.security.*)

      Thanks a lot
      Christian




      ---------------------------------------------------------------------------------------


      JBoss.xml:

      <ejb-name>Fibo</ejb-name>
      <jndi-name>ejb/Fibo</jndi-name>


      ejb-jar.xml

      <![CDATA[Description for Fibo]]>
      <display-name>Name for Fibo</display-name>
      <ejb-name>Fibo</ejb-name>
      tutorial.interfaces.FiboHome
      tutorial.interfaces.Fibo
      <ejb-class>tutorial.ejb.FiboBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>


      jboss-web.xml:
      <ejb-ref>
      <ejb-ref-name>ejb/Fibo</ejb-ref-name>
      <jndi-name>ejb/Fibo</jndi-name>
      </ejb-ref>

      web.xml:
      <ejb-ref >
      <![CDATA[Reference to the Fibo EJB]]>
      <ejb-ref-name>ejb/Fibo</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      tutorial.interfaces.FiboHome
      tutorial.interfaces.Fibo
      </ejb-ref>

        • 1. Re: JNDI-problem with Tutorial
          sfryer

          I'm having the same problems can anybody help my please??

          "chlfromde" wrote:
          I try to run the Fibo-example from 1.30 Tutorial.
          (JBoss 4.01, Eclipse 3.01, IDE 1.40, Jdk 1.50, WinXP)

          The lookup for the Ejb-Ref in ComputeServlet.Init() raises an exeception:

          Context context = new InitialContext();
          Object ref = context.lookup("java:/comp/env/ejb/Fibo");

          bang!

          javax.servlet.ServletException: Could not dereference object
          tutorial.web.ComputeServlet.init(ComputeServlet.java:67)
          org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
          org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
          org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
          org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
          org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
          org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
          org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
          org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
          org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
          java.lang.Thread.run(Thread.java:595)


          All DD's seem to be fine (see below) and there are no errors during deployment. I modified the code, using
          context.list() to browse "java:/comp/env/"; the entry for Fibo is present.

          Is this an security-issue, missing rights for the servlet to access the ejb ?
          (exceptions namespace: org.jboss.web.tomcat.security.*)

          Thanks a lot
          Christian




          ---------------------------------------------------------------------------------------


          JBoss.xml:
          <session>
          <ejb-name>Fibo</ejb-name>
          <jndi-name>ejb/Fibo</jndi-name>
          </session>

          ejb-jar.xml
          <session >
          <description>[CDATA[Description for Fibo]]</description>
          <display-name>Name for Fibo</display-name>
          <ejb-name>Fibo</ejb-name>
          <home>tutorial.interfaces.FiboHome</home>
          <remote>tutorial.interfaces.Fibo</remote>
          <ejb-class>tutorial.ejb.FiboBean</ejb-class>
          <session-type>Stateless</session-type>
          <transaction-type>Container</transaction-type>
          </session>

          jboss-web.xml:
          <ejb-ref>
          <ejb-ref-name>ejb/Fibo</ejb-ref-name>
          <jndi-name>ejb/Fibo</jndi-name>
          </ejb-ref>

          web.xml:
          <ejb-ref >
          <description>[CDATA[Reference to the Fibo EJB]]</description>
          <ejb-ref-name>ejb/Fibo</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          <home>tutorial.interfaces.FiboHome</home>
          <remote>tutorial.interfaces.Fibo</remote>
          </ejb-ref>


          • 2. Re: JNDI-problem with Tutorial
            sherwinds

            check this out: JBossIDE Tutorial 1.4, page 34, section 9.3, start from 3rd paragraph.

            Verify if you followed this tutorial and notice the 6th paragraph where it says:

            "The classes must be located under the WEB-INF/classes of the War package. Set the prefix to WEB-INF/classes."

            You can try to remove the entry on Prefix, it should be blank, and try to run Packaging again and re-deploy your FiboApp.ear and try Fibo again.

            Hopes this help. Mine is now working after 3 days of almost on the brink of insanity.

            S

            My current config:

            OS: WXP SP4
            JBossIDE: JBossIDE-1.5M1-jre15-win32.zip
            Java: 1.5.0_3

            • 3. Re: JNDI-problem with Tutorial
              pacwest

              I m having the same problem. I tried removing the WEB-INF/classes from the packaging info. I redeployed it also.

              But it is still giving me the same error.

              Can anybody help?

              • 4. Re: JNDI-problem with Tutorial
                bruteous

                I removed the WEB-INF/classes from packaging info as above, and it worked, thanks a million.

                • 5. Re: JNDI-problem with Tutorial
                  plasante

                  Hi,

                  In ComputeServlet.java I changed the following line from:

                  Object ref = context.lookup("java:/com/env/ejb/Fibo");

                  to:
                  Object ref = context.lookup("ejb/Fibo");

                  and Run Packaging and everything was fine.

                  I also had to use jboss-4.0.1 instead of jboss-4.0.2

                  Regards.

                  • 6. Re: JNDI-problem with Tutorial
                    helmut.staudinger

                    Hi,
                    the correct URL should be "java:com/env/ejb/Fibo".

                    If you get an exception like "ClassCastException" when narrowing the reference to the homeInterface, have a look at the AdminGuide Chapter 2 (Server Config.) and change some Config-Flags, making the server J2EE-1.4 compliant. I did this with Version 4.0.2 and 4.0.3RC1 and the tutorial example (jBossIDE) worked fine!

                    Helmut

                    • 7. Re: JNDI-problem with Tutorial
                      anderslind

                       

                      "helmut.staudinger" wrote:
                      Hi,
                      the correct URL should be "java:com/env/ejb/Fibo".

                      If you get an exception like "ClassCastException" when narrowing the reference to the homeInterface, have a look at the AdminGuide Chapter 2 (Server Config.) and change some Config-Flags, making the server J2EE-1.4 compliant. I did this with Version 4.0.2 and 4.0.3RC1 and the tutorial example (jBossIDE) worked fine!

                      Helmut


                      I can confirm that it works!

                      My sestup is eclipse 3.1.0 with jboss ide 1.5.0M2 and I use JBoss 4.0.3RC1.
                      I ran my setup as a J2EE 1.4 project and used the EAR 1.4 Deployment Descriptor and the application.xml has the following content:
                      <?xml version="1.0" encoding="UTF-8"?>
                      <application version="1.4"
                      xmlns="http://java.sun.com/xml/ns/j2ee"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                      http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
                      <display-name>Sum Application</display-name>
                      ...



                      • 8. Re: JNDI-problem with Tutorial

                         

                        "bruteous" wrote:
                        I removed the WEB-INF/classes from packaging info as above, and it worked, thanks a million.


                        Hi!

                        i had the same problem too:

                        Win2000
                        jboss-4.0.2
                        jdk1.5.0_04

                        removing only the WEB-INF/classes was enough to fix the problem, no changes in the jboss configuration was necessary...

                        best regards,
                        Christian


                        • 9. Re: JNDI-problem with Tutorial
                          jkytang

                          Would anyone explain why removing WEB-INF/classes can solve the problem?
                          Thanks!

                          • 10. Re: JNDI-problem with Tutorial
                            lucluc

                            Thanks to Helmut.
                            Your solution worked fine.

                            WinXP
                            jboss-4.0.2
                            jdk1.5.0_04

                            • 11. Re: JNDI-problem with Tutorial
                              joern

                              Please, could anyone explain me Helmut's solution?
                              What do I have to do, to get rid of this classCastException? What configuration files do I have to change?

                              Thank you very much!

                              • 12. Re: JNDI-problem with Tutorial
                                thomasramapuram

                                This is basically a classloading problem.
                                The new JBoss does not have a flat classloader like the old JBoss. So if you load a class in your EJB and you load a class in your servlet even though the bytecode is the same they are treated as diffrent classes.

                                So for the tutorial to work you should remove the FiboEJB-client.jar from your FiboWEB.war file. Your servlet will reference the class FiboHome from the FiboEJB.jar file.

                                After 2 days of digging into the code. IRC channels web searches. I finally managed to get the applcation working.

                                There is also a problem with the Discriptor Wizard but if you type in all that is written in the tutorial it should work.

                                @jboss.xxxx tags also did not work for me. I just typed it in.

                                From all this the lession I learnt was "There is no substitute to hard work" if you have any problems you can mail me.

                                I know your plight. I've been there.

                                Ciao

                                Some of the sites I visited to know more of the problem.

                                http://www.jbossgroup.com/index.html?module=bb&op=viewtopic&p=3887843
                                http://jira.jboss.com/jira/browse/JBAS-1775
                                http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration
                                http://jira.jboss.com/jira/browse/JBAS-1691

                                • 13. Re: JNDI-problem with Tutorial
                                  amathewk

                                  Just confirming that I had the classloader problem and ThomasRamapuram's solution of removing the client jar from the war worked perfectly. Wish I found this thread sooner!!
                                  thanks!

                                  • 14. Re: JNDI-problem with Tutorial

                                    Removing the WEB-INF/classes did the trick for me, thanks for the tip!!!
                                    After looking at the project tree on disk I found that there was no such directory, the classes are in the Tutorial/bin/ejb, Tutorial/bin/interfaces and Tutorial/bin/web directories. This explains why you have to leave it blank, everything is found relative to the class directory Tutorial/bin.

                                    Cheers, Roel.

                                    1 2 Previous Next