• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

InitialContext.lookup and narrow malfunctioning

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have successfully deployed a simple CMP entity bean on JBoss 3.2.3. I am attempting to access the ejb using the following client code. both the client and the jboss server that has the ejb container are on the same machine. However, I experienced a weird behavior from the lookup method. When i did Object obj = ctx.lookup("local/PersonnelBean"), it should return the LocalHome interface of the PersonnelBean which is PersonnelLocalHome (same name in ejb-jar.xml), but it returned me local/PersonnelBeanHome which doesnt exist at all. I got this by printint out the obj object. Thereafter, I changed my PersonnelLocalHome interface to PersonnelBeanHome just to let it go to the next step, but it is giving me the same NullPointer Exception. Kindly help. 'local/PersonnelBean' is the jndi name of the bean as told by JBoss. Following is the client code.


public static void main( String [] args )
{

Properties prop = new Properties();
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
prop.setProperty(Context.PROVIDER_URL, "localhost:1099");
prop.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming rg.jnp.interfaces");

try
{
Context ctx = new InitialContext(prop);
System.out.println("TestEJB: 1 ");

Object obj = ctx.lookup( "local/PersonnelBean" );
System.out.println("Obj is: " + obj);
System.out.println("TestEJB: 2");

com.btm.ejb.personnel.PersonnelBeanHome home =
(com.btm.ejb.personnel.PersonnelBeanHome)javax.rmi.PortableRemoteObject.narrow(
obj, com.btm.ejb.personnel.PersonnelBeanHome.class );
System.out.println("TestEJB: home object created");
PersonnelLocal personnel = home.create("M001", "Murad", "Iqbal",
"4343", 1, "SE", "PK", "19121979");
System.out.println("TestEJB: object created");
//System.out.println( personnelLocal.hello());
//personnel.remove();
}
catch ( Exception e )
{
e.printStackTrace();
System.out.println( "Exception: " + e );
}






TestEJB: 1
Obj is: local/PersonnelBeanHome
TestEJB: 2
java.lang.NullPointerException
TestEJB: home object created
Exception: java.lang.NullPointerException
at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
at $Proxy0.create(Unknown Source)
at com.test.TestEJB.main(TestEJB.java:45)
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Murad,
It seems to me that you have misunderstood the purpose of the "local" EJB interfaces (as opposed to the "remote" interfaces). The "local" interface is _not_ for clients that are on the same machine as the EJB container. The local interface is for clients that are in the same JVM as the EJB container. Since I assume your client is not in the same JVM as the EJB container, it is a remote client, and must therefore use the EJB "remote" interface.

The local interface was introduced so that one type of EJB (for example a session bean) could lookup a different type of EJB (for example an entity bean) in the same EJB container.

I think you also need to define remote interfaces for your EJB's -- since it appears you have currently only defined local interfaces.

For your information, TheServerSide Web site has a freely available book on EJB -- which can be downloaded as a single, PDF file.

Good Luck,
Avi.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic