Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse glassfish 3 , client error

I am using latest Eclipse to develop EJB 3 under Glassfish 3. I create a new Glassfish server instance in the Eclipse, write a simple EJB, deployed and succeeded.

Now I write a client, but it always give me error like this

java.lang.RuntimeException: Orb initialization erorr
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:148)
    at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
    at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.client.Test.main(Test.java:22)
Caused by: java.lang.NullPointerException
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:120)
    ... 8 more
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'helloRemote' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.client.Test.main(Test.java:22)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.RuntimeException: Orb initialization erorr]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    ... 3 more
Caused by: java.lang.RuntimeException: Orb initialization erorr
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:148)
    at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
    at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    ... 4 more
Caused by: java.lang.NullPointerException
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:120)
    ... 8 more

the client code is this

Properties props = new Properties();
        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");


         InitialContext ic = new InitialContext(props);

         HelloRemote remote = (HelloRemote) ic.lookup("helloRemote");
         System.out.println(remote.echo("john"));

Do you know why ? is it "com.sun.enterprise.naming.SerialInitContextFactory" not in the classpath ?

The source code is here http://www.mediafire.com/file/278rc1tpip0rjku/EJBApp2.rar

I appreciate your help.

like image 959
user595234 Avatar asked Dec 06 '22 21:12

user595234


2 Answers

To solve this issue, you just need to add external jar "appserv-rt.jar" in the buildpath of the client.

You can find it in the folder ...\glassfishv3\glassfish\lib

Or create a package with this jar and all its dependencies to add it in the BP

This is my code

InitialContext ctx = new InitialContext();
HelloWorld helloWorldRemote = (HelloWorld) ctx.lookup("ejb/helloWorldBeanJndiName");
System.out.println(helloWorldRemote.sayHello());

Without the jar file, i got the same error and with I get "Hello" in the console.

like image 101
Nico Baps Avatar answered Dec 10 '22 11:12

Nico Baps


Judging from the properties you set this must be a standalone client.

Make sure you include the gf-client.jar to your classpath for this to work. (glassfish\lib\gf-client.jar)

You also don't need to set the properties you set. To specify a non-localhost location of your server or alternative port however you might set:

prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

You also might want to go over "How do I access a Remote EJB component from a stand-alone java client?" at: http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

like image 25
Snelders Avatar answered Dec 10 '22 13:12

Snelders