cancel
Showing results for 
Search instead for 
Did you mean: 

Look up EJB in JNDI

Former Member
0 Kudos

Hi,

I am trying to use an EJB from a web dynpro application. The EJB is given a name as "MaterialBatchBean" as follows:

<ejb-j2ee-engine>

<description>

</description>

<enterprise-beans>

<enterprise-bean>

<ejb-name>MaterialBatchBean</ejb-name>

<jndi-name>MaterialBatchBean</jndi-name>

<entity-props/>

</enterprise-bean>

</enterprise-beans>

</ejb-j2ee-engine>

When I try to look up this EJB using the following codes, it always complains about the incorrect path:

InitialContext ctx = new javax.naming.InitialContext();

MaterialBatchHome mbHome = (MaterialBatchHome) javax.rmi.PortableRemoteObject.narrow(ctx.lookup("java:comp/env/ejb/MaterialBatchBean"),MaterialBatchHome.class);

Does anyone know what is wrong here? Your help is appreciated!

Hart

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Hart,

You can check the exact path of your EJB from the Visual Admin. In the Visual Admin, go to service EJB Container -> Beans. Then drill down to your ejb project and your ejb. You can then see the path from the JNDI Name field on the right.

Also, rememeber that you need to set the reference to this EJB from your Web Dynpro project properties when you lookup ejb from your code implementation and not using model.

Regards,

Marc

Former Member
0 Kudos

Hi Marc,

Thanks for the reply!

Actually this is what I did. I have two EJBs, one with modified JNDI name, the other with the default one. When I looked at them in Visual Admin, the JNDI name field has the following values respectively:

1. MaterialBatchBean

2. sap.com/MaterialProxyEAP/MaterialBatchIf_PortTypeBean

I tried to use the following codes to look up:

InitialContext ctx = new javax.naming.InitialContext();

MaterialBatchIf_PortTypeHome mbIfHome = (MaterialBatchIf_PortTypeHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("java:comp/env/ejb/sap.com/MaterialProxyEAP/MaterialBatchIf_PortTypeBean"),MaterialBatchIf_PortTypeHome.class);

MaterialBatchHome mbHome = (MaterialBatchHome) javax.rmi.PortableRemoteObject.narrow(ctx.lookup("java:comp/env/ejb/MaterialBatchBean"),MaterialBatchHome.class);

The exception returned is:

"Path to object does not exist at java:comp, the whole lookup name is java:comp/env/ejb/sap.com/MaterialProxyEAP/MaterialBatchIf_PortTypeBean.

It looks like the path is not correct. Any idea?

Regards,

Hart

detlev_beutner
Active Contributor
0 Kudos

Hi Hart,

do you try to access a local EJB? If yes, you didn't try to use "localejbs" as prefix? Then give it a try, see for more details around this topic.

Hope it helps

Detlev

Former Member
0 Kudos

Hi Detlev,

Thanks a lot for your help! It worked like a butterfly!

I did not know the prefix "java:comp/env" is not needed in the look up (I must be reading some old documentation).

Regards,

Hart

Vlado
Advisor
Advisor
0 Kudos

Hi Hart,

Actually, that's not exactly correct! Marc and Detlev have somewhat misled you.

When accessing an EJB from another J2EE component (servlet, JSP, other EJB's), one has to declare an <b><i>ejb-ref</i></b> in the component's deployment descriptor. Then he/she must use the reference name with the prefix <b>"java:comp/env"</b> to lookup the EJB from that component. Of course, one can use the JNDI name of the EJB to lookup directly from the JNDI root, but this should be avoided as it is not portable and may not be supported in the near future.

However, WebDynpro applications are not standard J2EE applications. With the current release the only way to lookup an EJB from a WebDynpro component is with the bean's JNDI name (or with the prefix "localejbs/" in front of the JNDI name for local home interfaces). Probably this will be revised in the next releases and WebDynpro components will lookup EJB's as standard J2EE components do - by means of declaring a reference and with the "java:comp/env" prefix before the reference name.

For more information, you can also have a look at the following links:

http://help.sap.com/saphelp_erp2004/helpdata/en/56/c8633e0084e946e10000000a114084/content.htm

http://help.sap.com/saphelp_erp2004/helpdata/en/86/2ccbdefb8f5843958a11062e19fc1d/content.htm

Best regards,

Vladimir

detlev_beutner
Active Contributor
0 Kudos

Hi Vladimir,

sorry, but I have to mention that guys coming around the corner saying I have mislead someone are welcome - if they are right. Your are not.

It was clear from the thread ("I am trying to use an EJB from a web dynpro application") that we have been talking of "WebDynpro accesses EJB". The hint I gave is the way it works at the moment, as you wrote by yourself and as it is documented in the corresponding (first) link you gave.

There are for sure a many topics where I'm not sure in, and the formal deployment/access declarations in fact are such a topic (it is boring stuff), but with this special issue (I knew by own experience - just because I had to learn that it does not work the standard way) I was just right.

Atmosphere on SDN is stamped by a great spirit of helping each other, and the best help is given if different experts work together to help the questioners.

So for sure you are welcome with your obvious great knowledge in these topics - but please, don't consider yourself as a lone fighter, trying to relegate others.

Have a nice weekend

Detlev

Vlado
Advisor
Advisor
0 Kudos

Hi Detlev,

Sorry, I didn't mean to offend anyone. If you feel this way please accept my sincere apologies.

My point was simply that from the replies in the thread finally Hart has left with the impression that the prefix "java:comp/env" is not needed anymore and EJB's should always be looked up directly from the JNDI root. Which is generally incorrect and could misguide other SDN members trying to access EJB's not only from WebDynpro applications.

Have a nice weekend too and best regards,

Vladimir

detlev_beutner
Active Contributor
0 Kudos

Hi Vladimir,

accepted [hand-shaking]

Or better: Seems to be just a misunderstanding, so in fact noone has to apology

Best regards

Detlev

Former Member
0 Kudos

Hi guys,

Looks like I am the one who should apologize...

No fighting or offending please, at least not on a word by which nothing bad was really meant.

It is very hard not to agree with Detlev's viewpoint of helping others through SDN forums. I believe this is what all the other SDN members, or we say, SDN friends think.

Back to my previous question, I did have an impression that the prefix "java:comp/env" is not needed anymore, but this is only my assumption, not a conclusion made from Detlev's posting.

With Vladimir's note, I am now much more clear about this.

Thanks again my friends!

Hart

Answers (0)