1 Reply Latest reply on Oct 15, 2007 10:07 AM by Tom Clifford

    Ex 5 client 4 is not working..help required

    Mahtab Singh Newbie

      Hi,

      The following is the error:


      javax.naming.NameNotFoundException: com.titan.travelagent.TravelAgentRemote not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
      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:585)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
      at sun.rmi.transport.Transport$1.run(Transport.java:153)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
      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:595)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
      at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
      at sun.rmi.server.UnicastRef.invoke(Unknown Source)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at com.titan.clients.Client_4.main(Client_4.java:29)



      The Bean is:

      package com.titan.travelagent;

      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.PersistenceContext;
      import javax.persistence.PersistenceUnit;
      import javax.persistence.FlushModeType;

      import com.titan.domain.Cabin;

      @Stateless
      public class TravelAgentBean implements TravelAgentRemote
      {
      @PersistenceUnit(unitName="Test") private EntityManagerFactory factory;
      @PersistenceContext(unitName="Test") private EntityManager manager;

      public void createCabin(Cabin cabin)
      {
      manager.persist(cabin);
      }

      public Cabin findCabin(int pKey)
      {
      return manager.find(Cabin.class, pKey);
      }

      public void updateCabin(Cabin cabin)
      {
      manager.merge(cabin);
      }

      public void flushModeExample()
      {
      EntityManager createdManager = factory.createEntityManager();

      try
      {
      Cabin newCabin2 = new Cabin();
      newCabin2.setId(2);
      newCabin2.setName("Another Cabin");
      newCabin2.setBedCount(1);
      createdManager.persist(newCabin2);

      System.out.println("hello");
      Cabin cabin2 = manager.find(Cabin.class, 2);
      if (cabin2 != null)
      {
      throw new RuntimeException("newCabin2 should not be flushed yet");
      }

      Cabin cabin1 = (Cabin)createdManager.createQuery("FROM Cabin c WHERE c.id = 1").getSingleResult();

      cabin2 = manager.find(Cabin.class, 2);
      if (cabin2 == null)
      {
      throw new RuntimeException("newCabin2 should be flushed now");
      }

      createdManager.setFlushMode(FlushModeType.COMMIT);
      newCabin2.setBedCount(99);

      cabin1 = (Cabin)createdManager.createQuery("FROM Cabin c WHERE c.id = 1").getSingleResult();

      manager.refresh(cabin2);
      if (cabin2.getBedCount() == 99)
      {
      throw new RuntimeException("should not be 99 yet with COMMIT and a query");
      }

      createdManager.flush();

      manager.refresh(cabin2);
      if (cabin2.getBedCount() != 99)
      {
      throw new RuntimeException("should be 99 yet with a flush");
      }
      }
      finally
      {
      createdManager.close();
      }
      }
      }


      The business Interface is:


      package com.titan.travelagent;

      import javax.ejb.Remote;

      import com.titan.domain.Cabin;

      @Remote
      public interface TravelAgentRemote
      {
      public void createCabin(Cabin cabin) throws java.rmi.RemoteException;
      public Cabin findCabin(int pKey) throws java.rmi.RemoteException;
      public void updateCabin(Cabin cabin) throws java.rmi.RemoteException;
      public void flushModeExample() throws java.rmi.RemoteException;
      }


      The Client code is:



      package com.titan.clients;

      import java.util.Properties;

      import com.titan.travelagent.TravelAgentRemote;
      import com.titan.domain.Cabin;

      import javax.naming.InitialContext;
      import javax.naming.Context;
      import javax.naming.NamingException;

      import javax.rmi.PortableRemoteObject;

      public class Client_4
      {
      public static void main(String [] args)
      {
      try
      {
      Properties p = new Properties( );
      p.put(Context.INITIAL_CONTEXT_FACTORY,
      "org.jnp.interfaces.NamingContextFactory");
      p.put(Context.URL_PKG_PREFIXES,
      " org.jboss.naming:org.jnp.interfaces");
      p.put(Context.PROVIDER_URL, "jnp://localhost:1099");

      Context jndiContext = new InitialContext(p);
      System.out.println(TravelAgentRemote.class.getName());
      Object ref = jndiContext.lookup(TravelAgentRemote.class.getName());
      TravelAgentRemote dao = (TravelAgentRemote)
      PortableRemoteObject.narrow(ref,TravelAgentRemote.class);

      dao.flushModeExample();
      }
      catch (Exception ne)
      {
      ne.printStackTrace();
      }
      }


      }


      Wud be a great help if you could help on this issue....

        • 1. Re: Ex 5 client 4 is not working..help required
          Tom Clifford Newbie

          Mahtab:

          I found that I had to create a jboss.xml for each app that had a
          TravelAgentBean, and put it in resources\META-INF, and also build it into
          the titan jar file that the TravelAgentBean was in.

          <jboss>
           <enterprise-beans>
           <session>
           <ejb-name>TravelAgentBean</ejb-name>
           <jndi-name>TravelAgentRemote</jndi-name>
           </session>
           </enterprise-beans>
           <resource-ref>
           <res-ref-name>jdbc/MySqlWorkbookDS</res-ref-name>
           <resource-name>MySqlWorkbookDS</resource-name>
           </resource-ref>
          </jboss>
          


          I also separated the 'domain' and 'travelagent' class files into one
          jar, called 'titan-ejb.jar', put that into the jboss deploy dir.
          I then built a titan-client.jar with only the clients classes in it.

          Hope this helps.
          Tom.