The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes problem in ejb3 stateless session bean  client 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 » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "problem in ejb3 stateless session bean  client" Watch "problem in ejb3 stateless session bean  client" New topic

problem in ejb3 stateless session bean client

mohan dodderi
Ranch Hand

Joined: Aug 23, 2004
Posts: 69

i am invoking a bean(POJO)object in stateless session bean through servlets.but getting ClassCastException in Servlet code. whole activity is as fallows

1)there is a method
WeatherBean getRequestData() in stateless session bean which
returns WeatherBean(serialized bean) object.

2)Then there is a servlet which invokes session bean. and calls
getRequestData() method which returns WeatherBean.
i.e WeatherBean weather=statelessbean.getRequestData();

when i build and execute the code i am getting fallowing exception.

java.lang.ClassCastException: com.common.weather.WeatherBean cannot be cast to com.common.weather.WeatherBean
at $Proxy203.getRequestData(Unknown Source)
at com.dcd.SDPRequestDispatcher.dispatchRequest(SDPRequestDispatcher.java:330)
at com.servlet.DashboardProxyServlet.processRequest(DashboardProxyServlet.java:102)
at com.servlet.DashboardProxyServlet.doPost(DashboardProxyServlet.java:155)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:183)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:189)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:90)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:96)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:325)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

if anyone know the answer please help me.

Mohana dodderi
Reza Rahman
Ranch Hand

Joined: Feb 01, 2005
Posts: 580

This is a class-loader issue probably caused because you have two copies of weather bean in the EJB-JAR and the WAR. As a result, the weather bean is being loaded twice and the copy you are passing from the EJB container is conflicting with the copy that's being loaded by the web container.

Try re-packaging the bean either as a separate "client API" jar or putting it only in the EJB-JAR. In the former case, the client jar is a module dependency for both the EJB-JAR and the WAR. In the latter case, the EJB-JAR is a module dependency for the WAR (this is simpler and it is what I personally prefer).

Remember that most system admins will not allow you to copy classes in different JARs willy nilly, so module dependencies are something you ought to have an understanding of :-). Java EE packaging is covered in most good references, ours certainly has it, as does our freely available example code.


P.S.: If this is an intra-vm call from the web to the EJB container, why bother with remoting, serialization, etc?

Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
mohan dodderi
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
Hi Rahman

i am using single jar file which comprises WeatherBean.and using the same jar file in ejb and servlet. also ejb is running in remote location. that means running in diff system.and Wheather bean has SerialUID. any other clues.

Mohana dodderi
Justin Bleach

Joined: Jun 16, 2008
Posts: 11
mohan dodderi wrote:Hi Rahman

i am using single jar file which comprises WeatherBean.and using the same jar file in ejb and servlet. also ejb is running in remote location. that means running in diff system.and Wheather bean has SerialUID. any other clues.

Mohana dodderi

Funny you mention this; came across this post in a Google search. I'm having the same issue. Stateless bean called via a delegate that retrieves the EJB local interface. When returning an object that wraps a File to the calling servlet get the classcastexception and I am 100% certain it is not a JBoss class loading issue.

When I don't wrap the File and just pass the File object back it works. I don't see how wrapping the File makes any difference. The wrapper implements serializable....

Obviously my situation is a bit more complicated but I believe we are experiencing the same problem underneath the layers.

Of course it's typical any time I search for issues via Google I come across boards where the question has never been answered from years ago!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: problem in ejb3 stateless session bean client
Similar Threads
Problem deploying spring - gwt application in JBoss 5.0.1 GA
newbie error
Bacis doubt input property in struts-config.xml
I set up JBoss mail, so why can't I access the mail bean?
Problem Upload files on google docs through Liferay portal 6.0.6