フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
Emmanuel Guiton
Getting portlet session from its id
2011/03/24 5:11
答え

Emmanuel Guiton

ランク: Junior Member

投稿: 39

参加年月日: 2010/12/03

最近の投稿

Hello all,

I have developed a portlet which includes GWT code, in particular for RPC calls.
I am trying to get the current user in the GWT servlet and I am stucked. I cannot get it directly, e.g.
1final HttpServletRequest request = this.getThreadLocalRequest();
2final User user = PortalUtil.getUser(request);
returns null;
As far as I understand it, the HttpServletRequest made from the javascript code does not include all the portlet session data that are included in the HttpServletRequest that goes directly through Liferay code.

However, in the GWT servlet, I can get the session id from the HTTP servlet request. This id is also the portlet session id.
Is there any way to get the portlet session from its id ?
I hope to finally get the data I need from the portlet session but I cannot find a mean to get it.

Thanks for any help,
- emmanuel
Murat ÇOLAK
RE: Getting portlet session from its id
2011/03/24 7:19
答え

Murat ÇOLAK

ランク: Junior Member

投稿: 45

参加年月日: 2009/07/27

最近の投稿

I think your code like this

PortletRequest realReq = (PortletRequest) request.getAttribute("javax.portlet.request");
User user = PortalUtil.getUser(realReq);
HttpSession session = PortalUtil.getHttpServletRequest(realReq).getSession();
Emmanuel Guiton
RE: Getting portlet session from its id
2011/03/24 7:59
答え

Emmanuel Guiton

ランク: Junior Member

投稿: 39

参加年月日: 2010/12/03

最近の投稿

Thanks, but it does not work :
1request.getAttribute("javax.portlet.request");
returns null.
David H Nebinger
RE: Getting portlet session from its id
2011/03/24 9:40
答え

David H Nebinger

ランク: Liferay Legend

投稿: 6527

参加年月日: 2006/09/01

最近の投稿

Emmanuel Guiton:
I am trying to get the current user in the GWT servlet and I am stucked. I cannot get it directly, e.g.
1final HttpServletRequest request = this.getThreadLocalRequest();
2final User user = PortalUtil.getUser(request);
returns null;

Lots of folks seem to have issues w/ this, but it is due to not understanding session handling...

When you are in a different servlet than Liferay (your context root is separate), your servlet will have a different session than Liferay's and you will not have access to any session information from Liferay's session.

So the PortalUser.getUser() call will always return null because, at it's core, it is referencing session information that is not there.

I believe that the common answer given to this type of issue is to store the user id as a temporary cookie. You can then access the id across the session boundary.
Emmanuel Guiton
RE: Getting portlet session from its id
2011/03/24 10:15
答え

Emmanuel Guiton

ランク: Junior Member

投稿: 39

参加年月日: 2010/12/03

最近の投稿

Well, I agree that the session content is not the same. And in fact, as I saw on some other post, the underlying object is not the same.

But the point is that the "sessions" are not so different since they share the same id.
So I get the correct id to identify the session I want, but I do not have any mean to fetch it. I feel as if I was looking for a building with a good map, a correct address, but ... no street.

As a workaround so far, I fetch the data I am interested in in the doView() method, set it in a global object, and pull the data from it in my GWT servlet code.
I prefer this solution to storing anything more on the client side, but it still feels somehow horrible ...

Any other suggestion ?
Murat ÇOLAK
RE: Getting portlet session from its id
2011/03/25 1:35
答え

Murat ÇOLAK

ランク: Junior Member

投稿: 45

参加年月日: 2009/07/27

最近の投稿

You can use cookie
Emmanuel Guiton
RE: Getting portlet session from its id
2011/03/25 2:14
答え

Emmanuel Guiton

ランク: Junior Member

投稿: 39

参加年月日: 2010/12/03

最近の投稿

You can use cookie

Isn't cookie a client side method ? emoticon
That is what I wanted to avoid.
David H Nebinger
RE: Getting portlet session from its id
2011/04/04 7:40
答え

David H Nebinger

ランク: Liferay Legend

投稿: 6527

参加年月日: 2006/09/01

最近の投稿

Emmanuel Guiton:
But the point is that the "sessions" are not so different since they share the same id.


The app container is still going to keep the session objects separate. And in general this is a really good thing from a security perspective; if I can somehow deploy my web app to your container I could then access everyone's session information, ...

Your app scope implementation would work. Depending upon how much control you have on the invocation of your servlet, you could also add a param to include in the call...