4 Replies Latest reply on Oct 12, 2011 1:06 PM by swig

    Inter deployment communication

    swig Newbie

      I 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.

        • 1. Re: Inter deployment communication
          jaikiran pai Master

          swig wrote:

           

          I 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)

           

          Does the mybase.jar in all those 3 applications have the exact same classes? I mean, would there be a chance where those jars might have different versions of the same class? If they are expected to be of the same version, then you could have create a "module" out of it and added it as a dependency to all 3 .ears. But given that this jar contains a persistence.xml (doesn't it?), things might not be straightforward.

          • 2. Re: Inter deployment communication
            swig Newbie

            Thanks Kiran for the reply..

             

            I am planning to keep same Classes in mybase.jar for all the applications, any application specific thing would be encapsulated in that very application. So there doesnt seem any scope of having diff version of mybase.jar for diff applications.

             

            Making it a seperate module looks cool..  This i think is just like droping it in deployement folder.. and adding it to dependencies in 3 application's MAINEFEST.MF? OR Do i need to touch any xml?

             

            persistence.xml is part of application ears.. not mybase.jar

            • 3. Re: Inter deployment communication
              jaikiran pai Master

              Ok, so your requirement appears to be feasible. All you have to do is

               

              1) create a (JBoss) module

              2) and add it as a dependency in your .ears.

               

              For #1 see this https://docs.jboss.org/author/display/MODULES/Home

              For #2 see this https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7 .Check the jboss-deployment-structure.xml section. Personally, I would recommend using that file instead of the MANIFEST.MF approach, which works too.

               

              Feel free to ask more questions if you run into issues trying this out.

              • 4. Re: Inter deployment communication
                swig Newbie

                I will try this approach now..

                 

                Just one thing.. mybase.jar has Logging framework too.. which interns uses jboss.logger.

                So right now having different apps using their own Logger embedded mybase.jar.

                 

                But using modular dependency specified above all Log messages from all the appilcations would hit to same mybase.jar's module.

                Will it not be a performance impact?

                 

                Thanks for the Help!! This was my first post to the forum.. n ws fruitful