• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Class Cast Exception while running client program

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am working on J2ee1.3 app server, I am able to successfully deploy the bean and able to return the client jar file too, but while exectuing my client program I am facing the below mentioned problem, If any one has worked on it, please share your ideas and help me out.
Regards,
Vidya
The exception is as follows:
----------------------------
F:\>java ejbclient
Basic Lookup is Successful....
Got the Object, Final Lookup is Successful....
Caught an unexpected exception!
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at ejbclient.main(ejbclient.java:23)
F:\>

My Client Program:
==================
import javax.rmi.*;
import javax.naming.*;
import ssrem;
import sshome;
public class ejbclient
{
public static void main(String args[])
{
try
{
Context initial = new InitialContext();
Object objref = initial.lookup("shiva");
System.out.println("Basic Lookup is Successful....");
if(objref==null)
{
System.out.println("Couldn't get the Object");
}
else
{
System.out.println("Got the Object, Final Lookup is Successful....");
}
sshome home = (sshome)PortableRemoteObject.narrow(objref,sshome.class);
ssrem ob= home.create();
ob.setString("Hello World");
ob.setIntegers(20,20);
ob.setDoubles(20.2,40.3);
double dd=ob.getDoubles();
int ee=ob.getIntegers();
String str=ob.getString();
System.out.println("The Double Value returned is : "+dd);
System.out.println("The Integer Value returned is : "+ee);
System.out.println("The String Value returned is : "+str);
}
catch (Exception ex)
{
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}
My Doubts:
==========
1. At the time of deploying, it is asking for Local home,Local
rem, remote home, remote rem. I am unable to understand what is the difference between local and remote.
FOR MY CURRENT PROGRAM GIVEN ABOVE, I HAVE USED REMOTE REM AND REMOTE CLASS,
I am new to j2ee, Please help me.
Regards,
Vidya
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from http://www.weblogic.com/docs51/classdocs/API_ejb/EJB_deployover.html


A common problem when deploying and using EJBs and servlets is the ClassCastException. ClassCastExceptions can occur when a class of the same name resides in more than one classloader within WebLogic Server. Although the classes may have the same name and use the same bytecode, if the classes are loaded by separate classloaders, they are treated as different classes. A common scenario is as follows:

An EJB provider uses a support class, "Address" in an EJB's public interface. Upon deployment, the EJB classloader exports the EJB's public interface, and also exports the "Address" class, to the WebLogic classloader.
A servlet developer includes an identical "Address" class as part of a servlet deployment. When the servlet class is deployed, the servlet classloader loads and maintains an identical version of the "Address" class.
The servlet invokes the EJB to obtain a new object of the "Address" class. In this case, WebLogic Server yields a ClassCastException error. Because the "Address" class exists in both the WebLogic classloader and Servlet classloader, they are treated as completely different classes.
To correct such ClassCastException errors, EJB and servlet developers must ensure that no two classloaders ever load an identical class. Specifically, you should always ensure that EJB classes reside only in the deployed EJB .jar file or EJB directory, and that they are not included in other EJB .jar files or classpath definitions.

 
vidya lakshmi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Greg,
Thank you for your reply, I checked my installation and the classpaths, I had set J2EE_HOME,JAVA_HOME(which is jdk1.3 version) in the user environment variables. also, I had set j2ee.jar file in the classpath and bin directory in the path, but could not get the desired result. Please if you had already worked on this, help me out.
Guys, In case, anyone of you have worked on j2ee please do let me know.
Regards,
vidya
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Vidya!
I am in trouble with your"
java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at ejbclient.main(ejbclient.java:23)"
Do you have settled it?Can you help me out?Thanks!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks greg, you solve my problem. I was having the same problem and spent 2 hours tried to figureout what's wrong and finally see you posting by searching.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic