users@glassfish.java.net

lookup of a sateless remote bean using Glassfish 3

From: <forums_at_java.net>
Date: Mon, 19 Sep 2011 10:33:37 -0500 (CDT)

As a glassfish novice I tried *very hard *(already for two weeks...) to get
simple access to a *stateless remote bean *from a standalone java client,
using Netbeans 6.8 and Glassfish 3.

Bean Class is:

@Stateless public class MySessionBean implements IMySessionBean { public
String sayHello() { return "hello"; } }
With interface

@Remote public interface IMySessionBean { public String sayHello(); }
running in a web component (war).

According to the documentation, it should work as follows:

InitialContext ic = new InitialContext();
ic.lookup("java:global/AmisWSServlet/MySessionBean");
However, I get during lookup()

Exception in thread "main" javax.naming.NoInitialContextException: Need to
specify class name in environment or system property, or as an applet
parameter, or in an application resource file: java.naming.factory.initial at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at
javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392) at
ejbtest.Main.main(Main.java:45)
I included *gf-client.jar *as a library.

When using the alternate aproach

Properties props = new Properties();
//com.sun.enterprise.naming.SerialInitContextFactory x = new
com.sun.enterprise.naming.SerialInitContextFactory();props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming"); props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
props.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
InitialContext ic = new InitialContext(props);
        ic.lookup("java:global/AmisWSServlet/MySessionBean");
I get during constructor *new InitialContext()*

Exception in thread "main" javax.naming.NoInitialContextException: Cannot
instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root
exception is java.lang.ClassNotFoundException:
com.sun.enterprise.naming.SerialInitContextFactory] at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657) at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at
javax.naming.InitialContext.init(InitialContext.java:223) at
javax.naming.InitialContext.<init>(InitialContext.java:197) at
ejbtest.Main.main(Main.java:44) Caused by: java.lang.ClassNotFoundException:
com.sun.enterprise.naming.SerialInitContextFactory at
java.net.URLClassLoader$1.run(URLClassLoader.java:200) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:188) at
java.lang.ClassLoader.loadClass(ClassLoader.java:303) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:248) at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316) at
java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:247) at
com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46) at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654) ...
4 more
  From somewhere I got the hint to include *appserv-rt.jar *(from glassfish
lib
dir), but then I get

Exception in thread "main" java.lang.NoClassDefFoundError:
com/sun/logging/LogDomains
        at
com.sun.enterprise.util.ORBManager.<clinit>(ORBManager.java:78)
        at
com.sun.enterprise.naming.SerialInitContextFactory.<clinit>(SerialInitContextFactory.java:56)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at
com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
        at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
        at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at ejbtest.Main.main(Main.java:44)
Caused by: java.lang.ClassNotFoundException: com.sun.logging.LogDomains
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
        at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
        ... 10 more
No idea where to get com/sun/logging/LogDomains...
Up to now, it's an endless game of surfing in the web to find any hints...but
no success at all. Why is that so complicated ???

By the way, I would expect port 3700 to be occupied, because this is the ORB
Port, used by glassfish. With netstat I cannot verfy that (of course
I started the glassfish domain)...?

Any hints are appreciated !

Many Thanks,  Michael


--
[Message sent by forum member 'schnudl']
View Post: http://forums.java.net/node/844647