Inter deployment communication
swig Oct 12, 2011 11:52 AMI have setup like below -
MyApp1.ear
|
|--- myApp1.war (This App1 is just one servlet)
|--- lib/mybase.jar (Common classes like datamodel definations)
MyApp2.ear
|
|--- myApp2.war (Web part i.e. Servlets of my App2)
|--- myApp2Enterprise.ear (Ejbs of my App2)
|--- lib/mybase.jar (Common classes like datamodel definations)
MyApp3.ear
|
|--- myApp3.war (Web part i.e. Servlets of my App3)
|--- myApp3Enterprise.ear (Ejbs of my App3)
|--- lib/mybase.jar (Common classes like datamodel definations)
MyApp1.ear is the entry point for any user to the Application. This application has only one Servlet. This servlet forward the httprequest to any of the servlet part of MyApp2.ear or MyApp3.ear and so on depending on request parameters. I am using Requestdispacher.farward(req,resp) to hit the destiantion deployment. Before forwarding the request I am setting an attribute(Object of datamodel class defined in mybase.jar) in request.
Now issue is when i try to use req.getAttribute("myobj") in myApp2.ear or myApp3.ear servlet, I get below ClassCastException -
java.lang.ClassCastException: com.meme.core.common.datamodel.CDR cannot be cast to com.meme.core.common.datamodel.CDR
com.meme.rider.callflowhandler.CallDataRecordHandler.doGet(CallDataRecordHandler.java:71) <- This is myApp2.ear Servlet
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
com.meme.cdr.servlet.CDRHandlerProxy.doGet(CDRHandlerProxy.java:91) <- This is myApp1.ear Servlet
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
As most of you might have already understood the cause by now. Yes different deployments (i.e. MyApp1.ear, myApp2.ear , myApp3.ear) are using different class loader so I am not able to cast back my object in the destination ear.
Can you please help me How can i specify to use single Classloader for classes defined in mybase.jar across all the deployments.
Please help me if there exist any other better solution too. I browsed a lot since yesterday but couldnt get any relevant post for AS7.
PS: I can not afford to use same classloader across all my deployments becasue there could be multiple deployments with same qualified class names. i.e. In future it is very much possible that my myApp3.ear and myApp4.ear would have same code just with different persistence.xml and webappName in web.xml of containing .war.