-
1. Re: access to outer request/session from within portlet
radzish Jan 13, 2007 12:28 PM (in response to 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 Mar 6, 2007 5:57 PM (in response to radzish)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 Mar 7, 2007 2:49 AM (in response to radzish)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 Mar 19, 2007 6:20 PM (in response to radzish)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 ?