File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Class Cast Exception while running client program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Class Cast Exception while running client program" Watch "Class Cast Exception while running client program" New topic
Author

Class Cast Exception while running client program

vidya lakshmi
Greenhorn

Joined: Jun 22, 2001
Posts: 2
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
greg philpott
Ranch Hand

Joined: Nov 10, 2000
Posts: 73
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

Joined: Jun 22, 2001
Posts: 2
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
jz
Greenhorn

Joined: Aug 21, 2002
Posts: 1
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!
skywing us
Greenhorn

Joined: Oct 22, 2003
Posts: 1
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.
 
Consider Paul's rocket mass heater.
 
subject: Class Cast Exception while running client program
 
Similar Threads
class not found error!!
NoClassDefFoundError
Execution of EJB Client
Getting Class cast exception while Lookup EJB2.1 session bean using JNDI name in WAS6.1
How to run a client...