6 Replies Latest reply on May 23, 2008 8:17 PM by Nikolay Elenkov

    communication between Seam web apps (single EAR)

    Nikolay Elenkov Master

      Hello,


      What would be the preferred (most 'Seam-like') approach to
      communicate between two Seam web apps in a single EAR?


      We have the following scenario:



      • One web app manages remote client authentication and sessions (XML/HTTP, but not SOAP) (app1)

      • The second web app (app2) has a management GUI and we need to:




      1. be able to change settings and passwords that affect the app1

      2. log out a specified client that is logged in app1



      1. is fairly easy: we store the settings/passwords in the DB and access them using shared Seam components. To achieve 2. we need to somehow call into app1. I could use Seam remoting but that would raise other issues (authentication for one, I wouldn't want just anyone to be able to log clients out), so I'd like to make the call into app1 in-process. Is there an easy way to expose a Seam component (not an EJB) so that it can be called from the other web app?


      TIA

        • 1. Re: communication between Seam web apps (single EAR)
          Tom Goring Apprentice

          sounds to me they should be one app.....

          • 2. Re: communication between Seam web apps (single EAR)
            Nikolay Elenkov Master

            Tom Goring wrote on Apr 23, 2008 11:32 PM:


            sounds to me they should be one app.....


            They used to be :) However, both apps needs independent session/auth management:



            • for app1, session timeout should be one-two days. Authentication is simple: store client ID in session; control access with a filter.  (no views, hence no need for pages.xml, etc.)

            • for app2 (administration app), session timeout should be 10-20 minutes. Lots of views, role-based access control, uses Seam for authentication/authorization.


            • 3. Re: communication between Seam web apps (single EAR)
              Tom Goring Apprentice

              For the changes to your user name and password these will be picked up as the database and your entity EJB's would be shared.


              My understanding is that all the seam context's are managed in the scope of the WAR so you won't be able to share them.  You'd have to put your own thing together to handle that....




              • 4. Re: communication between Seam web apps (single EAR)
                Nikolay Elenkov Master

                Tom Goring wrote on Apr 24, 2008 11:03 AM:


                For the changes to your user name and password these will be picked up as the database and your entity EJB's would be shared.


                Yes, that's what I have now. I have a couple of stateless beans at application scope to handle authentication and such. Those are used form both web apps.



                My understanding is that all the seam context's are managed in the scope of the WAR so you won't be able to share them.  You'd have to put your own thing together to handle that....



                That's what I was afraid of :) Thanks for the confirmation. I guess it will have to wait till the next release...



                • 5. Re: communication between Seam web apps (single EAR)
                  David Holbrook Newbie

                  I'm pretty sure you can do what you want with JMS.


                  The documentation is a bit sparse, but it says it can be done:


                  Reference Doc: Messaging in Seam


                  On the invalidating web app you would publish to a topic a message about ending all sessions for a user.


                  On the other web app you would have a Message Driven Bean that was also a Seam component, the Message Driven Beam could then invalidate the session (or raise a seam event for some other component to take care of the invalidation)


                  There are other ways: timer service that polls the db, web service that calls an invalidate method, you could probably hack something together with a shared cache and a filter.  I think JMS is the cleanest.

                  • 6. Re: communication between Seam web apps (single EAR)
                    Nikolay Elenkov Master

                    I didn't want to get JMS in the mix, but that's what I eventually did. It turned out there are other cases where I need one webapp to notify the other, so it was worth the effort.


                    Here's what I have:



                    1. a notifcation Queue

                    2. a listener component (a POJO thath implements MessageListener; not an MDB, since it needs to live in the webapp)

                    3. a startup component that is called after Seam initializations (via an Observer)

                    4. an HttpAttributeListener that stores sessions of interests in a Map



                    The startup component registers the listener for the Queue (webapp2) and onMessages (sent from webapp1) it searches for the relevant HttpSession and invalidates it.


                    Now I just have to make sure no one else can send messages to that Queue...