HELLO
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 clientejbtypes.Main.main(Main.java:30)
Any pointers on this will be of great help.
Thanks,
- Sonal
SCJP 6.0 93%
nitin pokhriyal
Ranch Hand
Joined: May 19, 2005
Posts: 263
posted
0
Use your server specification to set environment variable or write a method to for InitialContext(hashtable) implementation.
Sonal Popat
Greenhorn
Joined: May 10, 2010
Posts: 9
posted
0
Here I am using Glassfish V3 and
loosely following this, there is no need to specify properties.
I have changed nothing except adding gf-client.jar and appserv-rt.jar in classpath
I am getting new error...
Output is as follows:
HELLO
May 10, 2010 5:58:57 PM com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
java.lang.ClassCastException at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:258)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at com.sun.enterprise.naming.impl.SerialContext.narrowProvider(SerialContext.java:359)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:327)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at clientejbtypes.Main.main(Main.java:39)
Caused by: java.lang.ClassCastException: Object is not of remote type com.sun.enterprise.naming.impl.SerialContextProvider
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:250)
... 7 more
javax.naming.NamingException: Lookup failed for 'ejb/com.ejb.RemoteStateless' in SerialContext ,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext ,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is java.lang.ClassCastException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at clientejbtypes.Main.main(Main.java:39)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext ,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is java.lang.ClassCastException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 2 more
Caused by: java.lang.ClassCastException at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:258)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at com.sun.enterprise.naming.impl.SerialContext.narrowProvider(SerialContext.java:359)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:327)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 3 more
Caused by: java.lang.ClassCastException: Object is not of remote type com.sun.enterprise.naming.impl.SerialContextProvider
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:250)
... 7 more
Sachin Chandra
Greenhorn
Joined: Jun 19, 2009
Posts: 7
posted
0
Hi,
The name to the look up object is depend on the server. So please change the look up code as below.
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.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 clientejbtypes.Main.main(Main.java:37)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.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
Hi,
Add all jars from glassfish modules directory into the lib of your stand alone client.
Thanks
Sachin CR
Sonal Popat
Greenhorn
Joined: May 10, 2010
Posts: 9
posted
0
Hello,
Thanks Sachin and Nitin,
So far I've added gf-client.jar, appserv-rt.jar files and EJBTpes-ejb.jar (jar file having RemoteStateless EJB which I'm trying to lookup) file in to the library of my JAVA client application.
this is the sun-ejb-jar.xml file
<sun-ejb-jar>
<enterprise-beans>
<ejb>
<ejb-name>RemoteStateless</ejb-name>
<jndi-name>RemoteStateless</jndi-name>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
entry in to ejb-jar.xml file is as follows
<enterprise-beans>
<session>
<description> Remote EJB </description>
<display-name> Remote EJB </display-name>
<ejb-name>RemoteStateless</ejb-name>
<remote>com.ejb.RemoteStateless</remote>
<ejb-class>com.ejb.RemoteStateless</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
I've tried to lookup with all the different combinations
this is the entry of RemoteStateless EJB in server.log file
[#|2010-05-12T11:46:29.175-0700|INFO|glassfishv3.0|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=19;_ThreadName=Thread-1;|Portable JNDI names for EJB RemoteStateless : [java:global/EJBTypes/EJBTypes-ejb/RemoteStateless, java:global/EJBTypes/EJBTypes-ejb/RemoteStateless!com.ejb.RemoteStatelessRemote]|#]
[#|2010-05-12T11:46:30.127-0700|INFO|glassfishv3.0|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=19;_ThreadName=Thread-1;|Glassfish-specific (Non-portable) JNDI names for EJB RemoteStateless : [RemoteStateless#com.ejb.RemoteStatelessRemote, RemoteStateless]|#]
and then also I'm getting this error
May 12, 2010 11:57:16 AM com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
java.lang.ClassCastException at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:258)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at com.sun.enterprise.naming.impl.SerialContext.narrowProvider(SerialContext.java:359)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:327)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at clientejbtypes.Main.main(Main.java:38)
Caused by: java.lang.ClassCastException: Object is not of remote type com.sun.enterprise.naming.impl.SerialContextProvider
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:250)
... 7 more
javax.naming.NamingException: Lookup failed for 'RemoteStateless' in SerialContext ,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext ,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is java.lang.ClassCastException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at clientejbtypes.Main.main(Main.java:38)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext ,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is java.lang.ClassCastException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 2 more
Caused by: java.lang.ClassCastException at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:258)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at com.sun.enterprise.naming.impl.SerialContext.narrowProvider(SerialContext.java:359)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:327)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 3 more
Caused by: java.lang.ClassCastException: Object is not of remote type com.sun.enterprise.naming.impl.SerialContextProvider
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:250)
... 7 more
I tried com.ejb.RemoteStatelessRemote Rsl = (com.ejb.RemoteStatelessRemote) PortableRemoteObject.narrow(o, com.ejb.RemoteStatelessRemote.class); doesnt work that way too
Here is one more example, which is of Asynch Session bean but the same thing for JNDI lookup
but this is also does not work and it gives the same error
May 12, 2010 1:55:55 PM com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
java.lang.ClassCastException at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:258)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at com.sun.enterprise.naming.impl.SerialContext.narrowProvider(SerialContext.java:359)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:327)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at ClientMain.main(ClientMain.java:27)
Caused by: java.lang.ClassCastException: Object is not of remote type com.sun.enterprise.naming.impl.SerialContextProvider
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:250)
... 7 more
javax.naming.NamingException: Lookup failed for 'java:global/AsynchEJB/HelloEjbAsynchronous' in SerialContext targetHost=localhost,targetPort=3700,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is java.lang.ClassCastException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at ClientMain.main(ClientMain.java:27)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700,orb'sInitialHost=localhost,orb'sInitialPort=3700 [Root exception is java.lang.ClassCastException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 2 more
Caused by: java.lang.ClassCastException at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:258)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at com.sun.enterprise.naming.impl.SerialContext.narrowProvider(SerialContext.java:359)
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:327)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 3 more
Caused by: java.lang.ClassCastException: Object is not of remote type com.sun.enterprise.naming.impl.SerialContextProvider
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:250)
... 7 more
nitin pokhriyal
Ranch Hand
Joined: May 19, 2005
Posts: 263
posted
0
How about if you just run with lookup. is it working till that point? I have never used glassfish but in jboss we can get the lookup name, there should be a way to figure out what is the name you have to look up in JNDI. I doubt that lookup is not right.
Sonal Popat
Greenhorn
Joined: May 10, 2010
Posts: 9
posted
0
Hello Nitin,
No it doesnt execute any line after the lookup. As, problem occurs at the line of lookup only whatever parameter I am passing in the lookup, its end up with the same java.lang.ClassCastException problem.
I've tried MDB, it works but even for that I had to make connectionFactory under JMS resources, on the Glassfish server.
So, here also I guess, I've to make entry of this Remote EJB somewhere on Glassfish server. But where should I?
How did you deployed your project in glassfish? do you have any .ear file or any ant script to do that.
Sonal Popat
Greenhorn
Joined: May 10, 2010
Posts: 9
posted
0
Yeah, my deployed Remote EJB project is ear file and it is on the glassfish.
Infact, when I click on the deploy it automatically makes an entry in the application section of Glassfish server.
In my clientApp, I am including jar file of EJB module. So I am able to instantiate and then access the methods of the Remote EJB from Client App but not able to access through JNDI lookup.
Direct instantiation works ...
com.ejb.RemoteStateless Rsl = new com.ejb.RemoteStateless();
Rsl.setName("Hello"+str);
System.out.println("Value is = +Rsl.getName());
But,
Context ctx = new InitialContext(); //even I've tried InitialContext ctx = new InitialContext();
com.ejb.RemoteStateless Rsl = (com.ejb.RemoteStateless) ctx.lookup("com.ejb.RemoteStateless");
That's doesn't look like the correct JNDI name. Use the tool provided by your application server to view the JNDI tree and see what JNDI name you should be using. Looking at the logs, it probably is:
Did you find any solution to this problem? We have exactly the same problem, when trying to call an EJB on Glassfish v2.1 from Glassfish v3.0.1. There are differences between the classes needed for an EJB client between v2.1 and v3.0.1, and the client classes for v3.0.1 is already loaded on the v3.0.1 server when looking up the EJB on v2.1.
Specifically, it seems that on lookup the 2.1 server returns an object of the class com.sun.enterprise.naming.SerialContextProvider, while the 3.0.1 client classes expects
com.sun.enterprise.naming.impl.SerialContextProvider and this causes a ClassCastException.
I find it hard to accept that it is impossible to call EJBs on Glassfishv2.1 from Glassfish v3.0.1, so I really hope that someone has a solution for this problem.