2 Replies Latest reply on Jan 14, 2010 11:05 AM by Alexei Sadovnikov

    Migration from JBoss 4.2.3.GA to JBoss 5.0.0.GA

    Frank Riedel Newbie

      Hi,
      in JBoss 4 this code will works fine:

      @Stateless
      public class GetUserName implements GetUserNameLocal {
      
       public GetUserName() {
       }
      
       @Override
       public String getUserName() throws NamingException {
       InitialContext ic = new InitialContext();
       EJBContext sctxLookup = (EJBContext) ic.lookup("java:comp/EJBContext");
       Principal principal = sctxLookup.getCallerPrincipal();
       String userName = principal.getName();
      
       return userName;
       }
      }
      


      On JBoss 5 i get the following exception:
      08:56:29,719 INFO [STDOUT] javax.naming.NamingException: Could not dereference object [Root exception is java.lang.NullPointerException]
      08:56:29,719 INFO [STDOUT] at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1463)
      08:56:29,719 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:809)
      08:56:29,719 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:820)
      08:56:29,719 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
      08:56:29,750 INFO [STDOUT] at javax.naming.InitialContext.lookup(InitialContext.java:392)
      08:56:29,750 INFO [STDOUT] at de.test.riedel.ejb.service.GetUserName.getUserName(GetUserName.java:28)
      08:56:29,750 INFO [STDOUT] at de.test.riedel.ejb.revision.RevisionListener.newRevision(RevisionListener.java:22)
      08:56:29,750 INFO [STDOUT] at org.jboss.envers.revisioninfo.DefaultRevisionInfoGenerator.newRevision(DefaultRevisionInfoGenerator.java:73)
      08:56:29,750 INFO [STDOUT] at org.jboss.envers.revisioninfo.DefaultRevisionInfoGenerator.generate(DefaultRevisionInfoGenerator.java:80)
      08:56:29,750 INFO [STDOUT] at org.jboss.envers.synchronization.VersionsSync.executeInSession(VersionsSync.java:109)
      08:56:29,750 INFO [STDOUT] at org.jboss.envers.synchronization.VersionsSync.beforeCompletion(VersionsSync.java:144)
      08:56:29,750 INFO [STDOUT] at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101)
      08:56:29,750 INFO [STDOUT] at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:263)
      08:56:29,750 INFO [STDOUT] at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
      08:56:29,750 INFO [STDOUT] at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
      08:56:29,750 INFO [STDOUT] at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1414)
      08:56:29,750 INFO [STDOUT] at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
      08:56:29,750 INFO [STDOUT] at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
      08:56:30,250 INFO [STDOUT] at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:170)
      08:56:30,250 INFO [STDOUT] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
      08:56:30,250 INFO [STDOUT] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
      08:56:30,250 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,250 INFO [STDOUT] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      08:56:30,250 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,250 INFO [STDOUT] at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
      08:56:30,250 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,250 INFO [STDOUT] at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
      08:56:30,250 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,250 INFO [STDOUT] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:159)
      08:56:30,250 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,250 INFO [STDOUT] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
      08:56:30,250 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,281 INFO [STDOUT] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      08:56:30,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,281 INFO [STDOUT] at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:65)
      08:56:30,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,281 INFO [STDOUT] at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
      08:56:30,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:30,281 INFO [STDOUT] at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:486)
      08:56:30,281 INFO [STDOUT] at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:56)
      08:56:30,281 INFO [STDOUT] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
      08:56:30,281 INFO [STDOUT] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
      08:56:30,281 INFO [STDOUT] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
      08:56:30,281 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
      08:56:30,281 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
      08:56:30,281 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
      08:56:30,281 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
      08:56:30,281 INFO [STDOUT] Caused by: java.lang.NullPointerException
      08:56:30,281 INFO [STDOUT] at org.jboss.ejb3.EJBContextFactory.getObjectInstance(EJBContextFactory.java:57)
      08:56:30,281 INFO [STDOUT] at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
      08:56:30,281 INFO [STDOUT] at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1438)
      08:56:30,281 INFO [STDOUT] at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1455)
      08:56:30,281 INFO [STDOUT] ... 46 more
      08:56:30,874 INFO [STDOUT] javax.naming.NamingException: Could not dereference object [Root exception is java.lang.NullPointerException]
      08:56:30,874 INFO [STDOUT] at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1463)
      08:56:30,874 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:809)
      08:56:30,874 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:820)
      08:56:30,874 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
      08:56:31,281 INFO [STDOUT] at javax.naming.InitialContext.lookup(InitialContext.java:392)
      08:56:31,281 INFO [STDOUT] at de.test.riedel.ejb.service.GetUserName.getUserName(GetUserName.java:28)
      08:56:31,281 INFO [STDOUT] at de.test.riedel.ejb.revision.RevisionListener.newRevision(RevisionListener.java:22)
      08:56:31,281 INFO [STDOUT] at org.jboss.envers.revisioninfo.DefaultRevisionInfoGenerator.newRevision(DefaultRevisionInfoGenerator.java:73)
      08:56:31,281 INFO [STDOUT] at org.jboss.envers.revisioninfo.DefaultRevisionInfoGenerator.generate(DefaultRevisionInfoGenerator.java:80)
      08:56:31,281 INFO [STDOUT] at org.jboss.envers.synchronization.VersionsSync.executeInSession(VersionsSync.java:109)
      08:56:31,281 INFO [STDOUT] at org.jboss.envers.synchronization.VersionsSync.beforeCompletion(VersionsSync.java:144)
      08:56:31,281 INFO [STDOUT] at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101)
      08:56:31,281 INFO [STDOUT] at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:263)
      08:56:31,281 INFO [STDOUT] at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
      08:56:31,281 INFO [STDOUT] at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
      08:56:31,281 INFO [STDOUT] at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1414)
      08:56:31,281 INFO [STDOUT] at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
      08:56:31,281 INFO [STDOUT] at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
      08:56:31,281 INFO [STDOUT] at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:170)
      08:56:31,281 INFO [STDOUT] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
      08:56:31,281 INFO [STDOUT] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:201)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:159)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:65)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:486)
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:56)
      08:56:31,281 INFO [STDOUT] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
      08:56:31,281 INFO [STDOUT] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
      08:56:31,281 INFO [STDOUT] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:908)
      08:56:31,281 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:742)
      08:56:31,281 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)
      08:56:31,281 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)
      08:56:31,281 INFO [STDOUT] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:230)
      08:56:31,281 INFO [STDOUT] Caused by: java.lang.NullPointerException
      08:56:31,281 INFO [STDOUT] at org.jboss.ejb3.EJBContextFactory.getObjectInstance(EJBContextFactory.java:57)
      08:56:31,281 INFO [STDOUT] at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
      08:56:31,281 INFO [STDOUT] at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1438)
      08:56:31,281 INFO [STDOUT] at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1455)
      08:56:31,281 INFO [STDOUT] ... 46 more
      


      What's wrong?

      Thanks for help.

        • 1. Re: Migration from JBoss 4.2.3.GA to JBoss 5.0.0.GA
          Frank Riedel Newbie

          I have found one mistake.
          I have used the constructor from GetUserName to use the class. I have changed this and now i use the lookup:

           InitialContext ic = new InitialContext();
           GetUserNameLocal getUsername = (GetUserNameLocal) ic.lookup("GetUserName/local");
           userName = getUsername.getUserName();
          

          Now I get no exception.

          But the the username is not the user that is logged on the session. I get "anonymous".

          Why?



          • 2. Re: Migration from JBoss 4.2.3.GA to JBoss 5.0.0.GA
            Alexei Sadovnikov Newbie

            Hi, in the case of an EJB it is better to use injection of a SessionContext instead of JNDI lookup:

            {code}@Resource

            private SessionContext ctx;

            {code}

             

            I have the same problem in my EntityListener POJO class. The JBoss AS 5.1.0.GA throws exceptions when I try to lookup EJBContext, but it worked in JBoss AS 4.x. As a workaround I'm suggesting to use SecurityAssociation from the jbosssx.jar:

            {code}import org.jboss.security.SecurityAssociation;

            ...

            String callerName = SecurityAssociation.getCallerPrincipal().getName();

            {code}