Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

java.lang.ClassCastException During lookup the Local Interface

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I got the following error during the lookup time of Local interface, please help me to solve the problem. ( Websphere 6.0.1, Jsp, EJB2 )

--------
error
------
R java.lang.ClassCastException: test.EJSLocalStatelesscounterHome_8ada3073
at com.ibm._jsp._EJBTest._jspService(_EJBTest.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:117)
at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleRequest(JSPExtensionServletWrapper.java:171)

-------------------------------------------------------------------------
ejb-jar.xml
-----------

<enterprise-beans>
<session id="Session_MyTime">
<description>An EJB named counter</description>
<display-name>Ejb Lccal Counter</display-name>
<ejb-name>Counter</ejb-name>
<local-home>test.CounterLocalHome</local-home>
<local>test.CounterLocal</local>
<ejb-class>test.CounterBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-local-ref>
<description>This is a Counter session</description>
<ejb-ref-name>ejb/Counter</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>test.CounterLocalHome</local-home>
<local>test.CounterLocal</local>
<ejb-link>Counter</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
</ejb-jar>

-------------------------------------------------------------------
Client code ( JSP client)
------------------------
try {
InitialContext context = new InitialContext();
out.println("Context created.....");
CounterLocalHome home =(CounterLocalHome)context.lookup("java:comp/env/ejb/Counter");
CounterLocal remote=home.create();
out.println(" hit count....."+remote.hit()); out.println(" === finished ===== ");
}
catch (Exception e) {
out.println(e);
e.printStackTrace();
}


%>

------------------------------------------------------------------------
web.xml
--------
<web-app id="WebApp_ID" version="2.4"<br /> xmlns="http://java.sun.com/xml/ns/j2ee"<br /> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br /> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee <a href="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; rel="nofollow">" target="_blank">http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">;
<display-name>
counter</display-name>
<ejb-local-ref>
<ejb-ref-name>ejb/Counter</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>test.CounterLocalHome</local-home>
<local>test.CounterLocal</local>
<ejb-link>Counter</ejb-link>
</ejb-local-ref>
</web-app>


=================================================================
I try to Print the lookup Class before going to cast. it print the classs name is

out.print("Output="+context.lookup("java:comp/env/ejb/Counter").toString());

Output === test.EJSLocalStatelesscounterHome_8ada3073@181b8107(BeanId(__homeOfHomes#__homeOfHomes#__homeOfHomes, counter_jar#counter.jar#counter))


please help me to solve the problem....... Advance Thanks.............
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic