12 Replies Latest reply on Jun 24, 2011 9:27 AM by kgoedert

    inject remote ejb reference

    kgoedert

      Hello,


      I need to inject a ejb remote reference in a bean. I'm trying to use something like this


      @Produces @EJB(ejbLink="../their.jar#PaymentService")

      PaymentService paymentService


      But I seem to be using the wrong import, because eclipse keeps pointing me that ejbLink is not a valid attribute to EJB annotation. Which jar should I import? Or should I use some other attribute to reference the bean?


      Thanks


      Kelly

        • 1. Re: inject remote ejb reference
          lightguard

          According to the docs there is no ejbLink. Try one of the others.

          • 2. Re: inject remote ejb reference
            kgoedert

            Thanks for replying.


            I already tried all the other possibilities and none of them worked :(

            • 3. Re: inject remote ejb reference
              lightguard

              Can you find the EJB manually via a JNDI lookup?

              • 4. Re: inject remote ejb reference
                kgoedert

                Yes. This works for me:




                Context ctx;
                 try {
                      ctx=new InitialContext();
                      login=(LoginRemote) ctx.lookup("LoginModel/remote");
                      } catch (NamingException e) {
                          e.printStackTrace();
                 }





                But as I was reading the weld documentation I decided to try the @Produces @EJB(ejbLink="...") example

                • 5. Re: inject remote ejb reference
                  lightguard

                  @Produces @EJB(lookup="LoginModel/remote") doesn't work?

                  • 6. Re: inject remote ejb reference
                    kgoedert

                    No, it didn't. Can it be because the LoginModel/remote bean is in another .ear? Anyway, I thought this should have worked to. I expected the lookup attribute to have the same effect as ctx.lookup(...)

                    • 7. Re: inject remote ejb reference
                      lightguard

                      That's what I would have thought as well. Which version of AS or you running on, or Glassfish?


                      Also try a more fully qualified JNDI name like java:comp/LoginModel/remote or one of the EE6 names.

                      • 8. Re: inject remote ejb reference
                        meetoblivion

                        You may have conflicting issues here.


                        If you did @EJB(lookup="LoginModel/remote") LoginRemote loginRemote;  in your code, does it resolve correctly? is the reference not null?

                        • 9. Re: inject remote ejb reference
                          kgoedert

                          Hi,


                          I'm out of the office for the day. But tomorrow I give it try.


                          I'm running on a jboss 6.0.0.Final.


                          Thanks

                          • 10. Re: inject remote ejb reference
                            kgoedert

                            Hi,


                            I tried  @EJB(lookup="LoginModel/remote") again, and also a more qualified name like @EJB(lookup="java:comp/LoginModel/remote"). In both cases I get this stack trace



                            ERROR [org.jboss.seam.security.IdentityImpl] Login failed: java.lang.RuntimeException: org.jboss.ejb3.ejbref.resolver.spi.UnresolvableReferenceException: Could not resolve reference [EJB Reference: beanInterface 'my.package.login.LoginRemote', beanName '', mappedName 'null'] in AbstractVFSDeploymentContext@863689804{vfs:///usr/local/jboss-6.0.0.Final/server/all/deploy/mywar.war}
                                 at org.jboss.seam.security.IdentityImpl.authenticate(IdentityImpl.java:329) [:3.0.0.Final]
                                 at org.jboss.seam.security.IdentityImpl.login(IdentityImpl.java:229) [:3.0.0.Final]
                                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
                                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_24]
                                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_24]
                                 at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_24]
                                 at org.apache.el.parser.AstValue.invoke(AstValue.java:196) [:6.0.0.Final]
                                 at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) [:6.0.0.Final]
                                 at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43) [:6.0.0.Final]
                                 at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56) [:6.0.0.Final]
                                 at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:43) [:6.0.0.Final]
                                 at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:56) [:6.0.0.Final]
                                 at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102) [:2.0.3-]
                                 at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84) [:2.0.3-]
                                 at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) [:2.0.3-]
                                 at javax.faces.component.UICommand.broadcast(UICommand.java:311) [:2.0.3-]
                                 at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) [:2.0.3-]
                                 at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) [:2.0.3-]
                                 at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) [:2.0.3-]
                                 at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) [:2.0.3-]
                                 at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) [:2.0.3-]
                                 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) [:2.0.3-]
                                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final]
                                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
                                 at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [:6.0.0.Final]
                                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final]
                                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final]
                                 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final]
                                 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final]
                                 at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]
                                 at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
                                 at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
                                 at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]
                                 at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]
                                 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]
                                 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]
                                 at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]
                                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]
                                 at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]
                                 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]
                                 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final]
                                 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final]
                                 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]
                                 at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]
                            Caused by: org.jboss.ejb3.ejbref.resolver.spi.UnresolvableReferenceException: Could not resolve reference [EJB Reference: beanInterface 'my.package.login.LoginRemote', beanName '', mappedName 'null'] in AbstractVFSDeploymentContext@863689804{vfs:///usr/local/jboss-6.0.0.Final/server/all/deploy/mywar.war}
                                 at org.jboss.ejb3.ejbref.resolver.ejb30.impl.ScopedEJBReferenceResolver.resolveEjb(ScopedEJBReferenceResolver.java:80) [:6.0.0.Final]
                                 at org.jboss.weld.integration.ejb.JBossEjbInjectionServices.resolveEjb(JBossEjbInjectionServices.java:68) [:6.0.0.Final]
                                 at org.jboss.weld.util.Beans.injectEEFields(Beans.java:772) [:6.0.0.Final]
                                 at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1$1.proceed(ManagedBean.java:181) [:6.0.0.Final]
                                 at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:54) [:6.0.0.Final]
                                 at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1.work(ManagedBean.java:176) [:6.0.0.Final]
                                 at org.jboss.weld.bean.ManagedBean$FixInjectionPoint.run(ManagedBean.java:142) [:6.0.0.Final]
                                 at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.inject(ManagedBean.java:170) [:6.0.0.Final]
                                 at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:339) [:6.0.0.Final]
                                 at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:67) [:6.0.0.Final]
                                 at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:669) [:6.0.0.Final]
                                 at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:707) [:6.0.0.Final]
                                 at org.jboss.seam.security.IdentityImpl.getReferences(IdentityImpl.java:493) [:3.0.0.Final]
                                 at org.jboss.seam.security.IdentityImpl.lookupAuthenticator(IdentityImpl.java:456) [:3.0.0.Final]
                                 at org.jboss.seam.security.IdentityImpl.authenticate(IdentityImpl.java:297) [:3.0.0.Final]
                                 ... 43 more
                            



                            • 11. Re: inject remote ejb reference
                              pchevill.paulin.chevillon.gmail.com

                              I'm facing the same situation, and I found something about security unsig @ENB annotation on Jboss 5, 6 :


                              Migrating to JBoss 5.1 and JBoss 6 from JBoss 4.2.X


                              The interesting part is :



                              Injecting 'external' EJBs
                              Applies to: JBoss 5.1 and JBoss 6
                              JBoss 4.2.3 is quite forgiving when it comes to performing EJB injections using the @EJB annotation. If classpath isolation is turned off (which it is by default), you can even inject EJBs that are not part of your EAR and can even be packaged inside another EAR.

                              No so any more under JBoss 5.1 or JBoss 6; the injection will fail. JBoss 5.1 will even give a NullPointerException upon deployment (which is a bug fixed in JBoss 6). Fact of the matter is that it is against the EJB specifications to be able to do so; EJBs should only be visible within their own protected little environment (the EJB module or EAR they are part of). If you want to communicate with the EJB from outside that protected environment, you give the EJB a remote interface and you do a JNDI lookup.


                              This could explain why the old method still works.


                              Regards,
                              Paulin

                              • 12. Re: inject remote ejb reference
                                kgoedert

                                Yes, I guess it explains it.


                                Thanks for your help!


                                Kelly