J2EE Clients: NoInititialContextException to ClassCastException on SJAS 8.2

A

antonyf

I'm learning J2EE using the Sun Java Application Server 8.2 and have
stuck on building clients (not using the deploytool) and doing JNDI
lookups/getting the InitialContext. I've read all i can in tutorials
and forums but i still can't make it work. This is where my problem is:

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:3700");
Context ic = new InitialContext(env);
Object o = ic.lookup("AdviceBean");
AdviceHome home = (AdviceHome) PortableRemoteObject.narrow(o,
AdviceHome.class);

This is the error i get:

java.lang.ClassCastException
at PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at AdviceClient.main(AdviceClient.java:20)

If i exchange the three bottom lines to:

System.out.println(o.getClass()); i get the following result with no
errors:

class com.sun.corba.se.internal.iiop.CDRInputStream_1_0$1

I don't know what to make of this? As I understand it the code is
finding the object (Home Interface) bound to the JNDI name "AdviceBean"
(because if i change this name i get a NameNotFoundException) - but the
class type is wrong? Do i need to do more than narrow and cast the
results becaust it's using IIOP protocol?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top