Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain Liferay session in custom servlet?

I wrote custom servlet in Liferay and want to know which user page calls it and know other parameters like theme. But the request's attributes and session fields are all nulls.

How to make custom servlet to receive request as if portlet does?

Thanks

P.S. I don't want to use this solution https://www.everit.biz/web/guest/blog/-/blogs/getting-current-liferay-user-in-a-standalone-webapp?_33_redirect=/web/guest/blog

which reads cookies manually. I want to do such as Liferay does, i.e. by using it's API. Is it possible?

Update 1.

I have a portlet and a servlet in one WAR. I can know who am I (logged in user) from within portlet JSP like this:

HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();

ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);

themeDisplay.getUser()

Now I want to do the same from a servlet. Is it possible?

I am working in eclips which deploys automatically.

like image 239
Dims Avatar asked Nov 11 '11 14:11

Dims


1 Answers

You either have to mimic what Liferay does in the portlet request handling (not recommended) or, alternatively, put your servlet code into a portlet - this can be the "resource handling" of a portlet - here you get full access to the http request and can do everything yourself with regards to data types transmitted in the stream.

I'd rather recommend this as it will be significantly easier to upgrade. Portlet Resource Handler are very similar to servlets from a logical point of view. There might be other (more advisable) options, but this is what comes to my mind for this type of problem.

like image 134
Olaf Kock Avatar answered Sep 24 '22 08:09

Olaf Kock