All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: About Question enthuware.oce-ejbd.v6.2.383 :
PostPosted: Sat Jul 28, 2012 8:25 am 
I don't understand this question. I thought session beans are bound to 'java:[scope]/appName/moduleName/beanName'. But in this question it appears that 'yourBeanRef' is bound to 'java:comp/env'.

Which areas do I need to study to fully understand this question?

Thanks


Top
  
 
 Post subject: Re: About Question enthuware.oce-ejbd.v6.2.383 :
PostPosted: Mon Jul 30, 2012 10:36 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 3384
A bean may be bound to multiple names as governed by the specification section titled "Global JNDI Access". These names can be used by any other bean to locate a bean in a portable way.

Further, a bean reference may be set into another bean's context (using deployment descriptor or @EJB annotation) and in that case the other bean can look it up it its own context. All the such name in the bean's context start with java:comp/env.

Quote:
16.5.1.1 Injection of EJB References
The Bean Provider uses the EJB annotation to annotate a field or setter property method of the bean
class as a target for the injection of an EJB reference. The reference may be to a session bean’s business
interface or to a session bean’s no-interface view or to the local home interface or remote home interface of a session bean or entity bean.
The following example illustrates how an enterprise bean uses the EJB annotation to reference another
enterprise bean. The enterprise bean reference will have the name
java:comp/env/com.acme.example.ExampleBean/myCart in the referencing bean’s
naming context, where ExampleBean is the name of the class of the referencing bean and
com.acme.example its package. The target of the reference must be resolved by the Deployer,
unless there is only one session bean component within the same application that exposes a client view
type which matches the EJB reference.
package com.acme.example;
@Stateless public class ExampleBean implements Example {
...
@EJB private ShoppingCart myCart;
...
}


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.oce-ejbd.v6.2.383 :
PostPosted: Fri Nov 23, 2012 10:54 pm 
I have a question regarding the @EJB Usage

Is it possible to call inject an EJB using @EJB annotation , which is residing on different App Server than where Caller EJB is residing.

For example AppServer server1 has an EJB A
AppServer server2 has an EJB B

I want to inject B into EJB A using @EJB annotation (without using any look up logic) , where will I give the host name information for AppServer 2 ? I dont see any attribute in EJB which I can use to provide that.
is the only workaround to have Jndi.properties in class path of EJB A ?


Top
  
 
 Post subject: Re: About Question enthuware.oce-ejbd.v6.2.383 :
PostPosted: Sat Nov 24, 2012 7:37 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 3384
Usually app servers have the capability to configure remote objects. So the deployer configures EJB A in the app server 2 and ties it to a JNDI name, which is used by EJB B. Thus, when EJB B uses @EJB annotation, EJB A in injected (because the deployer has already configured EJB A to a name in app server 2)

HTH,
Paul.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.oce-ejbd.v6.2.383 :
PostPosted: Sat Nov 24, 2012 8:47 am 
Thanks Paul,

But I am little confused , looking at your answer . Question was how to call (or inject) EJB B reference in AppServer 1 when its originally deployed on AppServer 2 . But your answer seems to be the other way around. Thats OK. I got some idea .

Anywaz, can you please explain more briefly by citing example of any App Server ? That will be of real hep.
Also , that means we don't have anything in EJB Specs for this type of scenario . I think , we have a way to specify the Appserver location using props in initial context when doing JNDI look up . Dont we have
something similar available when getting EJB reference using injection. ?


Top
  
 
 Post subject: Re: About Question enthuware.oce-ejbd.v6.2.383 :
PostPosted: Sat Nov 24, 2012 10:39 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 3384
It has nothing to do with the specification. It is specific to a container. For example, when you deploy an ejb in glassfish, you can include glassfish-ejb-jar.xml in which you can bind the name to a remote ejb. For example:
Code:
<glassfish-ejb-jar>
 <enterprise-beans>
   <ejb>
     <ejb-name>Bean B</ejb-name>
     <ejb-ref>
        <ejb-ref-name>ejb/SomeOtherBean</ejb-ref-name>
        <jndi-name>protocol:host:port#java:global/anotherApp/SomeOtherBean</jndi-name>
       </ejb-ref>
   </ejb>
 </enterprise-beans>
</glassfish-ejb-jar>


Above, we are using someotherbean from another container and tying it to BeanB. To do so, we are using the remote server host and port in the jndi name. The host and port are specific to a container. So you have look at the specification of that container to learn what port and protocol to use.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.oce-ejbd.v6.2.383 :
PostPosted: Sat Nov 24, 2012 11:56 pm 
Offline

Joined: Sat Nov 24, 2012 8:52 am
Posts: 34
Thanks Paul.

Its clear now.

I think same can be achieved by lookup attribute of @EJB annotation.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.oce-ejbd.v6.2.383 :
PostPosted: Fri Dec 28, 2012 1:23 pm 
Hallo,

back to the Q59.

The right answer is: "Object obj = ic.lookup("java:comp/env/yourBeanRef");"
But why should be the answer "Object obj = ic.lookup("java:comp/env/YourBean");" wrong? With this lookup we get a new reference to YourBean.

Thanks!


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Template made by DEVPPL/ThatBigForum