Update question description to be more specified and detailed.
I have a weblogic 12c, configured with one cluster, 4 node instances in the cluster, Default Load Algorithm is Round Robin, Replication Type is MAN. I deploy one web application on all 4 nodes.
What I design at first time is:
Execute logout related business logic once user session got invalidated. Put logic code inside "sessionDestroyed" method of SessionListener.java which implements HttpSession Interface. As you know, session got invalidated could be caused by 2 case, one is manually logout, another is J2ee container trigger the time out. My issue is occurred because of the 2nd case.
Issue:
The business logic code inside "SessionDestroyed" event is executed twice for one user time out, which is not expected and result in business error. What I found is Primary Http Session on the node A and Backup Session on the node B both trigger the weblogic "SessionDestroyed" event.
Question:
- Why Backup Session on the node B trigger session timeout event although Primary Session on the node A has already been time out ?
- How to let Backup Session know that Primary Session has already been invalidated?
Attach the Log, you can see the first and second line is primary session, the third line is backup session, which can be proved by the session id in the line tail.
DEBUG Oct-20-17 01:53:40 [[ACTIVE] ExecuteThread: '9' for queue: 'weblogic.kernel.Default (self-tuning)'] (AMCSessionListener-27 ) - Session: wIc4WB62vlaYR_tMRMIc0WpBHchh5fbwpinxgaig4mJRJFhlPUcj!-1795465203!1400921280!1508478820022 Created at Fri Oct 20 01:53:40 EDT 2017
DEBUG Oct-20-17 02:54:05 [[ACTIVE] ExecuteThread: '9' for queue: 'weblogic.kernel.Default (self-tuning)'] (AMCSessionListener-46 ) - Session: wIc4WB62vlaYR_tMRMIc0WpBHchh5fbwpinxgaig4mJRJFhlPUcj!-1795465203!1400921280!1508478820022 Destroyed at Fri Oct 20 02:54:05 EDT 2017
DEBUG Oct-20-17 02:55:12 [[ACTIVE] ExecuteThread: '17' for queue: 'weblogic.kernel.Default (self-tuning)'] (AMCSessionListener-46 ) - Session: wIc4WB62vlaYR_tMRMIc0WpBHchh5fbwpinxgaig4mJRJFhlPUcj!173379423!1400921280!1508478820022 Destroyed at Fri Oct 20 02:55:12 EDT 2017
Below is my weblogic configuration:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<session-descriptor>
<cookie-path>/AppName</cookie-path>
<persistent-store-type>replicated</persistent-store-type>
<http-proxy-caching-of-cookies>true</http-proxy-caching-of-cookies>
<cookie-secure>true</cookie-secure>
</session-descriptor>
</weblogic-web-app>
This is my session configure in the web.xml inside web application:
<session-config>
<session-timeout>60</session-timeout>
</session-config>
This is my SessionListener.java:
public class SessionListener implements HttpSessionListener {
private static Logger logger = Logger.getLogger(SessionListener.class);
@Override
public void sessionCreated(HttpSessionEvent se) {
if (logger.isDebugEnabled()) {
logger.debug("Session: " + se.getSession().getId() + " Created at " + (new java.util.Date()));
}
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
/**
* The business logic code related to logout action
* would be executed twice here, this is not what I want.
**/
if (logger.isDebugEnabled()) {
logger.debug("Session: " + se.getSession().getId() + " Destroyed at " + (new java.util.Date()));
}
}
}
This code for manually logout:
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public ModelAndView logout(HttpServletRequest request,
HttpServletResponse response) throws Exception {
...
// Business Logic for Logout
...
request.getSession().invalidate();
CommonViewObject vo = new CommonViewObject();
return renderReponse(request, response, vo, "Login");
}
Any suggestion would be appreciated. I need address the issue, thank you!