File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes java.lang.ClassCastException  During lookup the Local Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "java.lang.ClassCastException  During lookup the Local Interface" Watch "java.lang.ClassCastException  During lookup the Local Interface" New topic
Author

java.lang.ClassCastException During lookup the Local Interface

babujava jayaraman
Greenhorn

Joined: Apr 28, 2007
Posts: 5
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.............
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.ClassCastException During lookup the Local Interface