You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by ia...@vacosolventus.com on 2009/02/02 11:01:49 UTC

java.lang.ClassCastException: $Proxy8

Hello,

I am trying to run a simple OpenEJB project using JSP and Tomcat. I could not find a proper way to reference EJB from JSP so I tired using the same code that works fine in a unit test, but not in JSP.

<%
        Properties p = new Properties();
	p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
	InitialContext initialContext = new InitialContext( p );
	Object o = initialContext.lookup("SayHelloLocal");
	SayHelloLocal local = (SayHelloLocal)o;
%>

However, during the cast operation on the last line above, the class loader throws java.lang.ClassCastException: $Proxy8. This seems to happen when JasperClassLoader trying to load the SayHelloLocal class.

I am using the latest OpenEJB release so I only have the ejb-jar.xml file and I use annotations to discover and load EJBs. This works fine during unit testing.

Is there a correct way to reference the EJB from JSP using JNDI name that works with OpenEJB? Did I not set the classpath correctly for Tomcat? I am using Tomcat 6.0. The below output is from Console window within Eclipse 3.4.

Cheers,
Arkady

Feb 2, 2009 10:40:21 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SayHelloWeb' did not find a matching property.
Feb 2, 2009 10:40:21 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/jdk1.5.0_16/jre/lib/i386/client:/usr/java/jdk1.5.0_16/jre/lib/i386:/usr/java/jdk1.5.0_16/jre/../lib/i386:/opt/MozillaFirefox/lib
Feb 2, 2009 10:40:21 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 2, 2009 10:40:21 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1004 ms
Feb 2, 2009 10:40:21 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 2, 2009 10:40:22 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
Feb 2, 2009 10:40:23 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Feb 2, 2009 10:40:23 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Feb 2, 2009 10:40:24 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/124  config=null
Feb 2, 2009 10:40:24 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2163 ms
Apache OpenEJB 3.1    build: 20081009-03:31
http://openejb.apache.org/
INFO - openejb.home = /home/aglabek
INFO - openejb.base = /home/aglabek
INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Found EjbModule in classpath: /home/aglabek/.eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SayHelloWeb/WEB-INF/lib/SayHello.jar
INFO - Beginning load: /home/aglabek/.eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SayHelloWeb/WEB-INF/lib/SayHello.jar
INFO - Configuring enterprise application: classpath.ear
INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean SayHello: Container(type=STATELESS, id=Default Stateless Container)
INFO - Enterprise application "classpath.ear" loaded.
INFO - Assembling app: classpath.ear
INFO - Jndi(name=SayHelloLocal) --> Ejb(deployment-id=SayHello)
INFO - Jndi(name=SayHelloRemote) --> Ejb(deployment-id=SayHello)
INFO - Created Ejb(deployment-id=SayHello, ejb-name=SayHello, container=Default Stateless Container)
INFO - Deployed Application(path=classpath.ear)
Feb 2, 2009 10:40:30 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: $Proxy8
	at org.apache.jsp.index_jsp._jspService(index_jsp.java:71)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:595)





Re: java.lang.ClassCastException: $Proxy8

Posted by David Blevins <da...@visi.com>.
Hi Arkady,

This seems like a classpath issue.  The SayHelloLocal class is likely  
existing in two different classloaders.  The most likely cause for  
that could be the class is on system classpath and then again on the  
webapp classpath due to how things are configured.   Try some code  
like this to help in the debug:


     Object object = initialContext.lookup("SayHelloLocal");

     Class expected = SayHelloLocal.class;
     Class actual = null;
     for (Class clazz : object.getClass().getInterfaces()) {
         if (clazz.getName().equals(expected.getName())) {
             actual = clazz;
             break;
         }
     }

     if (actual == null) throw new IllegalStateException("Not the  
proxy we were looking for");

     ClassLoader expectedClassLoader = expected.getClassLoader();
     ClassLoader actualClassLoader = actual.getClassLoader();

     System.out.println(expectedClassLoader);
     System.out.println(actualClassLoader);

     if (expectedClassLoader != actualClassLoader) throw new  
IllegalStateException("Not the same class");



-David


On Feb 2, 2009, at 2:01 AM, iaglabek@vacosolventus.com wrote:

> Hello,
>
> I am trying to run a simple OpenEJB project using JSP and Tomcat. I  
> could not find a proper way to reference EJB from JSP so I tired  
> using the same code that works fine in a unit test, but not in JSP.
>
> <%
>        Properties p = new Properties();
> 	p.setProperty(Context.INITIAL_CONTEXT_FACTORY,  
> "org.apache.openejb.client.LocalInitialContextFactory");
> 	InitialContext initialContext = new InitialContext( p );
> 	Object o = initialContext.lookup("SayHelloLocal");
> 	SayHelloLocal local = (SayHelloLocal)o;
> %>
>
> However, during the cast operation on the last line above, the class  
> loader throws java.lang.ClassCastException: $Proxy8. This seems to  
> happen when JasperClassLoader trying to load the SayHelloLocal class.
>
> I am using the latest OpenEJB release so I only have the ejb-jar.xml  
> file and I use annotations to discover and load EJBs. This works  
> fine during unit testing.
>
> Is there a correct way to reference the EJB from JSP using JNDI name  
> that works with OpenEJB? Did I not set the classpath correctly for  
> Tomcat? I am using Tomcat 6.0. The below output is from Console  
> window within Eclipse 3.4.
>
> Cheers,
> Arkady
>
> Feb 2, 2009 10:40:21 PM  
> org.apache.tomcat.util.digester.SetPropertiesRule begin
> WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context}  
> Setting property 'source' to  
> 'org.eclipse.jst.jee.server:SayHelloWeb' did not find a matching  
> property.
> Feb 2, 2009 10:40:21 PM  
> org.apache.catalina.core.AprLifecycleListener init
> INFO: The APR based Apache Tomcat Native library which allows  
> optimal performance in production environments was not found on the  
> java.library.path: /usr/java/jdk1.5.0_16/jre/lib/i386/client:/usr/ 
> java/jdk1.5.0_16/jre/lib/i386:/usr/java/jdk1.5.0_16/jre/../lib/i386:/ 
> opt/MozillaFirefox/lib
> Feb 2, 2009 10:40:21 PM org.apache.coyote.http11.Http11Protocol init
> INFO: Initializing Coyote HTTP/1.1 on http-8080
> Feb 2, 2009 10:40:21 PM org.apache.catalina.startup.Catalina load
> INFO: Initialization processed in 1004 ms
> Feb 2, 2009 10:40:21 PM org.apache.catalina.core.StandardService start
> INFO: Starting service Catalina
> Feb 2, 2009 10:40:22 PM org.apache.catalina.core.StandardEngine start
> INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
> Feb 2, 2009 10:40:23 PM org.apache.coyote.http11.Http11Protocol start
> INFO: Starting Coyote HTTP/1.1 on http-8080
> Feb 2, 2009 10:40:23 PM org.apache.jk.common.ChannelSocket init
> INFO: JK: ajp13 listening on /0.0.0.0:8009
> Feb 2, 2009 10:40:24 PM org.apache.jk.server.JkMain start
> INFO: Jk running ID=0 time=0/124  config=null
> Feb 2, 2009 10:40:24 PM org.apache.catalina.startup.Catalina start
> INFO: Server startup in 2163 ms
> Apache OpenEJB 3.1    build: 20081009-03:31
> http://openejb.apache.org/
> INFO - openejb.home = /home/aglabek
> INFO - openejb.base = /home/aglabek
> INFO - Configuring Service(id=Default Security Service,  
> type=SecurityService, provider-id=Default Security Service)
> INFO - Configuring Service(id=Default Transaction Manager,  
> type=TransactionManager, provider-id=Default Transaction Manager)
> INFO - Found EjbModule in classpath: /home/ 
> aglabek/.eclipse/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/ 
> wtpwebapps/SayHelloWeb/WEB-INF/lib/SayHello.jar
> INFO - Beginning load: /home/aglabek/.eclipse/.metadata/.plugins/ 
> org.eclipse.wst.server.core/tmp0/wtpwebapps/SayHelloWeb/WEB-INF/lib/ 
> SayHello.jar
> INFO - Configuring enterprise application: classpath.ear
> INFO - Configuring Service(id=Default Stateless Container,  
> type=Container, provider-id=Default Stateless Container)
> INFO - Auto-creating a container for bean SayHello:  
> Container(type=STATELESS, id=Default Stateless Container)
> INFO - Enterprise application "classpath.ear" loaded.
> INFO - Assembling app: classpath.ear
> INFO - Jndi(name=SayHelloLocal) --> Ejb(deployment-id=SayHello)
> INFO - Jndi(name=SayHelloRemote) --> Ejb(deployment-id=SayHello)
> INFO - Created Ejb(deployment-id=SayHello, ejb-name=SayHello,  
> container=Default Stateless Container)
> INFO - Deployed Application(path=classpath.ear)
> Feb 2, 2009 10:40:30 PM  
> org.apache.catalina.core.StandardWrapperValve invoke
> SEVERE: Servlet.service() for servlet jsp threw exception
> java.lang.ClassCastException: $Proxy8
> 	at org.apache.jsp.index_jsp._jspService(index_jsp.java:71)
> 	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
> 	at  
> org 
> .apache 
> .jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
> 	at  
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: 
> 342)
> 	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
> 	at  
> org 
> .apache 
> .catalina 
> .core 
> .ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java: 
> 290)
> 	at  
> org 
> .apache 
> .catalina 
> .core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> 	at  
> org 
> .apache 
> .catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 
> 233)
> 	at  
> org 
> .apache 
> .catalina.core.StandardContextValve.invoke(StandardContextValve.java: 
> 191)
> 	at  
> org 
> .apache 
> .catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
> 	at  
> org 
> .apache 
> .catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> 	at  
> org 
> .apache 
> .catalina.core.StandardEngineValve.invoke(StandardEngineValve.java: 
> 109)
> 	at  
> org 
> .apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java: 
> 286)
> 	at  
> org 
> .apache.coyote.http11.Http11Processor.process(Http11Processor.java: 
> 845)
> 	at org.apache.coyote.http11.Http11Protocol 
> $Http11ConnectionHandler.process(Http11Protocol.java:583)
> 	at org.apache.tomcat.util.net.JIoEndpoint 
> $Worker.run(JIoEndpoint.java:447)
> 	at java.lang.Thread.run(Thread.java:595)
>
>
>
>
> <SayHello.java><SayHelloLocal.java><SayHelloRemote.java><ejb-jar.xml>