8 Replies Latest reply on Aug 21, 2007 2:46 AM by urosmil

    Seam Remoting - ajax request after session expires

    urosmil

      Hi,

      after session expires I can access bean with Seam Remoting (as I understand new bean is created). Problem is that other necessary beans are not there. I would like to redirect page from which ajax request is sent if session is expired.
      What is preferred way with Seam to handle this?
      I am thinking to extend ResourceServlet and return something like:

      <envelope><header><context></context></header><body>
      <redirectPage to="/login.jsf"> <-- This is important part
      </body></envelope>

      if session is expired. But can I intercept Seam Remoting response in javascript?

      Thanks,
      Uros!

        • 1. Re: Seam Remoting - ajax request after session expires
          urosmil

          Just to add: I am using Seam 1.2.1 GA.

          • 2. Re: Seam Remoting - ajax request after session expires
            monkeyden

            BUMP

            I'd like the know the elegant solution for this too. Seems to me that the request itself would keep the session alive, rather than simply querying for remaining time left, if any.

            • 3. Re: Seam Remoting - ajax request after session expires
              urosmil

              Hi.
              Me again.

              Is it possible that Seam engineers overlooked this real life situation?
              Do you have some recommendation?
              Would this be fixed in Seam 2.0?

              I really enjoy working with Seam so I hope you would understand this as my attempt to help.

              Thanks,
              Uros!

              • 4. Re: Seam Remoting - ajax request after session expires
                livenow

                hi, it's better to post such thinks in Jira

                http://jira.jboss.org/jira/browse/JBSEAM

                as it may be overlooked here.

                cheers,
                livenow

                • 5. Re: Seam Remoting - ajax request after session expires
                  pmuir

                  JIRA is for feature requests and bugs with Seam. Please do not post support requests there. These issues will just be closed with a comment to ask on the forum.

                  • 6. Re: Seam Remoting - ajax request after session expires
                    urosmil

                    Hi Pete,

                    but isn't this feature that's missing (or bug)?
                    I wouldn't post this in JIRA if you think this doesn't belongs there!

                    Thanks,
                    Uros!

                    • 7. Re: Seam Remoting - ajax request after session expires
                      shane.bryzak
                      • 8. Re: Seam Remoting - ajax request after session expires
                        urosmil

                        Hi,

                        I am back with my solution for this issue.
                        This is what I did to solve problem (I hope this can help someone):

                        SERVER SIDE:

                        1) Create Filter:

                        public class SeamRemotingSessionValidationFilter implements Filter {
                        
                         public void init(FilterConfig filterConfig) throws ServletException {}
                         public void destroy() {}
                        
                         public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
                         HttpSession session = ((HttpServletRequest)request).getSession();
                         String servletPath = ((HttpServletRequest) request).getServletPath();
                        
                         if( servletPath.startsWith("/seam/resource") &&
                         ( session.getAttribute( "loged" ) == null || !((String)session.getAttribute( "loged" )).equals("true") ) )
                         {
                         ((HttpServletResponse)response).getWriter().append("<redirectPage to='startpage.jsf'/>");
                         return;
                         }
                        
                         chain.doFilter(request, response);
                         }
                        }
                        

                        Code "session.getAttribute( "loged" )" is my indicator for sassion.

                        2) Register Filter in web.xml:
                        <filter>
                         <filter-name>SeamRemotingSessionValidationFilter</filter-name>
                         <filter-class>
                        com.yc.isystem.presentation.filter.SeamRemotingSessionValidationFilter
                         </filter-class>
                        </filter>
                        <filter-mapping>
                         <filter-name>SeamRemotingSessionValidationFilter</filter-name>
                         <url-pattern>/seam/resource/remoting/*</url-pattern>
                        </filter-mapping>
                        


                        CLIENT SIDE:
                        I decide not to change seam's js libraries so I used Javascript AOP (Aspect Oriented Programing). We already use dojotoolkit in our project so I used dojo's aop functions (there are other libraries which are created just for aop - search google for "js aop"). Next steps are explanation for dojo's aop functionalities.

                        3) Import dojo and set required library:
                        <script src="#{facesContext.externalContext.requestContextPath}/js/dojo/dojo.js" language="javascript"></script>
                        <script>
                         dojo.require("dojo.event");
                        </script>
                        


                        4) Set around advice:
                        dojo.event.connect('around', Seam.Remoting, 'processResponse', 'ajaxResponseInterceptor');
                        

                        I put this in html body (tag) onload='--here--' (attribute) but you can put where you need it.

                        5) Create js function for redirection:
                        function ajaxResponseInterceptor(invocation){
                        
                         if(invocation.args[0].firstChild.tagName == 'redirectPage'){
                         window.location = invocation.args[0].firstChild.attributes['to'].nodeValue;
                         }
                        
                         var result = invocation.proceed();
                         return result;
                        }
                        


                        For some other js aop library steps would be same!

                        If you have problems adding this to you project feel free to ask for help - I'll help if I can.

                        IMPORTANT: This is first version so it's possible that there are some issues. If you seen some please inform me.

                        Thanks,
                        Uros.