5 Replies Latest reply on May 16, 2005 4:11 PM by Doug Glassman

    javax.naming.NameNotFoundException: CatalogBean not bound

    mamat ghislain Newbie

      good morning, i have a Javax.NamingNotFoundException in my test class of session bean CatalogBean and I can't resolved this problem
      can you help me?

      I use : Jboss 3.0.8 in eclipse.

      My test catalogBean is :

      package com.session.catalog;
      
      import javax.ejb.SessionBean;
      import com.cmp.*;
      import javax.ejb.*;
      import java.util.*;
      import com.util.*;
      
      /**
       * @ejb.bean name="Catalog"
       * jndi-name="CatalogBean"
       * type="Stateless"
       *
       * @ejb.ejb-ref ejb-name="Book"
       * view-type="local"
       * ref-name="BookLocal"
       *
       * @jboss.ejb-ref-jndi ref-name="BookLocal"
       * jndi-name="BookLocal"
       *--
       * This is needed for JOnAS.
       * If you are not using JOnAS you can safely remove the tags below.
       * @jonas.bean ejb-name="Catalog"
       * jndi-name="CatalogBean"
       *
       *--
       **/
      
      public abstract class CatalogBean implements SessionBean {
       protected SessionContext ctx;
       private BookLocalHome blHome;
      
       /**
       * The ejbCreate Method
       * @ejb.create-method
       *
       **/
       public void ejbCreate() throws javax.ejb.CreateException
       {
       try{
       blHome=BookUtil.getLocalHome();
       }
       catch(Exception e){
       e.printStackTrace();
       }
       }
      
       public void setSessionContext(javax.ejb.SessionContext ctx)
       {
       this.ctx=ctx;
       }
      
       public void unsetSessionContext()
       {
       this.ctx=null;
       }
       /**
       * @ejb.interface-method
       * view-type="remote"
       **/
       public void createProduct(String bookID, String type, String title,Double price ,String author) throws javax.ejb.CreateException
       {
       if(bookID==null)
       throw new CreateException("requerid bookID");
       blHome.create(bookID, type,title, price, author);
      
       }
       /**
       * @ejb.interface-method
       * view-type="remote"
       **/
       public BookData getBookData(String bookID){
       BookData bd =null;
       try{
       BookLocal myBook = blHome.findByPrimaryKey(bookID);
       if(myBook!=null){
       bd = myBook.getBookData();
       }
       }
       catch(Exception e){
       e.printStackTrace();
       }
       return bd;
       }
      
       /**
       * @ejb.interface-method
       * view-type="remote"
       **/
       public Vector searchProductsBook(String criteria, String keyWord)
       {
       keyWord = keyWord.toLowerCase();
       Collection result = null;
       System.out.println("Catalog:searchProduct in");
       try{
       if (criteria.equals("type"))
       result = (Vector)blHome.findByType("%"+keyWord+"%");
       System.out.println("Catalog:searchProduct out");
       return BookToItem(result);
       }
       catch(FinderException e){
       return null;
       }
       catch(NumberFormatException e){
       return null;
       }
       catch(Exception e){
       throw new EJBException(e.getMessage());
       }
       }
       /**
       * @ejb.interface-method
       * view-type="remote"
       **/
       private Vector BookToItem(Collection products)
       {
       Iterator i = products.iterator();
       Vector res = new Vector();
       while(i.hasNext()){
       BookLocal p = (BookLocal) i.next();
       try{
       System.out.println("Catalog:Product->Item:"+p.getTitle());
       res.addElement(new Item(p.getBookID(), p.getTitle(),p.getAuthor(), p.getPrice()));
       }
       catch(Exception e){
       throw new EJBException(e.getMessage());
       }
       }
       return res;
      
       }
      
      }
      


      The test class client is :
      package com.test;
      
      import java.rmi.RemoteException;
      import java.util.Hashtable;
      
      import javax.ejb.CreateException;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      //import java.util.*;
      //import com.cmp.*;
      //import com.util.*;
      
      /**
       * @author Administrateur
       *
       * To change the template for this generated type comment go to
       * Window>Preferences>Java>Code Generation>Code and Comments
       */
      public class Test {
      
       private com.session.catalog.CatalogHome getHome() throws NamingException{
      
       return (com.session.catalog.CatalogHome) getContext().lookup(
       com.session.catalog.CatalogHome.JNDI_NAME);
       }
       private InitialContext getContext() throws NamingException {
       Hashtable props = new Hashtable();
      
       props.put(
       InitialContext.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
       props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
      
       // This establishes the security for authorization/authentication
       // props.put(InitialContext.SECURITY_PRINCIPAL,"username");
       // props.put(InitialContext.SECURITY_CREDENTIALS,"password");
      
       InitialContext initialContext = new InitialContext(props);
       return initialContext;
       }
       public void testBean() {
      
       try {
       com.session.catalog.Catalog myBean = getHome().create();
      
       //--------------------------------------
       //This is the place you make your calls.
       //myBean.createProduct("B0005","INFO","J2EE par la pratique",new Double(958.2),"Ghislain M");
       System.out.println(myBean.getBookData("B0000"));
       //System.out.println(myBean.callYourMethod());
      
       /*Iterator iter = null;
       Vector items = null;
       items=myBean.searchProductsBook("type","BIB");
       iter = items.iterator();
       while(iter.hasNext())
       {
       Item data =(Item)iter.next();
       System.out.println("Reference :"+data.getRef());
       System.out.println("Titre :"+data.getTitle());
       System.out.println("Auteur :"+data.getAuthor());
       System.out.println("Prix :"+data.getPrice());
       }*/
      
      
       } catch (RemoteException e) {
       e.printStackTrace();
       } catch (CreateException e) {
       e.printStackTrace();
       } catch (NamingException e) {
       e.printStackTrace();
       }
       }
      
       public static void main(String[] args) {
       Test test = new Test();
       test.testBean();
      
       }
      }
      


      the error message is:

      javax.naming.NameNotFoundException: CatalogBean not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:282)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:534)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:493)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:472)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at com.test.Test.getHome(Test.java:29)
      at com.test.Test.testBean(Test.java:50)
      at com.test.Test.main(Test.java:83)