How to set different session timeout for each application?
As we learnt in our previous article How to set Session timeout in Hybris using below key value pair
- Default.session.timeout=1000
Default.session.timeout=1000
This timeout value is a global timeout value which means its applicable for all the hybris applications like storefront,cockpit,hmc etc.
Sometimes its not required to keep same timeout value for all the applications.
In such case, Hybris provides a way to define application specific timeout
We can achieve this by providing a custom sessionCloseStrategy Spring bean in the web Spring context
This strategy class has to either implement the SessionCloseStrategy interface or can extend the DefaultSessionCloseStrategy class
We can define this strategy in the extension where we need to set different session timeout
Let’s see how we can do it for storefront
Step 1
First create a class which extends DefaultSessionCloseStrategy
- public class StorefrontSessionCloseStrategy extends DefaultSessionCloseStrategy
- {
- @Override
- public void setTimeoutOnHttpSessionCreation(final HttpSession httpSession)
- {
- int timeoutSeconds = 3000; //Load this value from property file
- httpSession.setMaxInactiveInterval(timeoutSeconds);
- }
- }
public class StorefrontSessionCloseStrategy extends DefaultSessionCloseStrategy { @Override public void setTimeoutOnHttpSessionCreation(final HttpSession httpSession) { int timeoutSeconds = 3000; //Load this value from property file httpSession.setMaxInactiveInterval(timeoutSeconds); } }
Step 2
Register the above class as a spring bean in the storefront web application context
- <alias alias="sessionCloseStrategy" name="storefrontSessionCloseStrategy"/>
- <bean id="storefrontSessionCloseStrategy" class=“com.kb.storefront.StorefrontSessionCloseStrategy"/>
<alias alias="sessionCloseStrategy" name="storefrontSessionCloseStrategy"/> <bean id="storefrontSessionCloseStrategy" class=“com.kb.storefront.StorefrontSessionCloseStrategy"/>
Note :
Bean alias must exactly be sessionCloseStrategy in order for the bean to be picked up by hybris
Now default.session.timeout value is not applicable for storefront web application, instead value we set in this strategy will be used.
Great Article.
Thank you KB.
Could you please provide creating custom promotion in 6.x version.
or provide wiki link so that we can refer.
Waiting for your reply.