Skip to Content
author's profile photo Former Member
Former Member

Looking up the wrong object?

I'm using the NetWeaver 6.40. I have a question about looking up objects through the WebAS JNDI interface. How do I know what the right string is to use in the InitialContext.lookup call?

I've created a jsp similar to the one in the calculator demo. It references a proxy object, again like the calculator demo. When the jsp loads, the proxy object throws a class cast exception. The exception is caused by the call to PortableRemoteObject.narrow(). Here is the code fragment from the proxy:

public void init() throws Exception {

//Lookup the enterprise bean

try {

InitialContext ctx = new InitialContext();

Object ob = ctx.lookup ("java:comp/env/DocManager/DocumentManagerSB");

DocumentManagerHif home = (DocumentManagerHif)

PortableRemoteObject.narrow( ob, DocumentManagerHif.class);

dmSb = home.create();

} catch (Exception e) {

throw new Exception(

"Error instantiating DocumentManagerSB EJB: "

+ e.toString());



As you see, more or less identical to the calculator demo.

When I run the debugger I see the object ob contains a Hashtable which includes a "value=DocumentManagerHif_Stub (id=177)". At this point, as far as I can tell, it seems to be the right object. As I follow it into the narrow call I can see every thing looks fine until I get to This is where the exception occurs.

Curiously, I am able to access the bean from a java command line client. The look up and narrow call there look like this:




String host = getHost();

System.setProperty("java.naming.provider.url", host + ":50004");

InitialContext ctx = new InitialContext();

Object ob = ctx.lookup("DocManager/DocumentManagerSB");

DocumentManagerHif dmHome = (DocumentManagerHif)PortableRemoteObject.narrow( ob,


//Initialize the session bean

DocumentManagerRif dmRif = dmHome.create();


When I look in the Visual Administrator, under services:Ejb dmEJB.jar:DocumentManagerSB I see the JNDI name is DocManager/DocumentManagerSB. So I think it's correct. What am I doing wrong?


- Otto

Add comment
10|10000 characters needed characters exceeded

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Mar 05, 2004 at 04:21 PM

    Hi Otto,

    Did you use the NetWeaver Developer Studio to develop your application? If yes, try looking up your bean with this string: java:comp/env/ejb/DocManager/DocumentManagerSB

    (the studio sets the EJB reference to be bound to the ejb subcontext of the java:comp/env by default).

    If this is not the case, and if you have an administrator user, you can log on to the Visual Administrator and browse the JNDI tree. It appears under the JNDI Registry service. Under webcontainer node you can see the reference object that is bound to your application env.

    Hope that helps,


    Add comment
    10|10000 characters needed characters exceeded