How to access my application on a SunOne 8.0.0_01 from a stand-alone client
Hello,
perhaps someone of you knows how can solve my problem accessing my J2EE-Application with EJBs, etc. from a stand-alone client.
In the classpath of my client the appserv-rt.jar and j2ee.jar are accessible. In the sourcecode I tried to access the server with:
Properties env =new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL,"iiop://myserver:3700");
Context initialContext =new InitialContext(env);
Object objRef = initialContext.lookup("MySessionBean");
With these setting I get this exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException
at com.sun.corba.se.internal.iiop.ShutdownUtilDelegate.mapSystemException(ShutdownUtilDelegate.java:64)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
at de.fhhn.ectsmodulclient.interfaces._ECTSModulSession_Stub.getStudiengaenge(Unknown Source)
at de.hshn.ectsmodulclient.web.StandAloneClient.showStudiengaenge(StandAloneClient.java:68)
at de.hshn.ectsmodulclient.web.StandAloneClient.main(StandAloneClient.java:90)
Caused by: java.rmi.RemoteException
at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.java:213)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:797)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:137)
at $Proxy36.getStudiengaenge(Unknown Source)
Can anybody tell me what the problem is and probably how I can make it work?
Are there some "hidden" configuration-parameters on the serverside that I have to set/change?
Thank you for your help!
Greetings
Gregor Ewald
[1974 byte] By [
gewalda] at [2007-10-3 4:08:40]

Try to see what is written in server log, perhaps there you will find answer.
It was the first thing I did, but there was nothing different. Is it the right way to connect to the server? or are other ways?
> > Properties env = new Properties();
> env.put(Context.INITIAL_CONTEXT_FACTORY,
> "com.sun.jndi.cosnaming.CNCtxFactory");
> env.put(Context.PROVIDER_URL,
> "iiop://myserver:3700");
>
Scrap that.
Instead supply the following startup arguments to the JVM:
-Dorg.omg.CORBA.ORBInitialHost=${ORBhost}"
-Dorg.omg.CORBA.ORBInitialPort=${ORBport}"
where ORBhost and ORBport are the settings for your server ("myserver", "3700" in your example).
You will also need j2ee.jar and appserv-rt.jar on the classpath when running the client.
That's all you need.
In addition, you don't need to explicitly instantiate the CosNaming JNDI provider in your client. When using SUN's implementation, it's much easier to just create a no-arg InitialContext().As long as appserv-rt.jar is in your classpath, the correct naming provider will be bootstrapped.The other advantage of this is it allows you to take advantage of the dynamic RMI-IIOP feature in our implementation, which removes the need for static RMI-IIOP stubs.You can find more information here :
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB
ksaksa at 2007-7-14 22:08:31 >

This was a pretty good advice. It works for my standalone-client called from commandline. But it doesn磘 work in a class that is called by a JSP in a Tomcat-environment.
Calling this in my Class:
Properties env = System.getProperties();
env.put("org.omg.CORBA.ORBInitialHost",serviceAddress);
env.put("org.omg.CORBA.ORBInitialPort",providerPort);
Context initialContext = new InitialContext();
Object objRef = initialContext.lookup("MySessionBean");
MySessionBeanHome serviceHome = (MySessionBeanHome) PortableRemoteObject.narrow(
objRef, MySessionBeanHome.class);
...with this I get a namingexception in my JSP saying that there is no Object bound with the name "MySessionBeanHome"...I check this but it is definitly bound on my Applicationserver. I can still call my commandline client and the same implementation works fine.
I think that the JNDI-Name "MySessionBean" is searched in the Tomcat-Context and not in my remote Applicationserver, right?...but how can I tell him to use my applicationservers context, in which my Bean is bound?
Yes, non-Java EE web containers typically set the default naming provider for the JVM, which prevents the no-arg InitialContext() from bootstrapping to the appserver's provider.See :https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB --ken
ksaksa at 2007-7-14 22:08:31 >

Very good! With these settings described at glassfish
Properties env = new Properties();
env.put("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
env.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
env.put("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
env.put("org.omg.CORBA.ORBInitialHost", serviceAddress);
env.put("org.omg.CORBA.ORBInitialPort", providerPort);
Context initialContext = new InitialContext(env);
Object objRef = initialContext.lookup("MySessionBean");
...I got a CommunicationException saying the following:
java.rmi.RemoteException: NamingException; nested exception is:
javax.naming.CommunicationException: Can't find SerialContextProvider [Root exception is org.omg.CORBA.COMM_FAILURE:vmcid: SUN minor code: 201 completed: No]
What do I have to do with the SerialContextProvider? Where do I find it? I don磘 understand there errormessage...
Are you sure your target orb host and port attributes are set correctly and that the server is running ?
ksaksa at 2007-7-14 22:08:31 >

The server is up an running - I check it.org.omg.CORBA.ORBInitialHostorg.omg.CORBA.ORBInitialPortare set to the right values....The target operatingsystem is solaris...can this be a problem?Do I have to change some configurations on the server?
Have you gotten a stand-alone java client to run on the same machine as tomcat using the same JVM? The target OS shouldn't matter as long as you're using the same version of the JDK on both machines. --ken
ksaksa at 2007-7-14 22:08:31 >

Yes, both - standalone and tomcat are running on the client same jvm, the server is running on a remote maschine. All are using jvm 1.4.2_08.
Did your stand-alone client on the remote machine encounter the same error as your tomcat attempt?Try looking in the tomcat log for a more detailed stack trace.
I'm able to do this from tomcat 5.0 on a remote machine with JDK 1.5 and the latest version of the J2EE 1.4 SDK release (AS 8.2) for an appserver running on linux or solaris.You might want to try with those versions as well.
--ken
ksaksa at 2007-7-14 22:08:31 >

The standalone-Client works, it throws no exceptions. The result is correct. But the tomcat attempt is not working. The exception:
java.rmi.RemoteException: NamingException; nested exception is:
javax.naming.CommunicationException: Can't find SerialContextProvider [Root exception is org.omg.CORBA.COMM_FAILURE:vmcid: SUN minor code: 201 completed: No]
seems to be a client exception because there is nothing in the server磗 log about that.
I got it. I changed the value of the property
java.naming.factory.initial
from
com.sun.enterprise.naming.SerialInitContextFactory
to
com.sun.jndi.cosnaming.CNCtxFactory
so that I now initialize the connection this way
Properties env = new Properties();
env.put("java.naming.factory.initial",
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
env.put("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
env.put("org.omg.CORBA.ORBInitialHost", serviceAddress);
env.put("org.omg.CORBA.ORBInitialPort", providerPort);
Context initialContext = new InitialContext(env);
Object objRef = initialContext.lookup("MySessionBean");
and this works in my Tomcat-application. But I don磘 understand way this could be a problem? What is the matter with these contextfactories? What are they for and what kind of different factories can I use? Are they described somewhere?