2 Replies Latest reply on Nov 1, 2001 8:34 PM by Andreas Schaefer

    CMP 2.0 Proxy generates NullPointer

    Jochen Cordes Novice

      Hi !

      I'm using MySQL 3.23.42, mm.mysql.2.0.6.1 and JBoss3.0.0alpha. Currently I'm trying to figure out how to use the proxy classes correctly. My first attempt of calling an EJB from a JSP was like this:

      ...
      Properties p = new Properties();
      p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      p.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
      p.put("java.naming.provider.url","jnp://localhost:1099");
      Context jndiContext = new InitialContext(p);
      Proxy proxy = (Proxy)jndiContext.lookup("local/Article");
      InvocationHandler handler = Proxy.getInvocationHandler(proxy);
      ArticleLocalHome home = (ArticleLocalHome)Proxy.newProxyInstance(ArticleLocalHome.class.getClassLoader(),
      new Class[] { ArticleLocalHome.class },
      handler);

      if (home != null){
      try {
      LocalArticle article = home.create();
      } catch (CreateException e){
      %>
      <%= e %>
      <%
      } catch (NullPointerException e){
      %>
      <%= e %>
      <%
      } catch (UndeclaredThrowableException e){
      e.getUndeclaredThrowable().printStackTrace(new PrintWriter(out));
      }
      }
      %>
      ...

      where Article is a EntityBean with a no-arg ejbCreate-method (yes, it returns null)

      But all I got was a NullPointerException:
      java.rmi.ServerException: null; nested exception is: java.lang.NullPointerException java.lang.NullPointerException at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:922) at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:74) at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:74) at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:234) at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:151) at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:104) at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:100) at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:156) at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:56) at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:106) at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:109) at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:441) at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invokeHome(BaseLocalContainerInvoker.java:255) at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker$HomeProxy.invoke(BaseLocalContainerInvoker.java:406) at $Proxy47.create(Unknown Source) at _0002findex_0002ejspindex_jsp_0._jspService(_0002findex_0002ejspindex_jsp_0.java:97) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:176) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:307) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:488) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:387) at org.mortbay.http.HandlerContext.handle(HandlerContext.java:1040) at org.mortbay.http.HandlerContext.handle(HandlerContext.java:995) at org.mortbay.http.handler.ResourceHandler.handleGet(ResourceHandler.java:361) at org.mortbay.http.handler.ResourceHandler.handle(ResourceHandler.java:264) at org.mortbay.http.HandlerContext.handle(HandlerContext.java:1040) at org.mortbay.http.HandlerContext.handle(HandlerContext.java:995) at org.mortbay.http.HttpServer.service(HttpServer.java:683) at org.mortbay.http.HttpConnection.service(HttpConnection.java:732) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:889) at org.mortbay.http.HttpConnection.handle(HttpConnection.java:746) at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:146) at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:287) at org.mortbay.util.ThreadPool$PoolThreadRunnable.run(ThreadPool.java:609) at java.lang.Thread.run(Thread.java:484)

      Somebody help me, please !

      Thanks in advance,

      Jochen.

        • 1. Re: CMP 2.0 Proxy generates NullPointer
          Jochen Cordes Novice

          Hi !

          After hours I finally found that this was a classpath problem. I just packaged my EJB's and Servlets/JSP in an ear and all went as expected. Maybe I didn't understand the documentation right, it was just a matter of doing a lookup and a cast (not what I tried before) !!! So this should look like

          bean = ()jndiContext.lookup("local/");

          That's even easier than before (with narrow and all that stuff). Im quite impressed how easy it was to model complex relations. Go, JBoss go !!!

          • 2. Re: CMP 2.0 Proxy generates NullPointer
            Andreas Schaefer Apprentice

            Normally you should pack the EJBs in an JAR file, the Servlets/JSP in a WAR file which has to contain the Home/Remote Interfaces of all EJBs and the helper classes as well in the /WEB-INF/classes (you could als pack them in JAR and put this file in /WEB-INF/lib but this can product some problems with some versions of Tomcat).

            Then put everything in an EAR file, specify the modules which allows you to specify the path of you web application this should work then.

            The narrow cast is necessary when RMI/IIOP is used, AFAIK.

            Have fun - Andy