getSession()源码实例Demo

javax.servlet.http.HttpSessionEvent#getSession()源码实例Demo

下面列出了javax.servlet.http.HttpSessionEvent#getSession() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: quarkus-http   文件: JsrWebSocketFilter.java
@Override
public void sessionDestroyed(HttpSessionEvent se) {
    HttpSessionImpl session = (HttpSessionImpl) se.getSession();
    final Session underlying;
    if (System.getSecurityManager() == null) {
        underlying = session.getSession();
    } else {
        underlying = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(session));
    }
    List<UndertowSession> connections = (List<UndertowSession>) underlying.getAttribute(SESSION_ATTRIBUTE);
    if (connections != null) {
        synchronized (underlying) {
            for (UndertowSession c : connections) {
                try {
                    c.close(new CloseReason(CloseReason.CloseCodes.VIOLATED_POLICY, ""));
                } catch (IOException e) {
                    UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
                }
            }
        }
    }
}
 
源代码2 项目: rebuild   文件: OnlineSessionStore.java
@Override
public void sessionDestroyed(HttpSessionEvent event) {
	if (LOG.isDebugEnabled()) {
		LOG.info("Destroyed session - " + event);
	}
	
	HttpSession s = event.getSession();
	if (ONLINE_SESSIONS.contains(s)) {
		ONLINE_SESSIONS.remove(s);
	} else {
		for (Map.Entry<ID, HttpSession> e : ONLINE_USERS.entrySet()) {
			if (s.equals(e.getValue())) {
				ONLINE_USERS.remove(e.getKey());
				break;
			}
		}
	}
	
	// Logout time
	ID loginId = (ID) s.getAttribute(LoginControll.SK_LOGINID);
	if (loginId != null) {
		Record logout = EntityHelper.forUpdate(loginId, UserService.SYSTEM_USER);
		logout.setDate("logoutTime", CalendarUtils.now());
		Application.getCommonService().update(logout);
	}
}
 
源代码3 项目: boubei-tss   文件: SessionDestroyedListener.java
public void sessionCreated(HttpSessionEvent event) {
    HttpSession session = event.getSession();
    
    // 设置 session 的过期时间
    if(session.isNew()){
        String configValue = ParamConfig.getAttribute(PX.SESSION_CYCLELIFE_CONFIG);
        try {
        	int cycleLife = Integer.parseInt(configValue);
session.setMaxInactiveInterval(cycleLife); // 以秒为单位
        } 
        catch(Exception e) { }
    }
    
    String sessionId = session.getId();
    String appCode = Context.getApplicationContext().getCurrentAppCode();
    log.debug("应用【" + appCode + "】里 sessionId为:" + sessionId
            + " 的session创建完成,有效期为:" + session.getMaxInactiveInterval() + " 秒 ");
    
    Context.sessionMap.put(sessionId, session);
}
 
源代码4 项目: lams   文件: SessionListener.java
/** HttpSessionListener interface */
   @Override
   public void sessionCreated(HttpSessionEvent sessionEvent) {
if (sessionEvent == null) {
    return;
}
HttpSession session = sessionEvent.getSession();
session.setMaxInactiveInterval(Configuration.getAsInt(ConfigurationKeys.INACTIVE_TIME));

//set server default locale for STURTS and JSTL. This value should be overwrite
//LocaleFilter class. But this part code can cope with login.jsp Locale.
if (session != null) {
    String defaults[] = LanguageUtil.getDefaultLangCountry();
    Locale preferredLocale = new Locale(defaults[0] == null ? "" : defaults[0],
	    defaults[1] == null ? "" : defaults[1]);
    session.setAttribute(LocaleFilter.PREFERRED_LOCALE_KEY, preferredLocale);
    Config.set(session, Config.FMT_LOCALE, preferredLocale);
}
   }
 
源代码5 项目: java-tutorial   文件: MyHttpSessionListener.java
@Override
public void sessionCreated(HttpSessionEvent se) {
	HttpSession session = se.getSession();

	// 将 session 放入 map
	ApplicationConstants.SESSION_MAP.put(session.getId(), session);
	// 总访问人数++
	ApplicationConstants.TOTAL_HISTORY_COUNT++;

	// 如果当前在线人数超过历史记录,则更新最大在线人数,并记录时间
	if (ApplicationConstants.SESSION_MAP.size() > ApplicationConstants.MAX_ONLINE_COUNT) {
		ApplicationConstants.MAX_ONLINE_COUNT = ApplicationConstants.SESSION_MAP.size();
		ApplicationConstants.MAX_ONLINE_COUNT_DATE = new Date();
	}

	logger.debug("创建了一个session: {}", session);
}
 
源代码6 项目: openemm   文件: HttpSessionCleanUpListener.java
@Override
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
	HttpSession session = httpSessionEvent.getSession();
	String sessionID = session.getId();
	ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
	
	// Cleanup FutureHolder
	FutureHolderMap futureHolder = (FutureHolderMap) applicationContext.getBean("futureHolder");
	List<String> keysToRemove = new ArrayList<>();
	for (String key : futureHolder.keySet()) {
		if (key.endsWith("@" + sessionID) ) {
			keysToRemove.add(key);
		}
	}
	for (String removeMe : keysToRemove) {
		futureHolder.remove(removeMe);
	}
	
	// Remove all download data and associated files
	DownloadService downloadService = (DownloadService) applicationContext.getBean("DownloadService");
	downloadService.removeAllDownloadData(session);
	
	// Cleanup grid recycle bin
	ComAdmin admin = (ComAdmin) session.getAttribute(AgnUtils.SESSION_CONTEXT_KEYNAME_ADMIN);
       if (admin != null) {
           ComGridTemplateService gridTemplateService = applicationContext.getBean("GridTemplateService", ComGridTemplateService.class);
           gridTemplateService.deleteRecycledChildren(admin.getCompanyID());
       }
       
       // Cleanup waiting interactive imports
       ProfileImportWorker profileImportWorker = (ProfileImportWorker) session.getAttribute(ProfileImportAction.PROFILEIMPORTWORKER_SESSIONKEY);
	if (profileImportWorker != null && profileImportWorker.isWaitingForInteraction()) {
		profileImportWorker.cleanUp();
		session.removeAttribute(ProfileImportAction.PROFILEIMPORTWORKER_SESSIONKEY);
		logger.info("Canceled interactively waiting ProfileImport for session: " + sessionID + " " + (admin != null ? "admin: " + admin.getUsername() : ""));
	}
}
 
源代码7 项目: bidder   文件: CustomListener.java
@Override
public void sessionCreated(HttpSessionEvent ev) {
	HttpSession session = ev.getSession();
	String id = session.getId();

	sessions.add(session);
	//System.out.println("SESSION: " + id + " was created");
	
}
 
源代码8 项目: bidder   文件: CustomListener.java
@Override
public void sessionDestroyed(HttpSessionEvent ev) {
	HttpSession session = ev.getSession();
	String id = session.getId();

	sessions.remove(session);
	//System.out.println("SESSION: " + id + " was destroyed");
	
}
 
源代码9 项目: oslits   文件: SesssionEventListener.java
@SuppressWarnings("unchecked")
public void sessionCreated(HttpSessionEvent se) {
	HttpSession session = se.getSession();
	synchronized(sessionMonitor) {
		sessionMonitor.put(session.getId(), session);
		System.out.println(session.getId() + " : 세션 저장");
	}
}
 
源代码10 项目: oslits   文件: SesssionEventListener.java
public void sessionDestroyed(HttpSessionEvent se) {
	HttpSession session = se.getSession();
	synchronized( sessionMonitor ) {
		sessionMonitor.remove(session.getId());
		System.out.println(session.getId() + " : 세션 제거");
	}
}
 
@Override
public void sessionCreated(HttpSessionEvent se) {
    HttpSession session = se.getSession();
    ServletContext context = session.getServletContext();
    if (context.getAttribute("onlineCount") == null){
        context.setAttribute("onlineCount", 1);
    }else {
        context.setAttribute("onlineCount", (Integer)context.getAttribute("onlineCount") + 1);
    }

}
 
@Override
public void sessionDestroyed(HttpSessionEvent se) {
    HttpSession session = se.getSession();
    ServletContext context = session.getServletContext();
    Integer subFlag = (Integer)session.getAttribute("sub_flag");
    if(subFlag == null){
        context.setAttribute("onlineCount", (Integer)context.getAttribute("onlineCount") - 1);
    }
}
 
源代码13 项目: jivejdon   文件: UserCounterListener.java
public void sessionDestroyed(HttpSessionEvent se) {
	activeSessions--;
	HttpSession session = se.getSession();
	String username = (String) session.getAttribute("online");
	if (username == null) {
		return;
	}
	List userList = (List) servletContext.getAttribute(OnLineUser_KEY);
	userList.remove(username);

}
 
源代码14 项目: piranha   文件: HttpSessionIdListenerTest.java
/**
 * Handle the session id changed event.
 *
 * @param event the event.
 * @param oldSessionId the old session id.
 */
@Override
public void sessionIdChanged(HttpSessionEvent event, String oldSessionId) {
    HttpSession session = event.getSession();
    session.getServletContext().setAttribute("newSessionId", session.getId());
    session.getServletContext().setAttribute("oldSessionId", oldSessionId);
}
 
源代码15 项目: lams   文件: CsrfGuardHttpSessionListener.java
@Override
public void sessionCreated(HttpSessionEvent event) {
    HttpSession session = event.getSession();
    CsrfGuard csrfGuard = CsrfGuard.getInstance();
    csrfGuard.updateToken(session);
    // Check if should generate tokens for protected resources on current session
    if (csrfGuard.isTokenPerPageEnabled() && csrfGuard.isTokenPerPagePrecreate()
            && !SessionUtils.tokensGenerated(session)) {
        csrfGuard.generatePageTokensForSession(session);
    }

}
 
源代码16 项目: lams   文件: SessionListener.java
@SuppressWarnings("unchecked")
   @Override
   public void sessionDestroyed(HttpSessionEvent sessionEvent) {
if (SessionListener.authenticationManager == null) {
    try {
	InitialContext initialContext = new InitialContext();
	SessionListener.authenticationManager = (CacheableManager<?, Principal>) initialContext
		.lookup("java:jboss/jaas/lams/authenticationMgr");
    } catch (NamingException e) {
	SessionListener.log.error("Error while getting authentication manager.", e);
    }
}

// clear the authentication cache when the session is invalidated
HttpSession session = sessionEvent.getSession();
if (session != null) {
    SessionManager.removeSessionByID(session.getId(), false, true);

    UserDTO userDTO = (UserDTO) session.getAttribute(AttributeNames.USER);
    if (userDTO != null) {
	String login = userDTO.getLogin();
	Principal principal = new SimplePrincipal(login);
	SessionListener.authenticationManager.flushCache(principal);

	// remove obsolete mappings to session
	// the session is either already invalidated or will be very soon by another module
	SessionManager.removeSessionByLogin(login, false);
    }
}
   }
 
源代码17 项目: java-tutorial   文件: MyHttpSessionListener.java
@Override
public void sessionDestroyed(HttpSessionEvent se) {
	HttpSession session = se.getSession();
	// 将session从map中移除
	ApplicationConstants.SESSION_MAP.remove(session.getId());

	logger.debug("销毁了一个session: {}", session);
}
 
源代码18 项目: mytwitter   文件: MySessionListener.java
@Override
public void sessionDestroyed(HttpSessionEvent event) {
	HttpSession session = event.getSession();
	Users user = (Users) session.getAttribute("user");
	if (user == null) {
		return;
	}
	ServletContext servletContext = event.getSession().getServletContext();
	servletContext.removeAttribute(((Users) session.getAttribute("user")).getUname());
	Integer onlineNum = (Integer) servletContext.getAttribute("onlineNum");
	if (onlineNum > 0) {
		servletContext.setAttribute("onlineNum", onlineNum - 1);
	}
	Object signinid = session.getAttribute("signinid");

	if (user == null || signinid == null) {
		return;
	}
	int uid = user.getUid();
	Timestamp sdtime = Times.getSystemTime();
	usersDao.updateOnline(0, uid);
	signinDao.updateSignin((Integer) signinid, sdtime);

	Object adid = session.getAttribute("adid");
	Admins admin = (Admins) session.getAttribute("admin");
	if (admin == null || adid == null) {
		return;
	}

	int aid = admin.getAid();
	adminsDao.updateOnline(0, aid);
	adloginDao.updateSignin((Integer) adid, sdtime);
}
 
源代码19 项目: sailfish-core   文件: SessionListener.java
@Override
public void sessionCreated(HttpSessionEvent arg0) {

	HttpSession session =  arg0.getSession();

   	logger.info("Session created {}", session.getId());

   	User user = (User)session.getAttribute(BeanUtil.KEY_USER);

   	if(user != null) {

   		logger.info("Session contains user instance: {}", user);

   	} else {

   		session.setAttribute(BeanUtil.KEY_USER, getDefaultUser());

   	}

}
 
源代码20 项目: sailfish-core   文件: SessionListener.java
@Override
public void sessionDestroyed(HttpSessionEvent arg0) {

	HttpSession session = arg0.getSession();

   	Object user = session.getAttribute(BeanUtil.KEY_USER);

   	logger.info("Session {} of {} destroyed", session.getId(), user);

}
 
源代码评论
动弹
沙发等你来抢
 同类方法