I could reproduce this on my setup. Here's how my ear and war (which are deployed
separately) look like:
EAR
myapp.ear
| |
| |
| |--- myejb.jar
| | |
| | |--- <interfaces and bean implementation>
|
|
WAR
mywebapp.war
| |
| |
| |--- lib
| | |
| | |--- myejb.jar (copy of the same that is present in myapp.ear)
| | | |
| | | |--- <bean interfaces>
|
|
When i try to lookup the bean from the WAR i run into ClassCastException when casting the
returned object to my remote interface of the bean (irrespective of whether its SLSB or
SFSB):
InitialContext ctx = new InitialContext();
| UserManagerRemote usr = (UserManagerRemote)
ctx.lookup("RemoteUserManagerBean");
|
19:59:27,704 INFO [STDOUT] Caught exception
| 19:59:27,704 ERROR [STDERR] java.lang.ClassCastException: $Proxy119
| 19:59:27,704 ERROR [STDERR] at org.apache.jsp.test_jsp._jspService(test_jsp.java:75)
| 19:59:27,704 ERROR [STDERR] at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
| 19:59:27,704 ERROR [STDERR] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
| 19:59:27,704 ERROR [STDERR] at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
| 19:59:27,704 ERROR [STDERR] at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
| 19:59:27,704 ERROR [STDERR] at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
| 19:59:27,704 ERROR [STDERR] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
| 19:59:27,704 ERROR [STDERR] at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
| 19:59:27,704 ERROR [STDERR] at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
| 19:59:27,704 ERROR [STDERR] at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
| 19:59:27,704 ERROR [STDERR] at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
| 19:59:27,704 ERROR [STDERR] at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
| 19:59:27,704 ERROR [STDERR] at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
| 19:59:27,704 ERROR [STDERR] at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
| 19:59:27,704 ERROR [STDERR] at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
| 19:59:27,704 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
|
|
Here's what happening -
* The bean gets deployed as part of the EAR deployment. The bean and its interfaces are
loaded by the JBoss Unified Classloader (or the scoped classloader of the EAR, if
configured). Lets call this Classloader-A
* The WAR is then deployed in its own isolated classloader. Using the isolated classloader
for each WAR file is configured by default. Let's call this ClassLoader-B
* When the lookup is done from the WAR file and the object cast to the bean interface, the
bean interface in now loaded by Classloader-B. As a result, the ClassCastException.
Here's what you have to do:
1) Remove the jboss-app.xml and jboss-web.xml which we had added while debugging this
issue. The intention now is to not isolate the classloaders and instead use a single
classloader for both the applications.
2) In the %JBOSS_HOME%/server/<
serverName>/deploy/jboss-web.deployer/META-INF/jboss-service.xml file, change the value
of UseJBossWebLoader to true (by default its false):
<!-- A flag indicating if the JBoss Loader should be used. This loader
| uses a unified class loader as the class loader rather than the tomcat
| specific class loader.
| The default is false to ensure that wars have isolated class loading
| for duplicate jars and jsp files.
| -->
| <attribute name="UseJBossWebLoader">true</attribute>
|
As mentioned in this comments, if this attribute is set to false, isolated classloader
will be used for the WAR. Since we want to avoid this, we will set it to true.
P.S: The changes to this file will affect all web applications on the server.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4190910#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...