8 Replies Latest reply on Aug 1, 2006 3:35 PM by raysonliu

    comp not bound

    raysonliu

      Hi,
      I've been trying the following project on Jboss ( initially from SUN J2EE tutorial ). Depolyment of EJB to Jboss is ok, but when I try the ConverterClient, I got the following error:

      Caught an unexpected exception!
      javax.naming.NameNotFoundException: comp not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      ...



      -------------------------- Source Code start ---------------


      Converter.java

      
      package converter;
      
      import javax.ejb.EJBObject;
      import java.rmi.RemoteException;
      import java.math.*;
      
      public interface Converter extends EJBObject {
       public BigDecimal dollarToYen(BigDecimal dollars) throws RemoteException;
      
       public BigDecimal yenToEuro(BigDecimal yen) throws RemoteException;
      }
      
      



      ConverterHome.java

      package converter;
      
      import java.rmi.RemoteException;
      import javax.ejb.CreateException;
      import javax.ejb.EJBHome;
      
      public interface ConverterHome extends EJBHome {
       Converter create() throws RemoteException, CreateException;
      }
      
      



      ConverterBean.java

      package converter;
      
      import java.rmi.RemoteException;
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;
      import java.math.*;
      
       public class ConverterBean implements SessionBean {
       BigDecimal yenRate = new BigDecimal("121.6000");
       BigDecimal euroRate = new BigDecimal("0.0077");
      
       public BigDecimal dollarToYen(BigDecimal dollars) {
       BigDecimal result = dollars.multiply(yenRate);
       return result.setScale(2,BigDecimal.ROUND_UP);
       }
      
       public BigDecimal yenToEuro(BigDecimal yen) {
       BigDecimal result = yen.multiply(euroRate);
       return result.setScale(2,BigDecimal.ROUND_UP);
       }
      
       public ConverterBean() {}
       public void ejbCreate() {}
       public void ejbPostCreate() {}
       public void ejbRemove() {}
       public void ejbActivate() {}
       public void ejbPassivate() {}
       public void setSessionContext(SessionContext sc) {}
      }
      
      


      ConverbeanHome.java

      
      package converter;
      
       public interface ConverterBeanHome
       extends javax.ejb.EJBHome
      {
       public static final String COMP_NAME="java:comp/env/ejb/ConverterBean";
       public static final String JNDI_NAME="ejb/ConverterBean";
      
       public converter.ConverterBean create()
       throws javax.ejb.CreateException,java.rmi.RemoteException;
      
      }
      


      ejb-jar.xml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      
      <ejb-jar >
      
       <description><![CDATA[No Description.]]></description>
       <display-name>Generated by XDoclet</display-name>
      
       <enterprise-beans>
      
       <!-- Session Beans -->
       <session >
       <description><![CDATA[Description for test]]></description>
       <display-name>Name for test</display-name>
      
       <ejb-name>ConverterBean</ejb-name>
      
       <home>converter.ConverterHome</home>
       <remote>converter.Converter</remote>
       <ejb-class>converter.ConverterBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
      
       </session>
       </enterprise-beans>
      
      </ejb-jar>
      


      jboss.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
      
      <jboss>
       <enterprise-beans>
       <session>
       <ejb-name>ConverterBean</ejb-name>
       <jndi-name>ejb/ConverterBean</jndi-name>
      
       <method-attributes>
       </method-attributes>
       </session>
       </enterprise-beans>
      </jboss>
      



      ConverterClient.java
      
      import converter.Converter;
      import converter.ConverterHome;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.rmi.PortableRemoteObject;
      import java.math.BigDecimal;
      
      
      
      public class ConverterClient {
       public static void main(String[] args) {
       try {
       Context initial = new InitialContext();
       Context myEnv = (Context) initial.lookup("java:comp/env");
       Object objref = myEnv.lookup("ejb/ConverterBean");
      
       ConverterHome home =
       (ConverterHome) PortableRemoteObject.narrow(objref,
       ConverterHome.class);
      
       Converter currencyConverter = home.create();
      
       BigDecimal param = new BigDecimal("100.00");
       BigDecimal amount = currencyConverter.dollarToYen(param);
      
       System.out.println(amount);
       amount = currencyConverter.yenToEuro(param);
       System.out.println(amount);
      
       System.exit(0);
       } catch (Exception ex) {
       System.err.println("Caught an unexpected exception!");
       ex.printStackTrace();
       }
       }
      }
      


      -------------------------- Source Code end ---------------

      Anybody please help, thanks a lot in advance.


        • 1. Re: comp not bound
          peterj

          Try remove the line that reads:

          Context myEnv = (Context) initial.lookup("java:comp/env");


          and change the following line to:

          Object objref = initial.lookup("ejb/ConverterBean");


          • 2. Re: comp not bound
            raysonliu

            I tried this, everything is same except this time it's complaining that ejb not bound, as following:

            Caught an unexpected exception!
            javax.naming.NameNotFoundException: ejb not bound
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
             at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
            


            • 3. Re: comp not bound
              peterj

              Try this. With the EJB deployed, bring up the jmx-console. In the "jboss" namespace click on the link named service=JNDIView. On the reuslting page, scroll down to the list() operation and click on the Invoke button. Search for your EJB on the resulting page and then use that name to look it up.

              • 4. Re: comp not bound
                raysonliu

                Thanks Peter.
                The following is what I got:

                Ejb Module: ConverterAppEJB.jar
                java:comp namespace of the ConverterBean bean:
                 +- env (class: org.jnp.interfaces.NamingContext)
                
                java: Namespace
                 +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
                 +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
                 +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
                 +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
                 +- 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)
                 | +- HsqlDbRealm (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)
                 +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
                 +- Mail (class: javax.mail.Session)
                 +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
                 +- TransactionManager (class: org.jboss.tm.TxManager)
                
                Global JNDI Namespace
                 +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
                 +- jmx (class: org.jnp.interfaces.NamingContext)
                 | +- invoker (class: org.jnp.interfaces.NamingContext)
                 | | +- RMIAdaptor (proxy: $Proxy41 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
                 | +- rmi (class: org.jnp.interfaces.NamingContext)
                 | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
                 +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
                 +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
                 +- ConverterBean (proxy: $Proxy52 implements interface converter.ConverterHome,interface javax.ejb.Handle)
                 +- UserTransactionSessionFactory (proxy: $Proxy12 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
                 +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
                 +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
                 +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
                 +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
                 +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
                 +- 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)
                 +- topic (class: org.jnp.interfaces.NamingContext)
                 | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
                 | +- testTopic (class: org.jboss.mq.SpyTopic)
                 | +- securedTopic (class: org.jboss.mq.SpyTopic)
                 +- console (class: org.jnp.interfaces.NamingContext)
                 | +- PluginManager (proxy: $Proxy42 implements interface org.jboss.console.manager.PluginManagerMBean)
                 +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
                 +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
                 +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
                 +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
                 +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
                
                


                • 5. Re: comp not bound
                  jaikiran

                   

                  +- ConverterBean (proxy: $Proxy52 implements interface converter.ConverterHome,interface javax.ejb
                  .Handle)


                  So your lookup should be:

                  Context ctx = new InitialContext();
                  Object objref = ctx.lookup("ConverterBean");


                  This should work. However, i am surprised as to why your bean was bound to the jndi-name "ConverterBean" instead of "ejb/ConverterBean", which you have mentioned in the jboss.xml as:

                  <jboss>
                   <enterprise-beans>
                   <session>
                   <ejb-name>ConverterBean</ejb-name>
                   <jndi-name>ejb/ConverterBean</jndi-name>
                   <method-attributes>
                   </method-attributes>
                   </session>
                   </enterprise-beans>
                  </jboss>


                  Where are you placing this jboss.xml file(just wanted to make sure that the server is picking up this file during deployment)


                  • 6. Re: comp not bound
                    raysonliu

                    Thanks, but it's becoming worse, the JVM launcher crashed and I got the following error:

                    java.lang.UnsupportedClassVersionError: converter/ConverterHome (Unsupported major.minor version 49.0)
                     at java.lang.ClassLoader.defineClass0(Native Method)
                     at java.lang.ClassLoader.defineClass(Unknown Source)
                    ....................
                    


                    Thanks,

                    • 7. Re: comp not bound
                      peterj

                      You apparently compiled some of your code with the 5.0 JVM and are now trying to run it with the 1.4.2 JVM. Either recompile (and redeploy) using 1.4.2, or run using 5.0.

                      • 8. Re: comp not bound
                        raysonliu

                        You are right Peter, it's my mistake.
                        Thank you all for your help!