Hi,
I am trying to lookup an external remote bean from within an application. The lookup needs to be dynamic as I can not know in advance the IP address of the external remote bean AS.
To summarize: Two physical machines host1 and host2; dynamic lookup; Stateless Bean A is deployed on host1 and invokes Stateless Bean B on host2.
I used two approaches:
1. Use the @EJB annotation to inject the bean, and the corbaname
2. new InitalContext() and lookup.
1. -> Works
2. -> fails with exception
Here is my code snippet:
@EJB(mappedName = "corbaname:iiop:147.214.234.86:3700#B")
private B myDao = null;
public void foo() {
try {
System.out.println("try 1...");
// This works
System.out.println("try 1: " + myDao.readAllGlobalParameters()); //Here I get what I expected
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
}
try {
// Since I need to do a dynamic lookup (the ip is not static), I try with the corbaname
System.out.println("try 2...");
InitialContext ic = new InitialContext();
Object obj = ic.lookup("corbaname:iiop:147.214.234.86:3700#B");
System.out.println("try 2: " + obj);
B dao = (B) obj;
System.out.println("try 2: " + dao);
System.out.println("try 2: " + dao.readAllGlobalParameters());
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
}
And I get the following error on "try 2:":
[#|2009-04-30T16:35:36.193+0200|SEVERE|sun-glassfish-comms-server1.5|mysb.AImpl|_ThreadID=15;_ThreadName=p: thread-pool-1; w: 5;_RequestID=aa2fba5f-3e01-47d3-b5ea-e32992465054;|The log message is null.
javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
vax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
at com.sun.jndi.cosnaming.ExceptionMapper.mapException(ExceptionMapper.java:44)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:484)
at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:523)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at mysb.AImpl.funnyStuff(AImpl.java:90)
at mysb.AImpl.foo(AImpl.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:77)
at $Proxy41.foo(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:154)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:687)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:227)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223) at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:72)
at org.omg.CosNaming._NamingContextStub.resolve(_NamingContextStub.java:251)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:470)
... 31 more
|#]
What did I do wrong?
(PS: I am using sailfin-v1-b60g based on glassfish v2.1)
[Message sent by forum member 'baboune' (baboune)]
http://forums.java.net/jive/thread.jspa?messageID=344509