4 Replies Latest reply on Aug 20, 2002 11:00 AM by Adrian Brock

    getting localhome from external war in the same VM fails:add

    alskdjfa Newbie

      ** MY GOAL:
      Get via JNDI, a local home of an EJB from a .war external to the target ejb's .jar, but residing in the same container.


      ** PROBLEM ENCOUNTERED:
      org.jboss.deployment.DeploymentException: ejb-local-ref: ejb/appName/beanName, target not found, add valid ejb-link [...]


      ** PREVIOUS POSTS ABOUT THE TOPIC:
      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ got it working but with the .war within the .jar
      -frank proposed something for accessing ejb outside the .jar: not to bind the ejb in web.xml/jboss-web.xml at all and call it via the jndi name local/[ejb name]. I tried and JNDI sait "local not bound", and I can see in the JNDI tree that local context is not there...

      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ post is about exactly the same problem then mine, but is unaswered.

      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ situation than first thread link

      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ very helpful


      ** QUESTIONS/REQUESTS
      - Could someone post in this thread a working example of a servlet accessing an EJB residing in a different jar but in the same VM, with ejb-jar.xml, jboss-web.xml, web client's java source (JNDI lookup part), web.xml, jboss.xml? I can see that other people had the same problem, and this thread could become a reference for those who experience the same problem in the future if we could get a workable example.

      - The <ejb-link> tag is the one I am the most uncertain. I saw two syntax: <ejb-link>[bean name]</ejb-link> and <ejb-link>[path-to-.jar]#[bean name]</ejb-link>. Why there is 2 syntaxes? When should we use the first and when the other? The tag is optional, why? When should we use it, and when we should't? I read the path-to-.jar is relative to .war, but if I have:
      -+-MyEJBs.jar
      |
      +-MyWebApp.war
      Should I write ../MyEJB.jar or MyEJB.jar (or, on win32 ..\\MyEJB.jar or ..\MyEJB.jar)?

      - Any idea why my ejb is not bound to "local/[ejb name]" context by default?

      - A more "theorical" question: the container already got the jndi name in jboss-web.xml, why does it need a <ejb-link>?


      ** NOTES
      Thank you in advance for your help. Feel free to check my tests. When I tried many possibilities, they are in comments to show you what I have tried.


      ** SOURCE: web.xml
      ...
      <ejb-local-ref>
      <ejb-ref-name>ejb/ciscoipphonenetworkweb/Telephone</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>ca.bell.iptelephony.ciscoipphonenetwork.interfaces.TelephoneLocalHome</local-home>
      ca.bell.iptelephony.ciscoipphonenetwork.interfaces.TelephoneLocal
      <!-- <ejb-link>ciscoipphonenetwork/Telephone</ejb-link> -->
      <!-- <ejb-link>ejb-ciscoipphonenetwork-1.1.jar#ciscoipphonenetwork/Telephone</ejb-link> -->
      <ejb-link>C:\\jboss-3.0.0\\server\\default\\deploy\\ejb-ciscoipphonenetwork-1.1.jar#ciscoipphonenetwork/Telephone</ejb-link>
      </ejb-local-ref>
      ...


      ** SOURCE: jboss-web.xml
      ...
      <ejb-ref>
      <ejb-ref-name>ejb/ciscoipphonenetworkweb/Telephone</ejb-ref-name>
      <jndi-name>ejb/ciscoipphonenetwork/Telephone</jndi-name>
      </ejb-ref>
      ...


      ** SOURCE: ejb-jar.xml
      ...

      <![CDATA[An IP telephone representation]]>
      <display-name>An IP telephone representation</display-name>

      <ejb-name>ciscoipphonenetwork/Telephone</ejb-name>

      <local-home>ca.bell.iptelephony.ciscoipphonenetwork.interfaces.TelephoneLocalHome</local-home>
      ca.bell.iptelephony.ciscoipphonenetwork.interfaces.TelephoneLocal

      <ejb-class>ca.bell.iptelephony.ciscoipphonenetwork.entity.TelephoneCMP</ejb-class>
      ...


      ** SOURCE: jboss.xml
      ...

      <ejb-name>ciscoipphonenetwork/Telephone</ejb-name>
      <local-jndi-name>ejb/ciscoipphonenetwork/Telephone</local-jndi-name>

      ...


      ** SOURCE: JNDI lookup
      ...
      try
      {
      Context ctx = new InitialContext();
      TelephoneLocalHome telephoneLocalHome = (TelephoneLocalHome)ctx.lookup("java:comp/env/ejb/ciscoipphonenetworkweb/Telephone");
      //TelephoneLocalHome telephoneLocalHome = (TelephoneLocalHome)ctx.lookup("local/ciscoipphonenetwork/Telephone");

        • 1. Re: getting localhome from external war in the same VM fails
          Adrian Brock Master

          If you are are using separate packaging, you can
          forget <ejb-local-ref>

          You have bound your local interface into global jndi here:
          <local-jndi-name>ejb/ciscoipphonenetwork/Telephone</local-jndi-name>

          Your code should be:

          new InitialContext().lookup("ejb/ciscoipphonenetwork/Telephone");

          Regards,
          Adrian

          • 2. Re: getting localhome from external war in the same VM fails
            Tom Baeyens Master

            have you tried te following already ?

            TelephoneLocalHome telephoneLocalHome = (TelephoneLocalHome)ctx.lookup("local/Telephone");

            • 3. Re: getting localhome from external war in the same VM fails
              alskdjfa Newbie

              Thank you for your advice... but it still doesnt work.

              I tested the following configs and I got a not bound exception when trying to get an instance of the ejb. I also pasted a copy of my JNDI tree at the end. Take a look if you have 2 mintes. I would be very grateful.


              ** SOURCE: servlet getting an instance of the bean (TEST1)
              try
              {
              Context ctx = new InitialContext();
              TelephoneLocalHome telephoneLocalHome = (TelephoneLocalHome)ctx.lookup("ejb/ciscoipphonenetwork/Telephone");


              ** SOURCE: servlet getting an instance of the bean (TEST2)
              try
              {
              Context ctx = new InitialContext();
              TelephoneLocalHome telephoneLocalHome = (TelephoneLocalHome)ctx.lookup("local/Telephone");


              ** SOURCE: servlet getting an instance of the bean (TEST3)
              try
              {
              Context ctx = new InitialContext();
              TelephoneLocalHome telephoneLocalHome = (TelephoneLocalHome)ctx.lookup("local/ciscoipphonenetwork/Telephone");


              ** SOURCE: jboss-web.xml (I removed references to Telephone)
              ...
              <!--
              <ejb-ref>
              <ejb-ref-name>ejb/ciscoipphonenetworkweb/Telephone</ejb-ref-name>
              <jndi-name>ejb/ciscoipphonenetwork/Telephone</jndi-name>
              </ejb-ref>
              -->
              ...


              ** SOURCE: web.xml ( I removed references to Telephone)
              <!--
              <ejb-local-ref>
              <ejb-ref-name>ejb/ciscoipphonenetworkweb/Telephone</ejb-ref-name>
              <ejb-ref-type>Entity</ejb-ref-type>
              <local-home>ca.bell.iptelephony.ciscoipphonenetwork.interfaces.TelephoneLocalHome</local-home>
              ca.bell.iptelephony.ciscoipphonenetwork.interfaces.TelephoneLocal
              <ejb-link>C:\\jboss-3.0.0\\server\\default\\deploy\\ejb-ciscoipphonenetwork-1.1.jar#ciscoipphonenetwork/Telephone</ejb-link>
              </ejb-local-ref>
              -->


              ** SOURCE: ejb-jar.xml, jboss.xml unchanged


              ** COPY OF MY JNDI TREE:
              Ejb Module: file%/C%/jboss-3.0.0/server/default/deploy/ejb-management.jar
              java:comp namespace of the MEJB bean:

              +- env (class: org.jnp.interfaces.NamingContext)
              | +- Server-Name (class: java.lang.String)

              Ejb Module: file%/C%/jboss-3.0.0/server/default/deploy/jmx-ejb-adaptor.jar
              java:comp namespace of the jmx/ejb/Adaptor bean:

              +- env (class: org.jnp.interfaces.NamingContext)
              | +- Server-Name (class: java.lang.String)

              Ejb Module: file%/C%/jboss-3.0.0/server/default/deploy/ejb-ciscoipphonenetwork-1.1.jar
              java:comp namespace of the ciscoipphonenetwork/UUID bean:

              +- env (class: org.jnp.interfaces.NamingContext)

              java:comp namespace of the ciscoipphonenetwork/Telephone bean:

              +- env (class: org.jnp.interfaces.NamingContext)
              | +- ejb (class: org.jnp.interfaces.NamingContext)
              | | +- ciscoipphonenetwork (class: org.jnp.interfaces.NamingContext)
              | | | +- UUID[link -> ejb/ciscoipphonenetwork/UUID] (class: javax.naming.LinkRef)

              java: Namespace

              +- DefaultDS (class: org.jboss.resource.adapter.jdbc.local.LocalDataSource)
              +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
              +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
              +- DefaultJMSProvider (class: org.jboss.jms.jndi.JBossMQProvider)
              +- CounterService (class: org.jboss.varia.counter.CounterService)
              +- MySqlDS (class: org.jboss.resource.adapter.jdbc.local.LocalDataSource)
              +- comp (class: javax.naming.Context)
              +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
              +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
              +- jaas (class: javax.naming.Context)
              | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
              | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
              +- timedCacheFactory (class: javax.naming.Context)
              Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy
              +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
              +- Mail (class: javax.mail.Session)
              +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
              +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
              +- TransactionManager (class: org.jboss.tm.TxManager)

              Global JNDI Namespace

              +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
              +- UserTransactionSessionFactory (class: org.jboss.tm.usertx.server.UserTransactionSessionFactoryImpl)
              +- RMIXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
              +- topic (class: org.jnp.interfaces.NamingContext)
              | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
              | +- testTopic (class: org.jboss.mq.SpyTopic)
              | +- securedTopic (class: org.jboss.mq.SpyTopic)
              +- queue (class: org.jnp.interfaces.NamingContext)
              | +- A (class: org.jboss.mq.SpyQueue)
              | +- testQueue (class: org.jboss.mq.SpyQueue)
              | +- ex (class: org.jboss.mq.SpyQueue)
              | +- DLQ (class: org.jboss.mq.SpyQueue)
              | +- D (class: org.jboss.mq.SpyQueue)
              | +- C (class: org.jboss.mq.SpyQueue)
              | +- B (class: org.jboss.mq.SpyQueue)
              +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
              +- RMIConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
              +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
              +- ejb (class: org.jnp.interfaces.NamingContext)
              | +- mgmt (class: org.jnp.interfaces.NamingContext)
              | | +- MEJB (proxy: $Proxy19 implements interface javax.management.j2ee.ManagementHome,interface javax.ejb.Handle)
              | +- jmx (class: org.jnp.interfaces.NamingContext)
              | | +- ejb (class: org.jnp.interfaces.NamingContext)
              | | | +- Adaptor (proxy: $Proxy23 implements interface org.jboss.jmx.adaptor.interfaces.AdaptorHome,interface javax.ejb.Handle)
              | +- ciscoipphonenetwork (class: org.jnp.interfaces.NamingContext)
              | | +- Telephone (proxy: $Proxy29 implements interface ca.bell.iptelephony.ciscoipphonenetwork.interfaces.TelephoneLocalHome)
              | | +- UUID (proxy: $Proxy30 implements interface ca.bell.iptelephony.ciscoipphonenetwork.interfaces.UUIDHome,interface javax.ejb.Handle)
              +- invokers (class: org.jnp.interfaces.NamingContext)
              | +- cmzcrz (class: org.jnp.interfaces.NamingContext)
              | | +- jrmp (class: org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy)
              +- jmx:cmzcrz:rmi (class: org.jboss.jmx.adaptor.rmi.RMIAdaptorImpl)
              +- UILXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
              +- UILConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)

              • 4. Re: getting localhome from external war in the same VM fails
                Adrian Brock Master

                Test1 should work.

                Try looking up something else. Just to make sure
                you are looking in the correct jndi config.

                Regards,
                Adrian