6 Replies Latest reply on Mar 17, 2010 10:14 AM by devika.nrgh

    Unknown context variable name

    fshahy

      I have created a Stateless bean named CustomerManagerBean


      '@Stateless
      @Name(customerManager)
      public class CustomerManagerBean implements CustomerManager {


           @PersistenceContext
           EntityManager em;'


      and I want use it from my authenticator class


      '@Name(authenticator)
      public class Authenticator
      {
           @In
           CustomerManagerBean customerManagerBean;'


      when I am in eclipse, the validator (by a warning) says Unknown context variable name: customerManagerBean
      when I run the project I get a null pointer exception because is null.


      Does anybody knows whats wrong with this?
      thanks

        • 1. Re: Unknown context variable name
          fshahy

          Sorry for bad format, I post it again:


          I have created a Stateless bean named CustomerManagerBean


          @Stateless 
          @Name("customerManager") 
          public class CustomerManagerBean implements CustomerManager {
          
          @PersistenceContext 
          EntityManager em;
          



          and I want use it from my authenticator class



          @Name("authenticator") 
          public class Authenticator { 
          
          @In CustomerManagerBean customerManagerBean;
          



          when I am in eclipse, the validator (by a warning) says Unknown context variable name: customerManagerBean when I run the project I get a null pointer exception because customerManagerBean is null.


          Does anybody know what's wrong with this?


          thanks

          • 2. Re: Unknown context variable name
            igels.igelsss.gmail.com

            The component name is customerManager but you try to inject customerManagerBean. And you have to have this component created before you inject it. For example you can use factory or @In(creat=true).
            So here is correct code:


            @Name("authenticator") 
            public class Authenticator { 
            
            @In(create=true) CustomerManagerBean customerManager;


            • 3. Re: Unknown context variable name
              fshahy

              thank you Alexey


              I tried this and worked, but now I get another error:



              10:12:38,858 ERROR [SeamLoginModule] Error invoking login method
              javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: could not set field value: authenticator.customerManagerImp
                   at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:333)
                   at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
                   at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                   at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                   at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                   at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:174)
                   at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:109)
                   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 javax.security.auth.login.LoginContext.invoke(Unknown Source)
                   at javax.security.auth.login.LoginContext.access$000(Unknown Source)
                   at javax.security.auth.login.LoginContext$5.run(Unknown Source)
                   at java.security.AccessController.doPrivileged(Native Method)
                   at javax.security.auth.login.LoginContext.invokeCreatorPriv(Unknown Source)
                   at javax.security.auth.login.LoginContext.login(Unknown Source)
                   at org.jboss.seam.security.Identity.authenticate(Identity.java:335)
                   at org.jboss.seam.security.Identity.authenticate(Identity.java:324)
                   at org.jboss.seam.security.Identity.login(Identity.java:253)
                   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.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
                   at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
                   at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                   at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                   at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                   at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
                   at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
                   at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
                   at javax.faces.component.UICommand.broadcast(UICommand.java:383)
                   at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
                   at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
                   at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
                   at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
                   at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
                   at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                   at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
                   at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                   at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                   at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:51)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                   at java.lang.Thread.run(Unknown Source)
              Caused by: javax.ejb.EJBTransactionRolledbackException: could not set field value: authenticator.customerManagerImp
                   at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
                   at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
                   at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
                   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.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
                   at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                   at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
                   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:240)
                   at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
                   at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
                   at $Proxy89.authenticate(Unknown Source)
                   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.seam.util.Reflections.invoke(Reflections.java:22)
                   at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                   at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                   at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                   at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                   at org.javassist.tmp.java.lang.Object_$$_javassist_1.authenticate(Object_$$_javassist_1.java)
                   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.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
                   ... 81 more
              Caused by: java.lang.IllegalArgumentException: could not set field value: authenticator.customerManagerImp
                   at org.jboss.seam.Component.setFieldValue(Component.java:1884)
                   at org.jboss.seam.Component.access$600(Component.java:126)
                   at org.jboss.seam.Component$BijectedField.set(Component.java:2900)
                   at org.jboss.seam.Component.injectAttributes(Component.java:1693)
                   at org.jboss.seam.Component.inject(Component.java:1511)
                   at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                   at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                   at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                   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.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
                   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.invokeInCallerTx(TxPolicy.java:126)
                   ... 114 more
              Caused by: java.lang.IllegalArgumentException: Could not set field value by reflection: AuthenticatorImp.customerManagerImp on: org.domain.checkingnumberbusinessprocess.session.AuthenticatorImp with value: class org.javassist.tmp.java.lang.Object_$$_javassist_2
                   at org.jboss.seam.util.Reflections.set(Reflections.java:86)
                   at org.jboss.seam.Component.setFieldValue(Component.java:1880)
                   ... 142 more
              Caused by: java.lang.IllegalArgumentException: Can not set org.domain.checkingnumberbusinessprocess.session.CustomerManagerImp field org.domain.checkingnumberbusinessprocess.session.AuthenticatorImp.customerManagerImp to org.javassist.tmp.java.lang.Object_$$_javassist_2
                   at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
                   at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
                   at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
                   at java.lang.reflect.Field.set(Unknown Source)
                   at org.jboss.seam.util.Reflections.set(Reflections.java:71)
                   ... 143 more
              



              • 4. Re: Unknown context variable name
                cpopetz

                You can't inject the implementation type, because it's a SLSB.  You have to inject the interface:


                @In(create=true) CustomerManager customerManager;


                If it were a POJO you could do either, though some would consider it bad practice to create the CustomerManager interface but then have the client class (injection point) be aware of the implementation class.

                • 5. Re: Unknown context variable name
                  fshahy

                  Hi Clint


                  Thanks again, you are great.
                  I almost was disappointed to get answer from this forum.

                  • 6. Re: Unknown context variable name
                    devika.nrgh
                    hi i am getting same warning msg.
                    @In(required=false,create=true)
                            EventManagerLocal eventManager;

                    after writing this code.

                    can anybody help me.