calling EJB from the client
naveen Nov 30, 2004 6:10 AMI have created a simple entity bean using jboss.
i have deployed the entity bean.
now i want to call it from the client.
while running i get the error.
javax.naming.NoInitialCotextException Cannot instantiate class:jnp.interfaces.NamingContextFactory.
my client coding is
----------------------------------------------------------------------------
ackage product.myproduct;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
public class ProductClient
{
public static void main(String args[])
{
ProductHome home=null;
System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.provider.url", "192.168.1.7:1099");
try{
InitialContext jndiContext = new InitialContext();
home=(ProductHome)PortableRemoteObject.narrow(jndiContext.lookup("ProductHome"),ProductHome.class);
home.create("123-456-7890","P5-350","350 Mhz pentium");
/* home.create("123-456-7891","P5-400","400 Mhz pentium","300");
home.create("123-456-7892","P5-450","450 Mhz pentium","400");
home.create("123-456-7893","SD-64","64 MB SDRAM","50");
home.create("123-456-7894","SD-128","128 MB SDRAM","100");*/
Iterator i=home.findByName("SD-64").iterator();
System.out.println("These products match the name SD-64:");
while(i.hasNext())
{
Product prod=(Product)PortableRemoteObject.narrow(i.next(),Product.class);
System.out.println(prod.getDescription());
}
/* i=home.findByBasePrice("200").iterator();
System.out.println("These products match the base price $200");
while(i.hasNext())
{
Product prod=(Product) PortableRemoteObject.narrow(i.next(),Product.class);
System.out.println(prod.getDescription());
}*/
}catch(Exception e)
{e.printStackTrace();}
finally{
if(home != null){
Iterator i;
System.out.println("destroying products");
try{
i=home.findAllProducts().iterator();
while(i.hasNext())
{
try{
Product prod=(Product)PortableRemoteObject.narrow(i.next(),Product.class);
if(prod.getProductID().startsWith("123"))
{
prod.remove();
}
}catch(Exception e){e.printStackTrace();}
}
}catch(Exception e){}
}
}
System.out.println("Hai");
}
}
what r things i have to add.