• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Local interface example in HFEJB

 
Tong Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to EJB. I tried the advice example in HFEJB book. The remote
interface works as expected, but when I try the local interface, the
local client cannot find the JNI name. I specified the name in deploytool
as AdviceLocal. I wonder if anybody else got the same problem. I the
tried the program on WinNT and WinXP Pro and get the same result.
Here is the message:
C:\Java\ejb\projects\advice>java -cp %CLASSPATH%;AdviceLocalAppClient.jar AdviceLocalClient
javax.naming.NameNotFoundException: AdvisorLocal not found
at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:174)
at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:146)
at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:63)
at org.omg.stub.com.sun.enterprise.naming._SerialContextProviderImpl_Tie._invoke(Unknown Source)
at com.sun.corba.ee.internal.corba.ServerDelegate.dispatch(ServerDelegate.java:355)
at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)
at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)
Exception in thread "main" java.lang.NullPointerException
at AdviceLocalClient.go(AdviceLocalClient.java:29)
at AdviceLocalClient.main(AdviceLocalClient.java:10)
 
Anselm Paulinus
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You specified the name in the deployment descriptor as AdviceLocal but the error generated shows you were searching for AdvisorLocal.
 
Tong Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry. It was a typo. I do have the AdvisorLocal as the JNI name in deploytool and the client lookup string.
I am using j2se 1.4.2-b28 + j2ee 1.3.1-b17. Could it be a compatible
isssue? Anybody has this j2se1.4/j2ee1.3 combination and ran the local
Advice EJB successfully?
 
Tong Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found something related to the topic. It seems that the local client
needs to be in the same ear file or EJB container as the local bean in order
for it to access. The client, even running on the same JVM as the J2EE,
cannot lookup and find the local EJB home/object directly.
Any expert could share some wisdom on this? Thanks.
http://forum.java.sun.com/thread.jsp?forum=13&thread=293077
 
Uday Kiran
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Me too facing the same problem. Able to access Remote interfaces but not local interfaces from the same machine. Can anyone help us to go about this problem?
Thanx,
Uday Kiran
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy -- if you want to test a local interface, the most straightforward way is to do something like:
* Have Advice Bean be Remote
* Use your standard Remote AdviceClient
* Make another bean with a local interface
* Have the Remote Advice Bean lookup and access the *local* bean within the AdviceBean code.
(in other words, make AdviceBean be a local client to some other bean's local interface)
So, to test local interfaces, you should use a remote bean that then *internally* is a client to another bean's local interface.
You won't be able to do it any other way from a completely stand-alone client, because local means that the client and the bean MUST be running in the same JVM... because remember, local interfaces mean that arguments are passed "by value" in the normal Java sense (i.e. the bits in the variable are passed by copy) rather than serialization of objects.
Hope that helps... I REALLY should have had an example of this in the book. Hmmmm... next version.
cheers,
Kathy
 
Tong Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Kathy. I will try what you said. Yes, it's good
to add instructions on how to make a mini local interface work in the
book. It would be better not to have a main function inside local
client example(to indicate it can be run standalone).
I started feeling it's reasonable that local client should live
inside container after I posted my message yesterday...
BTW, I really enjoy this book(Head First EJB). You make a technology
as fun as art.
[ March 26, 2004: Message edited by: Tong Lin ]
[ March 26, 2004: Message edited by: Tong Lin ]
 
Tong Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I finally got the local interface work.
remote client -> remote EJBHome -> remote EJBObject -> remote bean with
local client -> local EJBHome -> local EJBObject -> local bean getMessage
1. As Kathy pointed out, the local client should live inside another
remote bean in order for outside remote client to access the local bean.
The local lookup string should be "java:comp/env/AdvisorLocal".
2. Add the remote and local home/object/bean in the same ejb jar with RI
(Add to Existing JAR file).
3. When you see there are two ejbs(remote and local) listed under one
jar icon, click the remote bean and "EJB Refs" tab, and add a reference
for the remote bean like this:
AdvisorLocal Session Local headfirst.AdviceHomeLocal headfirst.AdviceLocal
Then set "Enterprise Bean Name" to AdviceBeanLocal if your local bean named
AdviceBeanLocal.
This is to tell the deploytool to create local bean reference for the remote
bean in ejb-jar.xml.
You can also put the remote and local bean into different jar files for
the same ear file. Then you have to name the local bean reference as
something like "ejb-jar-ic.jar#AdviceBeanLocal" in the
"Enterprise Bean Name".
4. Verify, deploy the application with the two beans.
5. Compile your remote client with the stub created by the deploytool. And
run it.
[ March 28, 2004: Message edited by: Tong Lin ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic