7 Replies Latest reply on Jun 24, 2002 5:48 AM by Mart van Ineveld

    Classloader issue: java.lang.ObjectMissing no-arg constructo

    Ken Jennings Newbie

      I'm getting an error in JBoss 3.0 when my servlet tries to get a reference to the home interface of my session bean. I do this in the typical way:
      Object ref = ic.lookup("java:comp/env/ejb/CourseAccessHome");

      This worked fine in JBoss2.4.4. Porting it over to JBoss3.0 beta, however, I removed the EJB classes from the WEB-INF directory of my servlet's .war file in order to take advantage of the new UnifiedClassLoader in 3.0. However, the context lookup above now gives me the following:

      2002-04-16 14:26:51,813 ERROR [Default] javax.naming.CommunicationException. Root exception is
      2002-04-16 14:26:51,814 ERROR [Default] java.io.InvalidClassException: java.lang.ObjectMissing no-arg constructor for class
      2002-04-16 14:26:51,814 ERROR [Default] at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1350)
      2002-04-16 14:26:51,815 ERROR [Default] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
      2002-04-16 14:26:51,816 ERROR [Default] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
      2002-04-16 14:26:51,816 ERROR [Default] at java.rmi.MarshalledObject.get(MarshalledObject.java:138)
      2002-04-16 14:26:51,817 ERROR [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:369)
      2002-04-16 14:26:51,817 ERROR [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:349)
      2002-04-16 14:26:51,818 ERROR [Default] at javax.naming.InitialContext.lookup(InitialContext.java:350)
      2002-04-16 14:26:51,819 ERROR [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:437)
      2002-04-16 14:26:51,819 ERROR [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:473)
      2002-04-16 14:26:51,820 ERROR [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:349)
      2002-04-16 14:26:51,820 ERROR [Default] at javax.naming.InitialContext.lookup(InitialContext.java:350)
      2002-04-16 14:26:51,821 ERROR [Default] at com.comphealth.training.CourseServlet.createCourseAccess(CourseServlet.java:97)
      etc.

      Looks like a marshalling problem with Serializable, I guess, except I don't know what the problem might be. Repeated attempts to hit the servlet result in a different error:

      2002-04-16 14:28:13,977 ERROR [org.jboss.web.catalina.EmbeddedCatalinaServiceSX] ----- Root Cause -----
      java.lang.NoClassDefFoundError
      at java.io.ObjectInputStream.allocateNewObject(Native Method)
      at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1347)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
      at java.rmi.MarshalledObject.get(MarshalledObject.java:138)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:369)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:349)
      at javax.naming.InitialContext.lookup(InitialContext.java:350)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:437)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:473)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:349)
      at javax.naming.InitialContext.lookup(InitialContext.java:350)
      at com.comphealth.training.CourseServlet.createCourseAccess(CourseServlet.java:97)
      etc.

      This is similar to a problem reported in the forums here:
      http://main.jboss.org/thread.jsp?forum=47&thread=6759
      that as far as I can tell was never solved.

      I can't think of anything weird in my configuration...this is JBoss 3.0 beta straight off the site. This is also EJB code that worked flawlessly before I ported it over from JBoss 2.4.4.

      Suggestions?

        • 1. Re: Classloader issue: java.lang.ObjectMissing no-arg constr
          Adrian Brock Master

          Hi,

          There was a post on jboss-user today saying this works
          with jboss-3.0.0RC1-tomcat-4.0.3. I haven't had time
          to try this myself.

          If that doesn't work perhaps you can give some more
          information about the packaging, e.g. ear or jar/war,
          the java:comp/env config from web.xml and the ejb-jar.xml
          for the CourseAccess bean.

          Regards,
          Adrian

          • 2. Re: Classloader issue: java.lang.ObjectMissing no-arg constr
            Adrian Brock Master

            Actually,

            I've seen some follow ups of some reported problems.
            I noticed from looking in the dev forum
            that a test has been added for accessing an entity
            bean from a servlet. So maybe there are still problems?

            Regards,
            Adrian

            • 3. Re: Classloader issue: java.lang.ObjectMissing no-arg constr
              Adrian Brock Master

              Another follow up.

              Apparently the accessing an Entity works from a servlet.

              You could try comparing your application with the one
              from the testsuite. You can find a link to the
              testsuite in the where can get an example thread in the
              FAQ forum.

              I wish I had more time to verify this myself.

              Regards,
              Adrian

              • 4. Re: Classloader issue: java.lang.ObjectMissing no-arg constr
                Ken Jennings Newbie

                I haven't dug into CVS yet, but I have reproduced my error with a simple, HelloWorld-type servlet/session bean combination. The "Missing no-arg constructor" error recurs whether I deploy a war or a jar/ear.

                My servlet is just
                public class TestServlet extends HttpServlet
                {

                public void doGet(HttpServletRequest request,
                HttpServletResponse response)
                throws ServletException, IOException
                {
                try
                {
                InitialContext ic = new InitialContext();
                Object ref = ic.lookup("java:comp/env/ejb/SessionHome");
                }
                catch (Exception ex)
                {
                System.out.println("Servlet exception.");
                ex.printStackTrace();
                }
                }
                }
                and the bean lookup line returns the naming exception.

                My web.xml:
                <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                "http://java.sun.com/dtd/web-app_2_3.dtd">

                <web-app>
                <display-name>TrainingWar</display-name>
                Training WAR file

                <servlet-name>testing</servlet-name>
                <display-name>testing</display-name>
                Testing
                <servlet-class>com.comphealth.training.TestServlet</servlet-class>

                <servlet-mapping>
                <servlet-name>testing</servlet-name>
                <url-pattern>/testing</url-pattern>
                </servlet-mapping>
                <session-config>
                <session-timeout>30</session-timeout>
                </session-config>
                <ejb-ref>
                <ejb-ref-name>ejb/SessionHome</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                com.comphealth.ejb.training.SessionHome
                com.comphealth.ejb.training.Session
                </ejb-ref>
                </web-app>

                My jboss-web.xml:
                <jboss-web>
                <ejb-ref> <ejb-ref-name>ejb/SessionHome</ejb-ref-name>
                <jndi-name>jboss/training/SessionHome</jndi-name>
                </ejb-ref>
                </jboss-web>

                My ejb-jar.xml:
                <ejb-jar>
                Session bean
                <display-name>SessionEJB</display-name>
                <enterprise-beans>

                <ejb-name>SessionBean</ejb-name>
                com.comphealth.ejb.training.SessionHome
                com.comphealth.ejb.training.Session
                <ejb-class>com.comphealth.ejb.training.SessionEJB</ejb-class>
                <session-type>Stateful</session-type>
                <transaction-type>Container</transaction-type>

                </enterprise-beans>
                </ejb-jar>

                and my bean's jboss.xml:

                <enterprise-beans>

                <ejb-name>SessionBean</ejb-name>
                <jndi-name>jboss/training/SessionHome</jndi-name>

                </enterprise-beans>


                Hopefully that will give some background. Next stop, the testsuite. Thanks for the pointers, Adrian.

                Ken

                • 5. Re: Classloader issue: java.lang.ObjectMissing no-arg constr
                  Ken Jennings Newbie

                  One more note: this error still occurs in JBoss3.0.0_RC1. I can only assume that more people haven't reported it because they package their EJB classes in WEB-INF, as was acceptable in JBoss 2.4, and which doesn't cause this lookup problem?

                  Adrian, if you're reading--any idea which specific test in the testsuite is the one that "proves" that bean access from a servlet works?

                  Thanks!

                  • 6. Re: Classloader issue: java.lang.ObjectMissing no-arg constr
                    Ken Jennings Newbie

                    Solved this after a few days of frustration: I had unnecessary jars in my .ear's lib directory that were stymieing the class loader ("servlet.jar" and "jboss-j2ee.ear," I think). Oops. Accidentally deploying these jars in the .ear file worked in JBoss 2.4, funnily enough, but no longer.

                    Ken

                    • 7. Re: Classloader issue: java.lang.ObjectMissing no-arg constr
                      Mart van Ineveld Newbie

                      I am running into exactly the same serialization problem with version jboss 2.4.4. Changing the contents of the .ear file or the classpath (in manifest.mf or wherever) did not help me. I can deploy and run the same application under JBoss 2.4.1-Tomcat without any problems. As soon as I try the same deployed .ear (with session beans and war files) on JBoss2.4.4-Tomcat4.0.1 i get the mentioned error. Trying to create the session bean for a second time generates another error (as mentioned in this thread):
                      java.lang.NoClassDefFoundError
                      at java.io.ObjectInputStream.allocateNewObject(Native Method)
                      (...)

                      A very frustrating bug somewhere. If anybody has a clue?????!

                      Thanks
                      Mart