6 Replies Latest reply on Apr 14, 2003 4:58 PM by andyfyfe

    SLSB throws CreateException, client doesn't see it

    andyfyfe

      I have a stateless session bean with a remote interface that tries to set up a jdbc connection in its ejbCreate method.

      This can fail, and if it does, ejbCreate throws a new CreateException with what should be a meaningful message. I can log the message prior to the throw, and it all looks fine.

      However, the client doesn't see it. The call to home.create() succeeds without error.

      However, any attempt to access any of the bean's methods results in a java.lang.reflect.UndeclaredThrowableException exception being throw, and the exception getMessage() returns null.

      This is an exception I wouldn't normally trap, and it contains no information about the original problem.

      I must be missing something. Ideas?

        • 1. Re: SLSB throws CreateException, client doesn't see it

          You haven't declared "throws CreateException"
          on the home interface's "void create()" method?

          • 2. Re: SLSB throws CreateException, client doesn't see it
            andyfyfe

            XDoclet created the home interface, and create() throws both javax.ejb.CreateException and java.rmi.RemoteException.

            • 3. Re: SLSB throws CreateException, client doesn't see it

              Ok,

              Post the relevent section of the server.log
              and the full client side exception trace.

              Regards,
              Adrian

              • 4. Re: SLSB throws CreateException, client doesn't see it
                andyfyfe

                I took an example from Apple -- http://developer.apple.com/internet/java/enterprisejava.tar.gz --
                and modified it slightly -- to always throw an exception in ejbCreate, and to better check for exceptions.

                From the jboss log:

                00:21:38,309 ERROR [STDERR] Caught class java.lang.reflect.UndeclaredThrowableException: null
                00:21:38,310 ERROR [STDERR] java.lang.reflect.UndeclaredThrowableException
                00:21:38,310 ERROR [STDERR] at $Proxy24.hi(Unknown Source)
                00:21:38,311 ERROR [STDERR] at HelloWorldServlet.doGet(HelloWorldServlet.java:48)
                00:21:38,311 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
                00:21:38,311 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

                (and more stack trace) followed by

                00:21:38,323 ERROR [STDERR] Caused by: javax.ejb.CreateException: always throw an exception
                00:21:38,324 ERROR [STDERR] at HelloWorldEJB.ejbCreate(HelloWorldEJB.java:19)
                00:21:38,324 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                00:21:38,324 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                (and again more stack trace).

                So the create exception is in there.

                I've made a zip file containing my changes -- it can be found at http://homepage.mac.com/afyfe/

                I've tried this both under Solaris as well as Mac OSX.

                • 5. Re: SLSB throws CreateException, client doesn't see it

                  Ok,

                  I see what the problem is.

                  For a stateless session bean the
                  create() operations just creates the local
                  proxy, it does not invoke ejbCreate()

                  This is done by pool as real requests come in,
                  in your case hi().
                  The pool couldn't create an instance to process
                  hi() because you threw the CreateException
                  which isn't on the definition of hi()

                  Regards,
                  Adrian

                  • 6. Re: SLSB throws CreateException, client doesn't see it
                    andyfyfe

                    I changed the remote interface to throw both RemoteException and CreateException. The call to the remote interface method in the servlet will now catch a CreateException with the appropriate message.

                    I understood that a remote interface method should only have to deal with a RemoteException. Should the container be catching the CreateException and throwing a RemoteException in its place?