Foren

Portlet Servlet Communication

N. H., geändert vor 6 Jahren.

Portlet Servlet Communication

Junior Member Beiträge: 71 Beitrittsdatum: 14.11.13 Neueste Beiträge
Hello Together,
following problem I have. I want to migrate my portlets from a websphere application server to a tomcat.
In my portlet I have the following code snippet


PortletRequest request = (PortletRequest)getFacesContext().getExternalContext().getRequest();
PortletSession portletSession = request.getPortletSession();
HttpServletRequest httpRequest =  PortalUtil.getHttpServletRequest(request); 
HttpSession  session = httpRequest.getSession(true); 
session .setAttribute("test",anyObject);


Although I have a servlet where I tried to get this attribute from the session

public void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse)
	    throws ServletException, IOException {

		Object lObject = (Object ) pRequest.getSession().getAttribute("test");


In the websphere Server this code works fine but not in tomcat. In tomcat the lObject is null
Whats wrong who can help me

Kind regards
N.H
thumbnail
David H Nebinger, geändert vor 6 Jahren.

RE: Portlet Servlet Communication

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
N. H.:
In the websphere Server this code works fine but not in tomcat. In tomcat the lObject is null. Whats wrong who can help me


No one can help you because they are two different sessions.

Under Liferay, the portal (and all portlets) are actually running under the Liferay ROOT web application. Because of that, all HTTP requests are being handled by the ROOT web app and therefore when you get the HTTP session, it is a session tied to the ROOT web app.

Additional servlets that you might deploy outside of Liferay, well they are their own web application and therefore when you get the session you are getting the session tied to that web application, not Liferay's ROOT web application.

Two different sessions, two different variables, two different values, plus from an application server perspective there's also a really big wall between the web apps so the sessions cannot be reached by other web apps.








Come meet me at the 2017 LSNA!
N. H., geändert vor 6 Jahren.

RE: Portlet Servlet Communication

Junior Member Beiträge: 71 Beitrittsdatum: 14.11.13 Neueste Beiträge
Thank you for the answer emoticon.
But why it works in a websphere ?
thumbnail
David H Nebinger, geändert vor 6 Jahren.

RE: Portlet Servlet Communication

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
Websphere allows you to configure all kinds of things. Could be it was configured to share the session, could be it was deployed as part of an ear (I believe those can share session across the app IIRC), ...

We certainly can't tell you how your environment is configured...







Come meet me at the 2017 LSNA!
N. H., geändert vor 6 Jahren.

RE: Portlet Servlet Communication

Junior Member Beiträge: 71 Beitrittsdatum: 14.11.13 Neueste Beiträge
Hello David,
correct we deployed the servlet as part of an ear File. In tomcat I tried to deploy the servlet as part of the war.

I have a portlet export as a war file in the lib Folder of the war their is a jar file. In this jar file the servlet is placed.

Is there any possibility to transfer the object into the servlet ?
thumbnail
David H Nebinger, geändert vor 6 Jahren.

RE: Portlet Servlet Communication

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
No, the boundary between the web applications is there for a reason.

The only options are to move the servlet to the ROOT war using an EXT plugin or using a real persistence option (since session storage is a hack).









Come meet me at the 2017 LSNA!