7 Replies Latest reply on May 16, 2007 8:11 AM by mazu

    Nullpointer exception in embedded JBoss unit test when I use

    webmarck

      Environment:
      JBoss embedded Alpha 7
      Java 1.5.0_06
      Eclipse 3.1.2
      JUnit 4.0 (but writing old school test since Maven doesn?t understand annotations tests)

      The Case
      I have written a unit test that behaves ?funny? because it correctly throws a EJBAccessException: Authentication failure when I use a wrong password or unknown user ? but throws a NullPointerException when I use the correct user/password.

      Is this a known problem or have I done an environment setup error? All help is more then welcome.


      Details:
      The exception
      javax.ejb.EJBException: java.lang.NullPointerException
      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)

      The test class (ripe)

      public class MpSupportBeanTest extends TestCase {
      
      protected void setUp () {
      EJB3StandaloneBootstrap.boot(null);
      EJB3StandaloneBootstrap.deployXmlResource("security-beans.xml");
       EJB3StandaloneBootstrap.scanClasspath();
       }
      
      public static InitialContext getInitialContext() throws Exception {
       Hashtable props = getInitialContextProperties();
       return new InitialContext(props);
       }
      
      private static Properties getInitialContextProperties() {
       Properties props = new Properties();
       props.setProperty(Context.INITIAL_CONTEXT_FACTORY,
       "org.jboss.security.jndi.JndiLoginInitialContextFactory");
       props.setProperty(Context.SECURITY_PRINCIPAL, "firstuser");
       props.setProperty(Context.SECURITY_CREDENTIALS, "validpassword");
       return props;
       }
      
      public void testGetSubscriberDetails() throws Exception {
       InitialContext ctx = getInitialContext();
       MpSupport support = (MpSupportLocal) ctx.lookup("MpSupport/locale");
       Subscriber s = support.getSubscriberDetails();
       assertNotNull(s);
       }
      }


      The session bean (ripe)

      @Stateless
      @SecurityDomain("other")
      public class MpSupportBean implements MpSupport{
      
      @RolesAllowed("subsciber")
      public Subscriber getSubscriberDetails() {
      }


      Besides that I have copied default.persistence.properties
      ejb3-interceptors-aop.xml
      embedded-jboss-beans.xml
      jboss-jms-beans.xml
      log4j.xml
      login-config.xml
      roles.properties
      security-beans.xml
      users.properties

      and modifed the user and roles files so they contain a subscriber role and a firstuser with password validpassword

        • 1. Re: Nullpointer exception in embedded JBoss unit test when I
          webmarck

          Sigh!!
          Sometimes it helps to just READ the code.

          The exception was actually thrown INSIDE the getSubscriberDetails method.

          @Resource SessionContext ctx;

          @RolesAllowed("subsciber")
          public Subscriber getSubscriberDetails() {
          Principal callerPrincipal = ctx.getCallerPrincipal();
          ....

          }

          I have tested that the ctx is not null so the exception is thrown by getCallerPrincipal()

          full stacktrace:
          javax.ejb.EJBException: java.lang.NullPointerException
          at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
          at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
          at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:167)
          at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:100)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
          at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
          at $Proxy15.getSubscriberDetails(Unknown Source)
          at dk.niro.mpsuite.support.MpSupportBeanTest.testGetSubscriberDetails(MpSupportBeanTest.java:68)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at junit.framework.TestCase.runTest(TestCase.java:164)
          at junit.framework.TestCase.runBare(TestCase.java:130)
          at junit.framework.TestResult$1.protect(TestResult.java:110)
          at junit.framework.TestResult.runProtected(TestResult.java:128)
          at junit.framework.TestResult.run(TestResult.java:113)
          at junit.framework.TestCase.run(TestCase.java:120)
          at junit.framework.TestSuite.runTest(TestSuite.java:228)
          at junit.framework.TestSuite.run(TestSuite.java:223)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
          Caused by: java.lang.NullPointerException
          at org.jboss.security.plugins.JaasSecurityManager.getPrincipal(JaasSecurityManager.java:348)
          at org.jboss.ejb3.BaseSessionContext.getCallerPrincipal(BaseSessionContext.java:177)
          at dk.niro.mpsuite.support.MpSupportBean.getSubscriberDetails(MpSupportBean.java:42)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
          at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
          at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
          ... 34 more


          • 2. Re: Nullpointer exception in embedded JBoss unit test when I
            jgilbert

            I am getting the same thing with alpha8. I'm thinking it is a bug, because I can get the principal from org.jboss.security.SecurityAssociation.getPrincipal(), but not from the Session Context.

            • 3. Re: Nullpointer exception in embedded JBoss unit test when I
              webmarck

              Ok - did you fill out a bug rapport or should I ?

              • 4. Re: Nullpointer exception in embedded JBoss unit test when I
                jgilbert

                no, go ahead and report it. thanks

                • 5. Re: Nullpointer exception in embedded JBoss unit test when I
                  webmarck
                  • 6. Re: Nullpointer exception in embedded JBoss unit test when I
                    jazir1979

                    Hi all,

                    I've attached more info to this JIRA issue for a similar problem I'm having - NullPointerException when obtaining the principal, but a different stacktrace.

                    This was lodged in June -- any ideas when this might be looked at?

                    If it's not going to be soon, I guess I'm going to be testing against the full app server and ditching EJB3 embedded :(

                    "webmarck" wrote:
                    Consider it done ;-)
                    http://jira.jboss.com/jira/browse/EJBTHREE-615



                    • 7. Re: Nullpointer exception in embedded JBoss unit test when I
                      mazu

                      Hi All,

                      We encounter the same issue with the microcontainer.
                      We have EJB3 Interceptors getting the Principals (through the injected EJBContext) and it works into JBoss Server but not into the embeddable container.
                      Is it a bug ?