Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

EJB client for Websphere throws ClassCastException

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I'm Using Websphere Application Server 3.5.4. I'm able to succeessfully deploy an EJB, but when I run the following client code It gives me "ClassCastException"
-------------------------------------------------------
InitialContext ivjInitContext = null;
bgc.ipt.ejb.IPTLeasedLinePriceEstimatorHome beanHome = null;
bgc.ipt.ejb.IPTLeasedLinePriceEstimator remote = null;
// Get the initial context
try {
Properties properties = new Properties();
// Get location of name service
properties.put(javax.naming.Context.PROVIDER_URL,
"iiop://bharani_kumar:900/";);
// Get name of initial context factory
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory");

ivjInitContext = new InitialContext(properties);
Object homeObject = null;
homeObject = ivjInitContext.lookup("bharani");
//System.out.println(ivjInitContext.lookup("bharani").getClass().getName());
beanHome = (bgc.ipt.ejb.IPTLeasedLinePriceEstimatorHome) javax.rmi.PortableRemoteObject.narrow(homeObject,
bgc.ipt.ejb.IPTLeasedLinePriceEstimatorHome.class);

} catch (Exception e) { // Error getting the initial context
System.out.println("Error: "+e);
e.printStackTrace();
}
----------------------------------------------------------------
The following is the exception I get

Error : java.lang.ClassCastException
java.lang.ClassCastException
at com.ibm.ejs.ns.jndi.CNContextImpl.isContextLocalCheck(CNContextImpl.java:1340)
at com.ibm.ejs.ns.jndi.CNContextImpl.doLookup(CNContextImpl.java:764)
at com.ibm.ejs.ns.jndi.CNContextImpl.lookup(CNContextImpl.java:590)
at javax.naming.InitialContext.lookup(InitialContext.java:349)
at EJBClient.main(EJBClient.java:30)
Interactive Session Ended
I have tried setting the classpath Deployed EJB jar file as someone mentioned before. But The problem still exists.
Please Help Me!!!
Thanking you in anticipation,
- Bharani
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:
ivjInitContext = new InitialContext(properties);
Object homeObject = null;
homeObject = ivjInitContext.lookup("bharani");
//System.out.println(ivjInitContext.lookup("bharani").getClass().getName());
beanHome = (bgc.ipt.ejb.IPTLeasedLinePriceEstimatorHome)homeObject;
because you already have the home interface after you look it up with context.lookup()
Hope it works.
Francisco
 
Bharani Marepalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Francisco,
The problem here is, It fails at
homeObject = ivjInitContext.lookup("bharani");
It prints the same line number in Stack trace too. But If I give a message after that line it doesn't print that.
But If I give some arbitrary name, in stead of a JNDI name (ie. if I give ivjInitContext.lookup("bharani765765")), It appropriately throws NameNotFoundException. That does mean that I'm getting the right context and my "lookup" call goes to my EJB server. I dont know what's happening inside, which throws this ClassCastException.
Somebody Please help me.
- Bharani
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic