Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we access the Bean with local interface inside client in same package as bean?

 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have heard that we can only access bean locally through other beans inside same container & we can not access bean trough local interface from normal java client though client will be in same package as that of bean.
Is this true???

Thanx in advance.

Prash
 
karthikeyan Chockalingam
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it is not true. The local interface can be used by clients running in the same EJB container and same Java virtual machine. Clients not only include EJBs but also other co located Java classes.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
normal java client

If this is a standalone java client you *will have to* use remote interfaces, since this standalone class will be using its own JVM. You *cant* use local interfaces in this case
[ February 15, 2006: Message edited by: jaikiran pai ]
 
karthikeyan Chockalingam
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Prashant,

My reply is based on the assumption that normal java client though client will be in same package as that of bean refers to a Java class containing the code to create instance of Context (or InitialContext) and doing a lookup with the Local EJB JNDI name.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A local client must be in the same application as the EJB it is calling. This means that the client must be packaged in the same EAR file or exploded directory as the EJB.

If the client and EJB are in different applications, let us say different EAR files, then the client must be remote even if both apps are deployed to the same server instance.
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is my directory structure for EJB:-
========
CartMasterBean.java -- Bean Implementation class
CartMaster.java -- Bean Remote class
CartMasterLocal.java -- Bean Local Remote class
CartMasterLocalHome.java -- Bean Home class
CartMasterHome.java -- Bean Remote Home class
Client.java --------Simple Java Program (Client) Accessing Bean through Local Home Interface as follow
"CartMasterLocalHome cm=(CartMasterLocalHome)initialcontext.lookup("CartMasterLocal")"
========

Here "CartMasterLocal" is the local JNDI name for EJB.

Now can I access the Bean in this client?

Pls tell me.
Thanx.
Prash
 
Andreas Schaefer
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you mix things up here. As someone already pointed out a local interface can only accessed by a class within the same application (JAR or EAR). A local interface does not have the means to be invoked remotely but also class loading issues prevent you from accessing the local interface from another application (JAR/EAR) because these two applications are loaded by different class loaders. This means that even when your client in another application does have the local interface the class obtained from the JNDI service is different from the one locally and you will end up in a Class Cast Exception.
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Andreas ,

Thanx for ur reply. I got my mistake.
I would like to have ur mail ID in my mail list. If u dont mind then give me ur id.
My id is tiwari_p_k@yahoo.com
Thanx.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic