0 Replies Latest reply on May 6, 2015 3:48 AM by Martin Fluch

    Problems redirecting Ajax requests

    Martin Fluch Newbie

      I'm trying to implement with Wildfly 8.1 the redirect solition as it has been posted here:


      How to redirect ajax request when session times out and form authentication is configured


      Basically everything works fine, the phase listener gets called as it is described, but I have the following problem:


      When the session has timed out and I click in the browser on an UI element which issues a partial Ajax request, then Firebug shows me, that exactly one Ajax request is send (as it should be). This Ajax request contains as expected the old session ID (for example 6fljvP0qGFVvfU4hAEobD6vw) . However, Wildfly does not answer with a redirect, but with a nearly empty reply, which contains a new session ID (for example 9Z5-AiDu3LBK25J5K-0Xktx_).


      Serverside I observe in the phaselistener, that getRequestedSessionId() of the HttpServletRequest is already "9Z5-AiDu3LBK25J5K-0Xktx_" instead of the expexted "6fljvP0qGFVvfU4hAEobD6vw". Hence isRequestedSessionIdValid() returns of course "true" instead of the expected "false", and therefor the afterPhase() method does not fire the redirect.


      Now my question is: why does the getRequestedSessionId() method of the HttpServletRequest object return already the new session ID and not the expired requested ID as it should? What am I missing?


      Below is the relevant code:


      public void afterPhase(PhaseEvent event) {
           FacesContext context = FacesContext.getCurrentInstance();
           HttpServletRequest httpRequest = (HttpServletRequest) context.getExternalContext().getRequest();
           HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
           LOG.info("~~~~ getRequestedSessionId: " + httpRequest.getRequestedSessionId());            // 9Z5-AiDu3LBK25J5K-0Xktx_
           LOG.info("~~~~ isRequestedSessionIdValid: " + httpRequest.isRequestedSessionIdValid());    // true
           LOG.info("~~~~ currentSession: " + ((session != null) ? session.getId() : "---"));         // 9Z5-AiDu3LBK25J5K-0Xktx_
           if (httpRequest.getRequestedSessionId() != null && !httpRequest.isRequestedSessionIdValid()) {
               String facesRequestHeader = httpRequest.getHeader("Faces-Request");
               boolean isAjaxRequest = facesRequestHeader != null && facesRequestHeader.equals("partial/ajax");
               LOG.info("~~~~ facesRequestHeader: " + facesRequestHeader);
               LOG.info("~~~~ isAjaxRequest: " + isAjaxRequest);
               if (isAjaxRequest) {
                   ConfigurableNavigationHandler handler = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler();