4 Replies Latest reply on Mar 19, 2007 6:20 PM by antoine_h

    access to outer request/session from within portlet

    radzish

      Hi All!

      Are there any utility API to access outer request and/or outer session from within portlet ?
      thanks in advance.

        • 1. Re: access to outer request/session from within portlet
          radzish

          I still do not know whether there are any API to get outer request, but I have found the way how to do that. Here it is:

          public static final HttpServletRequest getOuterRequest(JBossRenderRequest request) {
           PortletInvocation portletInvocation = (PortletInvocation) request
           .getAttribute(ContextDispatcherInterceptor.REQ_ATT_COMPONENT_INVOCATION);
           return portletInvocation.getDispatchedRequest();
          }
          



          • 2. Re: access to outer request/session from within portlet
            antoine_h

            hello,

            this get the dispatched request, which seem not be usefull in my case (retrieve the session for setting a whole portal session parameter, that is the locale for all the portlet).

            I did this, through the PortletRequest, PortletInvocation and AbstractInvocationContext class.

            Not sure it is full correct, but it works. If someone has an comment on this ?
            may be another way to get the http session ?

            private static final Logger log = Logger
             .getLogger(MyClass.class);
            
             public static final HttpServletRequest getOuterRequest(
             PortletRequest request) {
             PortletInvocation portletInvocation = (PortletInvocation) request
             .getAttribute(ContextDispatcherInterceptor.REQ_ATT_COMPONENT_INVOCATION);
             // return portletInvocation.getDispatchedRequest();
            
             // Get the context of the invocation
             InvocationContext invocationContext = portletInvocation.getContext();
            
             // Try to cast the context of invocation to an AbstractInvocationContext
             AbstractInvocationContext abstractInvCtxt = null;
             if (invocationContext != null) {
             if (invocationContext instanceof AbstractInvocationContext) {
             abstractInvCtxt = (AbstractInvocationContext) invocationContext;
             } else {
             log
             .warn("The InvocationContext is not of instance of AbstractInvocationContext !");
             log.warn("The InvocationContext is : " + invocationContext
             + " // " + invocationContext.getClass().getName()
             + " // " + invocationContext.toString());
             }
            
             } else {
             log.warn("The invocationContext is null !");
             }
             HttpServletRequest httpServletRequest = null;
             if (abstractInvCtxt != null) {
             // The AbstractInvocationContext exists : try to retrieve the client
             // httpServletRequest.
             httpServletRequest = abstractInvCtxt.getClientRequest();
             if (httpServletRequest == null) {
             log.warn("The HttpServletRequest is null !");
             }
             } else {
             log.warn("The AbstractInvocationContext is null !");
             }
             return httpServletRequest;
             }
            





            • 3. Re: access to outer request/session from within portlet
              theute

              If you are just trying to access the HTTP Session of the Web archive containing your portlet you can use the APPLICATION_SCOPE when you set and get an attribute.

              What are you trying to achieve exactly ?

              • 4. Re: access to outer request/session from within portlet
                antoine_h

                About the session : store the locale in the session, for easy access in other places than the portlet.
                - from the login.jsp, to have a i18n login page
                - in other jsp or jsf pages

                or to have the current choosen localed store somewhere global, if the user does not allow the cookie.

                I have not used it really yet, but when storing the locale in a cookie, i anticipated this and store it also in the session.
                for the login.jsp, I will soon...

                About the HttpServletRequest and Response :
                - for the session
                - for setting and retrieving a cookie.

                cookie to store the locale, from one visit to another.

                I am not keen on using this, as it is not JSR-168 compliant, but... is there a compliant way ?
                (working on two portal projects, different companies, both need i18n... and locale stored between two visits).

                may be with a servlet wrapper and playing with a parameter to trigger the work ?
                or with an interceptor on the portlets or the portal container ?