0 Replies Latest reply on Mar 5, 2010 9:29 PM by Rafael Ribeiro

    EJB injection in WebSphere 6.1

    Rafael Ribeiro Novice

      Hi all,


      I was trying to achieve EJB injection on a Seam application running on WebSphere 6.1 Network Deployment. My application is packaged as an EAR with all dependencies (Mojarra, Richfaces, Seam, ...) on a lib folder under EAR root so I can reference them through MANIFEST.MF of each deployed module. I've also configured the Web module to use a classloader configured for PARENT_LAST so I guarantee that the libraries packaged inside the EAR will have priority over the ones on the application server.
      In order to be able to do local lookups I've configured the EJB references accordingly in web.xml (code below):


           <ejb-local-ref id="rar-local">
                <description>ejb/RarBean/local</description>
                <ejb-ref-name>ejb/RarBean/local</ejb-ref-name>
                <local>br.com.rar.ejb.api.RarLocal</local>
           </ejb-local-ref>
      
           <ejb-ref id="rar-remote">
                <description>ejb/RarBean/remote</description>
                <ejb-ref-name>ejb/RarBean/remote</ejb-ref-name>
                <remote>br.com.rar.ejb.api.RarRemote</remote>
           </ejb-ref>



      and binded then using WebSphere proprietary ibm-web-bnd.xmi.
      The backing bean related to the view that was used on these tests was coded at first as follows:


      package foo.bar;
      
      import java.rmi.RemoteException;
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.ejb.CreateException;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.rmi.PortableRemoteObject;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.TransactionPropagationType;
      import org.jboss.seam.annotations.Transactional;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.international.StatusMessage.Severity;
      import org.primefaces.event.ItemSelectEvent;
      
      import br.com.rar.ejb.api.RarRemote;
      import br.com.rar.ejb.api.RarRemoteHome;
      
      @Name("chart")
      public class ChartBean {
           @In(create = true)
           FacesMessages facesMessages;
      
              @In(create = true)
           private RarRemote rarBean;
      
      



      Then I first attempted to render the view in question using a Remote reference being injected by Seam which led me to configure components.xml as follows:


      <core:init transaction-management-enabled="false" debug="true"
                jndi-pattern="java:comp/env/ejb/#{ejbName}/remote" />



      This led me to the following exception:


      Caused by: java.lang.IllegalArgumentException: value of context variable is not an instance of the component bound to the context variable: rarBean. If you are using hot deploy, you may have attempted to hot deploy a session or application-scoped component definition while using an old instance in the session.




      My next attempt was to perform the local lookup which required changing the code fragment above to become like it is below:


      <core:init transaction-management-enabled="false" debug="true"
                jndi-pattern="java:comp/env/ejb/#{ejbName}/local" />



      Then I tried again to render the view and this time I got the following error (sorry for the pt_BR locale error messages):


      [05/03/10 09:19:51:851 BRT] 0000002c Helpers       W   NMSV0610I: Uma NamingException está sendo emitida a partir de uma implementação javax.naming.Context. Seguem os detalhes
      Implementação do contexto: com.ibm.ws.naming.jndicos.CNContextImpl
      Método do contexto: lookupExt
      Nome do contexto: cpqd051728Cell01/clusters/dcachecluster
      Nome do destino: local:ejb/ejb/RarBean
      Outros dados: ""
      Rastreio da Pilha de exceção: javax.naming.ConfigurationException: NamingManager.getURLContext cannot find the factory for this scheme: local
           at com.ibm.ws.naming.jndicos.CNContextImpl.checkForUrlContext(CNContextImpl.java:3290)
           at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1549)
           at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory$1.run(IndirectJndiLookupObjectFactory.java:372)
           at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
           at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory.getObjectInstanceExt(IndirectJndiLookupObjectFactory.java:221)
           at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:893)
           at com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:191)
           at com.ibm.ws.naming.java.javaURLContextRoot.processBoundObjectForLookup(javaURLContextRoot.java:407)
           at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1280)
           at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:384)
           at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:205)
           at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:145)
           at javax.naming.InitialContext.lookup(InitialContext.java:363)
           at org.jboss.seam.Component.instantiateSessionBean(Component.java:1400)
      [... a long trace then another interesting part]
      [05/03/10 09:19:52:054 BRT] 0000002c Helpers       W   NMSV0605W: Um objeto javax.naming.Reference consultado a partir do contexto "java:" com o nome "comp/env/ejb/RarBean/local" foi enviado ao Gerenciador de Nomenclatura JNDI e resultou em uma exceção. Seguem os dados de Referência:
      Nome de Classe do Depósito de Informações do Provedor de Referência: com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory
      URLs da Localização da Classe do Depósito de Informações do Provedor de Referência: <null>
      Reference Class Name: java.lang.Object
      Type: JndiLookupInfo
      Content: JndiLookupInfo: jndiName="local:ejb/ejb/RarBean"; providerURL=""; initialContextFactory=""
      
      Seguem os dados de exceção:
      javax.naming.ConfigurationException: NamingManager.getURLContext cannot find the factory for this scheme: local
           at com.ibm.ws.naming.jndicos.CNContextImpl.checkForUrlContext(CNContextImpl.java:3290)
           at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1549)
           at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory$1.run(IndirectJndiLookupObjectFactory.java:372)
           at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
           at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory.getObjectInstanceExt(IndirectJndiLookupObjectFactory.java:221)
           at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:893)
           at com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:191)
           at com.ibm.ws.naming.java.javaURLContextRoot.processBoundObjectForLookup(javaURLContextRoot.java:407)
           at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1280)
           at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:384)
           at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:205)
           at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:145)
           at javax.naming.InitialContext.lookup(InitialContext.java:363)
           at org.jboss.seam.Component.instantiateSessionBean(Component.java:1400)
      [... another long trace then another interesting part]
      [05/03/10 09:19:52:086 BRT] 0000002c Helpers       W   NMSV0610I: Uma NamingException está sendo emitida a partir de uma implementação javax.naming.Context. Seguem os detalhes
      Implementação do contexto: com.ibm.ws.naming.java.javaURLContextRoot
      Método do contexto: lookup(Name)
      Nome do contexto: java:
      Nome do destino: comp/env/ejb/RarBean/local
      Outros dados: ""
      Rastreio da Pilha de exceção: com.ibm.websphere.naming.CannotInstantiateObjectException: Exception occurred while the JNDI NamingManager was processing a javax.naming.Reference object. [Root exception is javax.naming.ConfigurationException: NamingManager.getURLContext cannot find the factory for this scheme: local]
           at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:1000)
           at com.ibm.ws.naming.urlbase.UrlContextHelper.processBoundObjectForLookup(UrlContextHelper.java:191)
           at com.ibm.ws.naming.java.javaURLContextRoot.processBoundObjectForLookup(javaURLContextRoot.java:407)
           at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1280)
           at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:384)
           at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:205)
           at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:145)
           at javax.naming.InitialContext.lookup(InitialContext.java:363)
           at org.jboss.seam.Component.instantiateSessionBean(Component.java:1400)
      [... last long trace part]
      Caused by: javax.naming.ConfigurationException: NamingManager.getURLContext cannot find the factory for this scheme: local
           at com.ibm.ws.naming.jndicos.CNContextImpl.checkForUrlContext(CNContextImpl.java:3290)
           at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1549)
           at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory$1.run(IndirectJndiLookupObjectFactory.java:372)
           at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
           at com.ibm.ws.naming.util.IndirectJndiLookupObjectFactory.getObjectInstanceExt(IndirectJndiLookupObjectFactory.java:221)
           at com.ibm.ws.naming.util.Helpers.processSerializedObjectForLookupExt(Helpers.java:893)
           ... 105 more
      



      Strangely enough if I change the bean code to do a manual lookup as follows everything works just fine:


                try {
                     Object o = new InitialContext().lookup("java:comp/env/ejb/RarBean/remote");
                     RarRemoteHome home = (RarRemoteHome) PortableRemoteObject.narrow(o, RarRemoteHome.class); 
                     rarBean = home.create();
                     rarBean.sysout();
                } catch (RemoteException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                } catch (NamingException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                } catch (CreateException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
                }
      
      



      Is there any chance Seam is doing anything wrong in this lookup or it is just that Seam does not support what I am trying to achieve?