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?
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?