• 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

session bean -classcast exception

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I deployed example ear file in JBoss, Jboss gave class cast exception- portable remote object.
I am using RHEL 4

my profram is like this downloaded from net, example3.ear from roseindia.net. The code is like this

bean:
public class MyTestSessionBean

implements SessionBean

{



public void ejbCreate()

throws

CreateException

{

}



public String SayHello(){

String msg="Hello! I am Session Bean";

System.out.println(msg);

return msg;

}



public void setSessionContext( SessionContext aContext )

throws EJBException

{



}



public void ejbActivate()

throws EJBException

{

}



public void ejbPassivate()

throws EJBException

{

}



public void ejbRemove()

throws EJBException

{

}

}


servlet:
package test.session;



import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import javax.naming.*;

import javax.rmi.PortableRemoteObject;









public class SessionTestServlet extends HttpServlet {

MyTestSessionHome testSessionBean;



public void init(ServletConfig config) throws ServletException{

//Look up home interface

try {

InitialContext ctx = new InitialContext();

Object objref = ctx.lookup("ejb/test/MyTestSessionBean");

testSessionBean = (MyTestSessionHome)PortableRemoteObject.narrow(objref, MyTestSessionHome.class);

} catch (Exception NamingException) {

NamingException.printStackTrace();

}





}



public void doGet (HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException

{



PrintWriter out;

response.setContentType("text/html");

String title = "EJB Example";

out = response.getWriter();



out.println("<html>");

out.println("<head>");

out.println("<title>Hello World Servlet!</title>");

out.println("</head>");

out.println("<body>");

out.println("<p align=\"center\"><font size=\"4\" color=\"#000080\">Servlet Calling Session Bean</font></p>");





try{

MyTestSession beanRemote;

beanRemote = testSessionBean.create();

out.println("<p align=\"center\"> Message from Session Bean is: <b>" + beanRemote.SayHello() + "</b></p>");

beanRemote.remove();

}catch(Exception CreateException){

CreateException.printStackTrace();

}

out.println("<p align=\"center\"><a href=\"javascript:history.back()\">Go to Home</a></p>");

out.println("</body>");

out.println("</html>");





out.close();

}



public void destroy() {

System.out.println("Destroy");

}

}

ejb-jar.xml:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">



<ejb-jar>



<description>Example 3</description>

<display-name>Example 3</display-name>



<enterprise-beans>



<!-- Session Beans -->

<session id="test_MyTestSession">

<display-name>My Test Session Bean</display-name>

<ejb-name>test/MyTestSession</ejb-name>

<home>test.session.MyTestSessionHome</home>

<remote>test.session.MyTestSession</remote>

<ejb-class>test.session.MyTestSessionBean</ejb-class>

<session-type>Stateless</session-type>

<transaction-type>Container</transaction-type>

</session>



</enterprise-beans>



<assembly-descriptor>



</assembly-descriptor>



</ejb-jar>



jboss.xml:

<jboss>

<enterprise-beans>

<session>
<ejb-name>test/MyTestSession</ejb-name>
<jndi-name>ejb/test/MyTestSessionBean</jndi-name>
</session>

</enterprise-beans>

<resource-managers>
</resource-managers>

</jboss>

i have set JBOSS_HOME, jdk path, class path to
JAVA_HOME= /usr/java/jdk1.5.0_11
PATH=/usr/java/jdk1.5.0_11/bin:$PATH
CLASSPATH=/usr/java/jdk1.5.0_11/lib:$CLASSPATH
JBOSS_HOME=/home/servers/java/jboss-4.0.5.GA

when i copy , i am getting exception in Jboss. I am unable to resolve this. Should i set any env varible, or jar should be included.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at ClassCastExceptions, specifically the jmx-console method mentioned over there.
 
gayathri jayapalan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the jboss this is the error:

java.lang.ClassCastException
[STDERR] at com.sun.corba.se.impl.javax.rmi.PortableRemot eObject.narrow(PortableRemoteObject.java:229)
at javax.rmi.PortableRemoteObject.narrow(Portabl eRemoteObject.java:137)
at test.session.SessionTestServlet.init(SessionT estServlet.java:29)
at org.apache.catalina.core.StandardWrapper.load Servlet(StandardWrapper.java:1105)
 
gayathri jayapalan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found the problem. i don't know how to resolve it.

The JDK which i have installed is jdk1.0.5_11
In this rt.jar has 2 Portable object classes at
1.at com.sun.corba.se.impl.javax.rmi.PortableRemot eobject.narrow(PortableRemoteObject.java:229)
2.at javax.rmi.PortableRemoteObject.narrow(Portabl eRemoteObject.java:137)

That is y when i copy the bean it was giving this exception. i need soln for this
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Are you sure that the object at "ejb/test/MyTestSessionBean" is of type "MyTestSessionHome" ?

2. Are you sure there is a jndi-name tag allowed in the session tag ?
 
gayathri jayapalan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[root@gayathri bin]# ./run.sh
run.sh: Missing file: /lib/tools.jar
run.sh: Unexpected results may occur. Make sure JAVA_HOME points to a JDK and not a JRE.

=========================================================================

JBoss Bootstrap Environment

JBOSS_HOME: /home/servers/java/jboss-4.0.5.GA-src/build/output/jboss-4.0.5.GA

JAVA: java

JAVA_OPTS: -Dprogram.name=run.sh -server -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000

CLASSPATH: /home/servers/java/jboss-4.0.5.GA-src/build/output/jboss-4.0.5.GA/bin/run.jar:/lib/tools.jar

=========================================================================

Is it not finding tools.jar
 
gayathri jayapalan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yaah, home class name is correct, jndi name is reqd
 
gayathri jayapalan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i deploy a session bean in JBoss, while deploying i got classcast exception . When i am looking thro ctxlook up, it is always returing the object ref as JNDI name+Home. why this error is coming? i need help.
servlet code


THis is the output in Jboss:

393 INFO [STDOUT] bbbbbbbbbejb/test/MyTestSessionBean/remoteHome
11:43:38,408 ERROR [STDERR] java.lang.ClassCastException
11:43:38,413 ERROR [STDERR] at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)


If the code is like this in the lookup:
Object objref = ctx.lookup("ejb/test/MyTestSessionBean");


It returns objref like this:MyTestSessionBeanHome - This class does not exist.
I need help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic