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 com.sap.engine.system.PortableRemoteObjectProxy. 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:
...
System.setProperty("java.naming.factory.initial",
"com.sap.engine.services.jndi.InitialContextFactoryImpl");
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,
DocumentManagerHif.class);
//Initialize the session bean
DocumentManagerRif dmRif = dmHome.create();
...
When I look in the Visual Administrator, under services:Ejb Container:sap.com/dmEAR: dmEJB.jar:DocumentManagerSB I see the JNDI name is DocManager/DocumentManagerSB. So I think it's correct. What am I doing wrong?
Thanks,
- Otto