6 Replies Latest reply on Feb 6, 2007 5:40 AM by Henning Eiben

    EJB client: NullPointerException in StatelessLocalProxy

    Andreas Nauerz Newbie

      Hi!

      This is a follow-up to my last thread which has almost been resolved.
      So, the current code looks as follows:

      An interface:

      package src;
      
      public interface MyCalculator
      {
       String sayHello();
      
       int add(int x, int y);
      
       int sub(int x, int y);
      }
      


      The local interface:

      package src;
      
      import javax.ejb.Local;
      
      @Local
      public interface MyCalculatorLocal extends MyCalculator
      {
      
      }
      


      The remote interface:

      package src;
      
      import javax.ejb.Remote;
      
      @Remote
      public interface MyCalculatorRemote extends MyCalculator
      {
      
      }
      


      The bean class:

      package src;
      
      import javax.ejb.Stateless;
      
      @Stateless
      public class MyCalculatorBean implements MyCalculatorLocal, MyCalculatorRemote
      {
       public String sayHello()
       {
       return "Hello";
       }
      
       public int add(int x, int y)
       {
       return x + y;
       }
      
       public int sub(int x, int y)
       {
       return x - y;
       }
      
      }
      


      The client:

      package client;
      
      import javax.naming.InitialContext;
      
      import src.MyCalculator;
      
      public class MyCalculator_Client
      {
      
       /**
       * @param args
       */
       public static void main(String[] args)
       {
       try
       {
       InitialContext ctx = new InitialContext();
      
       /*
       Properties props = new Properties();
       props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
       props.setProperty("java.naming.provider.url","localhost");
       Context ctx = new InitialContext(props);
       */
      
       MyCalculator myCalculator = (MyCalculator) ctx
       .lookup("MyCalculatorBean/local");
      
       System.out.println(myCalculator.sayHello());
       } catch (Exception e)
       {
       e.printStackTrace(System.err);
       }
       }
      
      }
      


      This is what I see during deployment, look ok to me:

      2006-02-18 22:16:25,956 DEBUG [org.jboss.deployment.MainDeployer] Starting deployment of package: file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:25,956 DEBUG [org.jboss.deployment.MainDeployer] Starting deployment (init step) of package at: file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:25,956 DEBUG [org.jboss.deployment.MainDeployer] Copying file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar -> E:\jboss-4.0.4RC1\server\default\tmp\deploy\tmp10668ejb3_1.jar
      2006-02-18 22:16:26,057 DEBUG [org.jboss.deployment.MainDeployer] using deployer org.jboss.ejb3.EJB3Deployer@ce0bb
      2006-02-18 22:16:26,057 DEBUG [org.jboss.ejb3.EJB3Deployer] init, ejb3_1.jar
      2006-02-18 22:16:26,057 DEBUG [org.jboss.ejb3.EJB3Deployer] looking for nested deployments in : file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:26,067 DEBUG [org.jboss.deployment.DeploymentInfo] createLoaderRepository from config: LoaderRepositoryConfig(repositoryName: JMImplementation:service=LoaderRepository,name=Default, repositoryClassName: null, configParserClassName: null, repositoryConfig: null)
      2006-02-18 22:16:26,067 DEBUG [org.jboss.mx.loading.UnifiedClassLoader] New jmx UCL with url file:/E:/jboss-4.0.4RC1/server/default/tmp/deploy/tmp10668ejb3_1.jar
      2006-02-18 22:16:26,067 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@10ab09f, cl=org.jboss.mx.loading.UnifiedClassLoader3@11e170c{ url=file:/E:/jboss-4.0.4RC1/server/default/tmp/deploy/tmp10668ejb3_1.jar ,addedOrder=0}
      2006-02-18 22:16:26,067 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.UnifiedLoaderRepository3@10ab09f, cl=org.jboss.mx.loading.UnifiedClassLoader3@11e170c{ url=file:/E:/jboss-4.0.4RC1/server/default/tmp/deploy/tmp10668ejb3_1.jar ,addedOrder=0}
      2006-02-18 22:16:26,067 DEBUG [org.jboss.mx.loading.UnifiedLoaderRepository3] Adding org.jboss.mx.loading.UnifiedClassLoader3@11e170c{ url=file:/E:/jboss-4.0.4RC1/server/default/tmp/deploy/tmp10668ejb3_1.jar ,addedOrder=0}
      2006-02-18 22:16:26,067 DEBUG [org.jboss.mx.loading.ClassLoaderUtils] Multiple class loaders found for pkg:
      2006-02-18 22:16:26,067 DEBUG [org.jboss.deployment.MainDeployer] found 0 subpackages of file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:26,067 DEBUG [org.jboss.deployment.MainDeployer] Watching new file: file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:26,067 DEBUG [org.jboss.deployment.MainDeployer] create step for deployment file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:26,067 DEBUG [org.jboss.ejb3.EJB3Deployer] create, ejb3_1.jar
      2006-02-18 22:16:26,127 DEBUG [org.jboss.ejb3.EJB3Deployer] Deploying: file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:26,127 DEBUG [org.jboss.system.ServiceController] Creating service jboss.j2ee:service=EJB3,module=ejb3_1.jar
      2006-02-18 22:16:26,127 DEBUG [org.jboss.ejb3.Ejb3Module] Creating jboss.j2ee:service=EJB3,module=ejb3_1.jar
      2006-02-18 22:16:26,137 DEBUG [org.jboss.ejb3.security.JaccHelper] Initialising JACC Context for deployment: ejb3_1.jar
      2006-02-18 22:16:26,347 INFO [org.jboss.ejb3.Ejb3AnnotationHandler] found EJB3: ejbName=MyCalculatorBean, class=src.MyCalculatorBean, type=STATELESS
      2006-02-18 22:16:26,377 DEBUG [org.jboss.ejb3.ProxyDeployer] no declared remote bindings for : MyCalculatorBean
      2006-02-18 22:16:26,407 DEBUG [org.jboss.ejb3.ProxyDeployer] there is remote interfaces for MyCalculatorBean
      2006-02-18 22:16:26,407 DEBUG [org.jboss.ejb3.ProxyDeployer] default remote binding has jndiName of MyCalculatorBean/remote
      2006-02-18 22:16:26,437 DEBUG [org.jboss.ejb3.security.JaccHelper] JACC Policy Configuration for deployment has been put in service
      2006-02-18 22:16:26,437 INFO [org.jboss.ejb3.Ejb3Deployment] EJB3 deployment time took: 310
      2006-02-18 22:16:26,437 DEBUG [org.jboss.ejb3.Ejb3Module] Created jboss.j2ee:service=EJB3,module=ejb3_1.jar
      2006-02-18 22:16:26,437 DEBUG [org.jboss.system.ServiceController] Creating dependent components for: jboss.j2ee:service=EJB3,module=ejb3_1.jar dependents are: []
      2006-02-18 22:16:26,437 DEBUG [org.jboss.deployment.MainDeployer] Done with create step of deploying ejb3_1.jar
      2006-02-18 22:16:26,437 DEBUG [org.jboss.deployment.MainDeployer] Begin deployment start file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:26,437 DEBUG [org.jboss.ejb3.EJB3Deployer] start application, deploymentInfo: org.jboss.deployment.DeploymentInfo@213eb928 { url=file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar }
       deployer: org.jboss.ejb3.EJB3Deployer@ce0bb
       status: Starting
       state: START_DEPLOYER
       watch: file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
       altDD: null
       lastDeployed: 1140297386067
       lastModified: 1140297385956
       mbeans:
      , short name: ejb3_1.jar, parent short name: null
      2006-02-18 22:16:26,437 DEBUG [org.jboss.system.ServiceController] starting service jboss.j2ee:service=EJB3,module=ejb3_1.jar
      2006-02-18 22:16:26,437 DEBUG [org.jboss.ejb3.Ejb3Module] Starting jboss.j2ee:service=EJB3,module=ejb3_1.jar
      2006-02-18 22:16:26,507 DEBUG [org.jboss.ejb3.EJBContainer] Initialising interceptors for MyCalculatorBean...
      2006-02-18 22:16:26,507 DEBUG [org.jboss.ejb3.EJBContainer] Default interceptors: null
      2006-02-18 22:16:26,507 DEBUG [org.jboss.ejb3.EJBContainer] Class interceptors: []
      2006-02-18 22:16:26,507 DEBUG [org.jboss.ejb3.EJBContainer] All applicable interceptor classes: []
      2006-02-18 22:16:26,507 DEBUG [org.jboss.ejb3.JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
      2006-02-18 22:16:26,547 INFO [org.jboss.ejb3.JmxKernelAbstraction] installing MBean: jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean with dependencies:
      2006-02-18 22:16:26,557 DEBUG [org.jboss.system.ServiceController] Creating service jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean
      2006-02-18 22:16:26,557 DEBUG [org.jboss.system.ServiceController] adding depends in ServiceController.register: []
      2006-02-18 22:16:26,557 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Creating jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean
      2006-02-18 22:16:26,557 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Created jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean
      2006-02-18 22:16:26,557 DEBUG [org.jboss.system.ServiceController] Creating dependent components for: jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean dependents are: []
      2006-02-18 22:16:26,557 DEBUG [org.jboss.system.ServiceController] starting service jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean
      2006-02-18 22:16:26,557 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Starting jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean
      2006-02-18 22:16:26,597 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] Added url: file:/E:/jboss-4.0.4RC1/server/default/tmp/aopdynclasses/ucl10669/?dynamic=true, to ucl: org.jboss.mx.loading.UnifiedClassLoader3@11e170c{ url=file:/E:/jboss-4.0.4RC1/server/default/tmp/deploy/tmp10668ejb3_1.jar ,addedOrder=31}
      2006-02-18 22:16:26,998 DEBUG [org.jboss.ejb3.tx.UserTransactionImpl] new UserTx: org.jboss.ejb3.tx.UserTransactionImpl@183aedf
      2006-02-18 22:16:27,108 DEBUG [org.jboss.ejb3.security.JaccHelper] MyCalculatorBean has no @SecurityDomain - skipping JACC configuration
      2006-02-18 22:16:27,419 DEBUG [org.jboss.ejb.txtimer.EJBTimerServiceImpl] createTimerService: org.jboss.ejb.txtimer.TimerServiceImpl@3abc87
      2006-02-18 22:16:27,419 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Started jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean
      2006-02-18 22:16:27,419 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean dependent components: []
      2006-02-18 22:16:27,419 DEBUG [org.jboss.ejb3.Ejb3Deployment] Bound ejb3 container jboss.j2ee:service=EJB3,jar=ejb3_1.jar,name=MyCalculatorBean
      2006-02-18 22:16:27,419 DEBUG [org.jboss.ejb3.Ejb3Module] Started jboss.j2ee:service=EJB3,module=ejb3_1.jar
      2006-02-18 22:16:27,429 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: jboss.j2ee:service=EJB3,module=ejb3_1.jar dependent components: []
      2006-02-18 22:16:27,429 INFO [org.jboss.ejb3.EJB3Deployer] Deployed: file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:27,429 DEBUG [org.jboss.deployment.MainDeployer] End deployment start on package: ejb3_1.jar
      2006-02-18 22:16:27,429 DEBUG [org.jboss.deployment.MainDeployer] Deployed package: file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      2006-02-18 22:16:27,429 DEBUG [org.jboss.deployment.scanner.URLDeploymentScanner] Watch URL for: file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar -> file:/E:/jboss-4.0.4RC1/server/default/deploy/ejb3_1.jar
      


      And this is the exception when invoking the client:

      java.lang.NullPointerException
       at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:74)
       at $Proxy0.sayHello(Unknown Source)
       at client.MyCalculator_Client.main(MyCalculator_Client.java:30)
      


      Anyone any idea?
      Is this maybe a bug in JBoss?

      Thanks.

        • 1. Re: EJB client: NullPointerException in StatelessLocalProxy
          Janek Ziniewicz Newbie

          I also have the same problem with my bean. I use jBoss-404RC1. Pleas help us or give a hint where to look for clues.

          • 3. Re: EJB client: NullPointerException in StatelessLocalProxy
            William DeCoste Apprentice

            The client is using the bean's local interface. The local interface can only be used from within the same VM as the bean's container (i.e. the server's VM). If your client is being executed external to the server VM, that is the problem - you should be using the remote interface.

            • 4. Re: EJB client: NullPointerException in StatelessLocalProxy
              Yannik Klich Newbie

              I'm having a similar problem. I'm injecting the local EJB into a servlet, and when accesing the bean, the servlet throws a NullPointerException, just as if the bean wasn't instanciated. The servlet runs in the web-container, the bean in the EJB-container. So using the Local interface shouldnt be any problem(?)

              public class ControllerServlet extends HttpServlet
              {
               @EJB
               private ItemManagerLocal itemManager;
              
               protected void processRequest(HttpServletRequest req, HttpServletResponse res)
               {
               itemManager.findItem(itemId); // <--NPE happens
               }
              }
              


              The <web-app> tag in the web.xml is defined as version=2.5
              Using the JBoss JMX console I found the following entry in the Global JNDI Namespace:

              +- klich (class: org.jnp.interfaces.NamingContext)
              | +- ItemManager (class: org.jnp.interfaces.NamingContext)
              | | +- local (proxy: $Proxy116 implements interface com.klich.ejb.ItemManagerLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
              | | +- remote (proxy: $Proxy115 implements interface com.klich.ejb.ItemManagerRemote,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)

              The servlet runs fine if I add:
               InitialContext ictx = new InitialContext();
               itemManager = (ItemManagerLocal)ictx.lookup("klich/ItemManager/local");
              

              without using the @EJB anotation, but we all love our anotations so much :)
              Thanks in advance for any help.

              Yannik Klich

              • 5. Re: EJB client: NullPointerException in StatelessLocalProxy
                Andrew Rubinger Master

                @EJB injection into Servlets isn't yet supported, Yannik.

                • 6. Re: EJB client: NullPointerException in StatelessLocalProxy
                  Henning Eiben Newbie

                   

                  "ALRubinger" wrote:
                  @EJB injection into Servlets isn't yet supported, Yannik.


                  I have a similar problem; for one I also wanted to inject a stateless bean into a servelt, but since that doesn't seem to work. So next I tried injecting the same bean in a "normal" app, but I get the same problem :(

                  App-Code:
                  public class SimpleTest
                  {
                  
                   @EJB
                   private static ICustomerDispatcher disp;
                  
                   public static void main(String[] args)
                   {
                   injectionMode();
                   }
                  
                   private static void injectionMode()
                   {
                   System.out.println("injectionmode!");
                  
                   if (disp != null)
                   {
                   Customer newCust = disp.createCustomer("Jane", "Smith");
                  
                   System.out.println(newCust.getLastName());
                   System.out.println(newCust.getId());
                   }
                   else System.out.println("no dispatcher!!");
                   }
                  


                  Bean:
                  @Stateless
                  @Local(ICustomerDispatcher.class)
                  @Remote(ICustomerDispatcher.class)
                  public class CustomerDispatcherBean implements ICustomerDispatcher
                  {
                   @PersistenceContext
                   EntityManager em;
                  
                   public static final String RemoteJNDIName = CustomerDispatcherBean.class.getSimpleName() + "/remote";
                   public static final String LocalJNDIName = CustomerDispatcherBean.class.getSimpleName() + "/local";
                  
                   public Customer createCustomer(String firstName, String lastName)
                   {
                   Customer newCust = new Customer();
                   newCust.setFirstName(firstName);
                   newCust.setLastName(lastName);
                   em.persist(newCust);
                   return newCust;
                   }
                  
                   public Customer findCustomer(int id)
                   {
                   return em.find(Customer.class, id);
                   }
                  }
                  


                  And the interface:
                  @Local
                  @Remote
                  public interface ICustomerDispatcher
                  {
                   public Customer createCustomer(String firstName, String lastName);
                   public Customer findCustomer(int id);
                  }
                  


                  Well, I skipped the Customer entity ... since it's a POJO with an @Entity annotation.