14 Replies Latest reply on Dec 10, 2012 7:51 AM by jeromej

    Problem accessing HttpSession

    ltaraud

      Hi,

       

      in each client request, I need to acces the HttpSession. I can accees it, but only data in the portlet scope are visible. I should be possible (JSR286)

      any idea ?

       

      I need to share data between JSF portlet and other Servlets (http session scope).

       

       

      I made a class that implements javax.portlet.faces.Bridge acting as a Facade in front of the real bridge. The javax.portlet.faces.GenericFacesPortlet call it and the facade is just calling the real bridge for each method.

      that's ok

       

      But, I need to access to data in the HTTP Session from the facade.

       

       

      Using The PorletRequest, I just see data in the portlet scope.

       

      public void doFacesRequest(ResourceRequest pr, ResourceResponse rep) throws BridgeException {
         

        PortletSession ps = pr.getPortletSession(false);

              if (ps != null) {

                  Object val = ps.getAttribute(DATA_KEY, PortletSession.APPLICATION_SCOPE);  //return null and the data is in the HTTPSession

                  ...

              }

       

            HttpServletRequest httpServletReq = (HttpServletRequest) pr.getAttribute("javax.servlet.request"); //return null

          

              Enumeration e = ps.getAttributeNames(PortletSession.APPLICATION_SCOPE);
              while (e.hasMoreElements()){
                  String val = e.nextElement();
                  System.out.println("session portlet attr : " + val);
              }

       

      }

       

      Console :

      session portlet attr : javax.portlet.p.p_5f888a85-db04-41dd-8189-951404450bfe?beanCmpNav
      session portlet attr : javax.portlet.p.p_5f888a85-db04-41dd-8189-951404450bfe?com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap
      session portlet attr : javax.portlet.p.p_5f888a85-db04-41dd-8189-951404450bfe?beanCmpOngl
      session portlet attr : javax.portlet.p.p_5f888a85-db04-41dd-8189-951404450bfe?javax.portlet.faces.viewIdHistory.edit
      session portlet attr : javax.portlet.p.p_5f888a85-db04-41dd-8189-951404450bfe?actionCmpNav

      ....

      Only javax.portlet.* attributes....

      Thanks.

      Laurent

       

      -- using gtn 3.2.4 (eXo 3.5.3) / Tomcat 6 / PB 3.1Final --

        • 1. Re: Problem accessing HttpSession
          kenfinni

          Laurent,

           

          When you say that the data is in the HTTPSession, how did you verify that?  Was it by debugging the getAttribute call on PortletSession and seeing what was in the Map?

           

          I've used ApplicationScope in PortletSession before and it works fine.

           

          Ken

          • 2. Re: Problem accessing HttpSession
            ltaraud

            thanks Ken,

             

            debugging the getAtrribute call on PortletSession, I have the same problem.

             

            I used a breakpoint in a Tomcat Valve to see the httpSession in the same httpRequest/servletRequest.

             

            When debugging into the Valve, I see data in the session, that are not visible from the portlet.

             

            May I have more than one HttpSession for the same user ?

             

            Laurent

            • 3. Re: Problem accessing HttpSession
              kenfinni

              It may be possible that there are two distinct sessions for the same user if the requests are made from Browsers such that they are using indepenent sessions as opposed to the same.

               

              What kind of information are you wanting to pass between a Servlet and a JSF Portlet? There may be another way to achieve what you need.

               

              Ken

              • 4. Re: Problem accessing HttpSession
                ltaraud

                Ken,

                 

                By investigating a little more :

                - the portal war seems to have his own http Session (containing portal data and all data accessible with Tomcat Valve)

                - each porlet (one war per portlet) seems to have his own http session. And I realy access the http session, but it is not shared wih the others portlets or with the portal.

                 

                I need to share states & data between a lots of porlet. My problem is that the PorletEvents (IPC) are not send to other portlet if they are active but not displayed. These porltet won't be up to date when they will be visible again.

                And I need to keep data into theses portlets for performance reason.

                 

                How can I share data between (JSF) Porlets ?

                A singleton is not realy usefull because data must but isolated for each "session" from a navigator point of view. I need too to be sure that all data will be deleted if the session is cleared (user action or timeout).

                 

                Thanks.

                 

                Laurent

                • 5. Re: Problem accessing HttpSession
                  jeromej

                  Laurent,

                   

                  i've the same problem with eXo, when portlets are in differents WAR we can't use PortletSession.APPLICATION_SCOPE to set attribute.

                  I'm looking for a workaround with gatein/eXo to share parameters bewteen portlet in the same user session.

                   

                  Jérôme

                  • 6. Re: Problem accessing HttpSession
                    kenfinni

                    Laurent,

                     

                    As your portlets are deployed in separate WARs, each will have their own HttpSession instance as they are not shared across servlet containers.

                     

                    One way to resolve the issue is to utilize a cache or persistent store to maintain the information that all portlets need access to.

                     

                    Ken

                    • 7. Re: Problem accessing HttpSession
                      ltaraud

                      Thanks Ken,.

                       

                      using a cache/persistent store will be complicated. It's difficult to be sure that all data associated to closed http Session will be removed.

                      I'll neeed to create a thread to remove obsolete data, in addition to SessionListener.

                      It will be costly in performance for a large website.

                       

                      Is there a way to access to the poral Session (/portal) from all others portlet WARs ?

                       

                       

                      I know that other portals like Liferay are able to share an unique httpSession between all portlets. Do you know if this is planned for gatein ?

                       

                       

                      Laurent

                      • 8. Re: Problem accessing HttpSession
                        kenfinni

                        I don't believe there's a way to access the Session of the main portal site, as that would be the same problem of trying to access the Session of one portlet from another.

                         

                        To my knowledge there is no plan to introduce such support in GateIn.

                         

                        Another option is to add the portlets into the same WAR, so that they can share the same Session.

                         

                        Ken

                        • 9. Re: Problem accessing HttpSession
                          ltaraud

                          Thanks Ken for your quick answer,

                           

                          So, in need to put all the portlet that need to share an httpSession in the same war. If I don't want it, I must find an other way to share data (persistance, cache, ...).

                           

                          Laurent

                          • 10. Re: Problem accessing HttpSession
                            kenfinni

                            That's correct

                            • 11. Re: Problem accessing HttpSession
                              jeromej

                              Many custom portlets and eXo portlets in the same WAR if i want to share informations ... i'm surprised gatein/eXo dont have a system to share parameters between portlets in differents war with APPLICATION_SCOPE (a specific parameter in portlet.xml for example and it would be great lol

                               

                               

                              • 12. Re: Problem accessing HttpSession
                                mposolda

                                Hi,

                                 

                                I think that you can access Http session of whole portal application from your portlet via something like this:

                                 

                                {code}

                                import org.exoplatform.portal.webui.util.Util;

                                 

                                PortalRequestContext prContext = Util.getPortalRequestContext();

                                HttpServletRequest servletRequest = prContext.getRequest();

                                HttpSession portalSession = servletRequest.getSession();

                                {code}

                                 

                                In this session you can then share data between all portlet applications.

                                 

                                The problem is that it's not standardized in JSR286 and it's proprietary not-officialy supported API, which works only in GateIn portal and may not work (or could be changed) in future releases. So it's not officialy recommended to use this (even if it probably works). Also in your portlet, you will need to add compile-dependency on GateIn portal maven artifacts. The Util class is here https://github.com/gatein/gatein-portal/blob/master/webui/portal/src/main/java/org/exoplatform/portal/webui/util/Util.java , so correct maven artifact is this https://github.com/gatein/gatein-portal/blob/master/webui/portal/pom.xml . Maybe you can use reflection if you don't want to add this compile-time dependency...

                                 

                                Marek

                                • 13. Re: Problem accessing HttpSession
                                  mposolda

                                  Hi,

                                   

                                  I think that you can access Http session of whole portal application from your portlet via something like this:

                                   

                                  import org.exoplatform.portal.webui.util.Util;

                                   

                                  PortalRequestContext prContext = Util.getPortalRequestContext();

                                  HttpServletRequest servletRequest = prContext.getRequest();

                                  HttpSession portalSession = servletRequest.getSession();

                                   

                                  In this session you can then share data between all portlet applications.

                                   

                                  The problem is that it's not standardized in JSR286 and it's proprietary not-officialy supported API, which works only in GateIn portal and may not work (or could be changed) in future releases. So it's not officialy recommended to use this (even if it probably works). Also in your portlet, you will need to add compile-dependency on GateIn portal maven artifacts. The Util class is here https://github.com/gatein/gatein-portal/blob/master/webui/portal/src/main/java/org/exoplatform/portal/webui/util/Util.java , so correct maven artifact is this https://github.com/gatein/gatein-portal/blob/master/webui/portal/pom.xml . Maybe you can use reflection if you don't want to add this compile-time dependency...

                                   

                                  Marek

                                  • 14. Re: Problem accessing HttpSession
                                    jeromej

                                    Hi,

                                     

                                    Hey, thanks Marek !

                                    In fact, it seems to be a good solution.

                                    We'll try this.

                                     

                                    Jérôme