cancel
Showing results for 
Search instead for 
Did you mean: 

JNDI lookup of a Stateless Session bean from another stateless session bean

Former Member
0 Kudos

Hi,

I am working on SAP Netweaver. We have created a stateless session bean which is finally deployed as a webservice. From this stateless session bean we need to call another stateless session bean as a local reference.

I have done the following.

1. Added JNDI-Name to the ejb-j2ee-engine.xml.

2. My lookup code is as follows

Context context = null;

Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");

context = new InitialContext(env);

Object ejbObj = context.lookup("MyBean");

But i get the NamingException .Here MyBean is the jndi-name provided in the ejb-j2ee-engine.xml.

Can somebody tell me what i am doing wrong.

Thanks

Priya

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi,

I tried changing the lookup string to java.comp/ .But i get this error message " Naming Exception : Path to object does not exist at java:comp".I have removed the jndi-name from the ejb-j2ee-engine.xml also.

In the previous code the PathfromJNDIRegistry actually meant the context from JNDI Registry from visual admin. I can see my bean there and i tried lookup using information from JNDIRegistry.When i do that i get RemoteException (Error while loading the class).

Regards

Priya

Former Member
0 Kudos

Hi Priya,

in my opinion you find referenced beans into the underlying context of the bean in which you had the reference. Have a look in your Visual Administrator -> Cluster Tab -> Services -> JNDI Registry. There you can find your deployed bean and it's

own

context where the Bean MyBean is.

Furthermore try

context.lookup("java:comp/MyBean");

.

Regards André

Former Member
0 Kudos

Hi,

Thanks for your replies.I did as you had suggested.I added ejb-local-ref to the ejb-jar.xml and i provided ejb-ref as MyBean.

My lookup code uses the string

ctxt.lookup("localejbs\MyBean");

But still i get Naming Exception.

I tried something different yesterday.

I changed the code to use

InitialContext ctxt = new InitialContext();

ctxt.lookup("localejbs/"+ pathfromJNDIRegistry);

and this time i did not get Naming exception but i got RemoteException saying there was error loading the class.

Is there something i need to add somewhere for the classloader to be able to find and load this class in the second scenario.

Please suggest me which method to go for amongst the two and what is the missing information i need to add.

Thanks

Priya

viliana
Advisor
Advisor
0 Kudos

Hi Priya,

Try to remove the jndi-name tag from the ejb-j2ee-engine.xml. And then look up the bean by java:comp/env/<ejb-ref-name>.

Best regards,

Viliana

Vlado
Advisor
Advisor
0 Kudos

Hi Priya,

and a small addition from my side too: if you want to lookup the local home interface, you must declare an ejb-local-ref instead of ejb-ref.

Best regards,

Vladimir

Former Member
0 Kudos

Hi,

in addition to Andre's reply, you can have a look at this post: (it describes how to add the reference in the web.xml, but it's analogous for the ejb-jar.xml).

Also, keep in mind that in this case you should lookup the EJB relative to the java:comp/env context (you can see the correct lookup string in the above thread also.)

Hope that helps!

Former Member
0 Kudos

Hi Priya,

you can create a ejb-ref in the ejb-jar.xml for the SessionBean you want to reference to. So the Context of the second SessionBean know this Bean under the given EJB Reference Bean.

Regards André