简体   繁体   中英

Liferay Session mod_jk issue

The session is not working with mod_jk load balancer (from httpd web server). However, the same code is working fine in the application server.

Following is worker.properties:

worker.list=loadbalancer,status,web

worker.node0.port=8009
worker.node0.host=10.50.26.19
worker.node0.type=ajp13
worker.node0.lbfactor=1
worker.node0.socket_keepalive=false

worker.node0.connect_timeout=10000
worker.node0.prepost_timeout=10000
worker.node0.socket_timeout=60

worker.node0.connection_pool_timeout=600

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node0
worker.loadbalancer.sticky_session=1

Java Code in Portlet 1:

PortletSession portletSession = actionRequest.getPortletSession();
portletSession.setAttribute("username",reg.getFname(), PortletSession.APPLICATION_SCOPE);

JSP Code in Portlet 2:

PortletSession portletSessionobject = renderRequest.getPortletSession();
userName=(String)portletSessionobject.getAttribute("username",PortletSession.APPLICATION_SCOPE);

In both the portlet the following property have been applied in the liferay-portlet.xml

<private-session-attributes>false</private-session-attributes>

But unable to get username in the Portlet 2 JSP page in web server it is returning null. But in the application server the value is coming as expected. Please suggest.

After doing much research found the solution. Hence posting it to help others. There are two things that cause the issue.

i) The sessions were overwritten by the httpd server. Following header tag was added in the httpd.conf which actually caused the issue. Removed it and JSESSION started to appear.

Header set Set-Cookie HttpOnly;Secure

ii) Session Affinity was not working properly due to jvmRoute was not defined. As a result, the session gets terminated intermittently. So added the instance-id for subsystem web in the standalone.xml of each instance,

For node0,

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" instance-id="node0" native="false">

For node1,

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" instance-id="node1" native="false">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM