1 Reply Latest reply on Jan 8, 2009 5:41 AM by Nick Belaevski

    Session Uniqueness from a4j:push

    Mehmet Salgar Novice

      Hi everybody,

      I have funny question and a problem with a4j:pushBean...

      We have a web application, which runs perfectly in test environment with single web client.

      But if for the same page in the web application another browser client is opened, second browser start receiving the events intended for the first browser...

      So my first impression is that push functionality make no distinction about from which session is called...

      So I surf little bit in the source code and here what I found....

      In org.ajax4jsf.webapp.BaseFilter an instance of PushEventsCounter is obtained with the following call

      PushEventsCounter listener = eventsManager .getListener(ajaxPushHeader);

      which my debuging shows ajaxPushHeader contains no session specific information. At this point I have to say I am using the JBoss Portal and JBoss Portlet Bridge and I made some more debuging and I found this....

      In org.ajax4jsf.component.UIPush in method getListenerId method only HttpSession case taking into count....

      Object session = context.getExternalContext().getSession(false);
      StringBuffer id = new StringBuffer();
      if(null != session && session instanceof HttpSession){
      HttpSession httpSession = (HttpSession) session;
      id.append(httpSession.getId());
      }
      id.append(context.getViewRoot().getViewId());
      id.append(NamingContainer.SEPARATOR_CHAR);
      id.append(getClientId(context));
      return id.toString();

      But portal delivers PortalSession object so the SessionId is not there at that is causing the mentioned problem...

      Now this problem is quite critical for our project and I can actually deliver code solution to be commited jboss source tree also but the question is how to solve this without putting portal dependencies to Richfaces classes...

      Or can we solve this PortletBridge?

        • 1. Re: Session Uniqueness from a4j:push
          Nick Belaevski Master

          Hi,

          You can use this code:

          public String getSessionId(FacesContext context, UIComponent component) {
           String id = null;
           Object session = context.getExternalContext().getSession(false);
           if (session != null) {
           if (session instanceof HttpSession) {
           id = ((HttpSession) session).getId();
           } else {
           Class<? extends Object> sesssionClass = session.getClass();
           try {
           Method getIdMethod = sesssionClass.getMethod("getId");
           id = (String) getIdMethod.invoke(session);
           } catch (SecurityException e) {
           throw new FacesException(e.getMessage(), e);
           } catch (NoSuchMethodException e) {
           throw new FacesException(e.getMessage(), e);
           } catch (IllegalArgumentException e) {
           throw new FacesException(e.getMessage(), e);
           } catch (IllegalAccessException e) {
           throw new FacesException(e.getMessage(), e);
           } catch (InvocationTargetException e) {
           Throwable cause = e.getCause();
           throw new FacesException(cause.getMessage(), cause);
           }
           }
           }
          
           return id;
           }