How to access remote session bean from local stand-alone client?
I deploy a stateless session bean in a remote machine.
I can access the session bean at the same machine from a stand-alone client.
But I couldn't access the session bean from another machie's stand-alone client. Where do I set the session bean's ip address and service port number and how?
Thanks for your help.
Message was edited by:
cmyganda
[387 byte] By [
cmygandaa] at [2007-11-26 19:15:35]

# 1
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, <<vendorspecific classname>>);
p.put(Context.PROVIDER_URL, <<url for the jndi lookup>>);
// vendor specific properties
InitialContext ctx = new InitialContext(p);
The actual properties and their values you need depend on the applicationserver you're talking to.
Each vendor (and possibly version) has its own peculiarities.
# 2
Thanks for your reply. :)
I use the Sun Application Server and tried like below.
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://192.168.68.8:3700");
InitialContext ctx = new InitialContext(env);
MyHello myHello = (MyHello) ctx.lookup("MyHelloEJB");
But I got an error like this...
javax.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.cosnaming.CNCtx.lookup(CNCtx.java:501)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at myhello.MyHelloClient.main(Unknown Source)
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._NamingContextExtStub.resolve(_NamingContextExtStub.java:406)
at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:470)
Was the context factory name wrong?
# 5
I set the InitialContext properties like below
env.put("org.omg.CORBA.ORBInitialHost", "host-ip-address");
env.put("org.omg.CORBA.ORBInitialPort", "3700");
It works well at the same machine with the sssion bean.
But in the different machine I got an error ...
Feb 22, 2007 3:05:33 PM com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl <init>
WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: local-ip-address; port: 3700"
org.omg.CORBA.COMM_FAILURE:vmcid: SUN minor code: 201 completed: No
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2348)
at com.sun.corba.ee.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2369)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:212)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:225)
at com.sun.corba.ee.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:104)
at com.sun.corba.ee.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:159)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:156)
at com.sun.corba.ee.impl.protocol.CorbaClientDelegateImpl.is_a(CorbaClientDelegateImpl.java:296)
at org.omg.CORBA.portable.ObjectImpl._is_a(ObjectImpl.java:112)
at org.omg.CosNaming.NamingContextHelper.narrow(NamingContextHelper.java:69)
at com.sun.enterprise.naming.SerialContext.narrowProvider(SerialContext.java:110)
at com.sun.enterprise.naming.SerialContext.getProvider(SerialContext.java:164)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:309)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at myhello.MyHelloClient.main(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.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
at com.sun.enterprise.appclient.Main.main(Main.java:180)
Caused by: java.lang.RuntimeException: java.net.ConnectException: Connection refused: connect
at com.sun.enterprise.iiop.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:356)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:195)
... 19 more
Caused by: java.net.ConnectException: Connection refused: connect at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:507)
at java.nio.channels.SocketChannel.open(SocketChannel.java:146)
at com.sun.enterprise.iiop.IIOPSSLSocketFactory.createSocket(IIOPSSLSocketFactory.java:340)
... 20 more
It looks like the client tried to connect the local machine.
It means it does not work the setting of the InitialContext properties
in the client's code.
Have any idea?