Ex 5 client 4 is not working..help required
mahtab.singh Jun 11, 2007 2:58 AMHi,
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....