当前位置: 首页>>代码示例>>Java>>正文


Java HttpSession.setMaxInactiveInterval方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpSession.setMaxInactiveInterval方法的典型用法代码示例。如果您正苦于以下问题:Java HttpSession.setMaxInactiveInterval方法的具体用法?Java HttpSession.setMaxInactiveInterval怎么用?Java HttpSession.setMaxInactiveInterval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpSession的用法示例。


在下文中一共展示了HttpSession.setMaxInactiveInterval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sessionEnded

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void sessionEnded(final RequestContext context, final FlowSession session, final String outcome,
                         final AttributeMap output) {

    if ( session.isRoot() ) {
        final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
        // get session but don't create it if it doesn't already exist
        final HttpSession webSession = request.getSession(false);

        if (webSession != null) {
            LOGGER.debug("Terminate web session {} in {} seconds", webSession.getId(), this.timeToDieInSeconds);
            // set the web session to die in timeToDieInSeconds
            webSession.setMaxInactiveInterval(this.timeToDieInSeconds);
        }
    }
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:17,代码来源:TerminateWebSessionListener.java

示例2: removeSession

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
protected void removeSession(HttpServletRequest request, int interval) {
	if (Engine.isEngineMode()) {
		Engine.logContext.debug("[GenericServlet] End of session required => try to invalidate session");
		try {
			HttpSession httpSession = request.getSession();
			boolean isAdminSession = Engine.authenticatedSessionManager.isAuthenticated(httpSession);
			if (!isAdminSession && Engine.theApp.contextManager.isSessionEmtpy(httpSession.getId())) {
				Engine.logContext
						.debug("[GenericServlet] The owner HTTP session is empty => invalidating HTTP session in "
								+ interval + "s.");
				httpSession.setMaxInactiveInterval(interval);
			}
		} catch (Exception e) {
			Engine.logContext.debug("[GenericServlet] End of session required => failed to get the session: " + e);
		}
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:18,代码来源:GenericServlet.java

示例3: setSessionMaxInactiveInterval

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
   * Sets the maximum inactive interval (session timeout) an HttpSession
   * @param sessionId
   * @param maxInactiveInterval in seconds
   * @return old value for maxInactiveInterval
   * @throws IOException 
   */
  public int setSessionMaxInactiveInterval(String path, String sessionId, int maxInactiveInterval) throws IOException {
      HttpSession session = getSessionForPathAndId(path, sessionId).getSession();
      if (null == session) {
          // Shouldn't happen, but let's play nice...
      	if (debug >= 1) {
      		log("WARNING: can't set timout for null session " + sessionId);
      	}
          return 0;
      }
      try {
	int oldMaxInactiveInterval = session.getMaxInactiveInterval();
	session.setMaxInactiveInterval(maxInactiveInterval);
	return oldMaxInactiveInterval;
      } catch (IllegalStateException ise) {
      	if (debug >= 1) {
      		log("Can't set MaxInactiveInterval '" + maxInactiveInterval + "' for invalidated session id " + sessionId);
      	}
      	return 0;
}
  }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:HTMLManagerServlet.java

示例4: sessionCreated

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/** HttpSessionListener interface */
   @Override
   public void sessionCreated(HttpSessionEvent sessionEvent) {
if (sessionEvent == null) {
    return;
}
HttpSession session = sessionEvent.getSession();
session.setMaxInactiveInterval(SessionListener.timeout);

//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);
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:SessionListener.java

示例5: init

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
/**
 * Method for stream initialization
 * @param clientUri - Client Uri
 * @param request - The servlet request object
 * @param response - The servlet Response Object
 */
private void init(String clientUri,HttpServletRequest request, HttpServletResponse response){
	LOG.info("Response Stream Inititated");
	try{
		HttpSession session = request.getSession();
		session.setMaxInactiveInterval(72*60*60);
		EventClient client = new EventClient();
		client.connectToClient(clientUri);
		response.setHeader("Content-Type", "text/event-stream");
		response.setHeader("Cache-Control", "no-cache, no-store");
		response.setHeader("Connection", "keep-alive");
		AsyncContext asyncContext = request.startAsync(request,response);
		asyncContext.setTimeout(72*60*60*1000);
		asyncContext.getResponse().setBufferSize(1200);
		try {
			asyncContext.getResponse().flushBuffer();
		} catch (IOException e1) {
			ErrorLog.logError(e1.getMessage(),e1.getStackTrace());
		}
		ServletContext servletContext = request.getServletContext();
		Map<String,AsyncContext> responseStreams = (ConcurrentHashMap<String,AsyncContext>) servletContext.getAttribute("responseStreams");
		responseStreams.put(clientUri,asyncContext);
	} catch (Exception e){
		ErrorLog.logError(e.getMessage(),e.getStackTrace());
	}
}
 
开发者ID:opendaylight,项目名称:fpc,代码行数:32,代码来源:EventServer.java

示例6: invoke

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void invoke(Request request, Response response) throws IOException,
        ServletException {

    boolean isBot = false;
    String sessionId = null;
    String clientIp = null;

    if (log.isDebugEnabled()) {
        log.debug(request.hashCode() + ": ClientIp=" +
                request.getRemoteAddr() + ", RequestedSessionId=" +
                request.getRequestedSessionId());
    }

    // If the incoming request has a valid session ID, no action is required
    if (request.getSession(false) == null) {

        // Is this a crawler - check the UA headers
        Enumeration<String> uaHeaders = request.getHeaders("user-agent");
        String uaHeader = null;
        if (uaHeaders.hasMoreElements()) {
            uaHeader = uaHeaders.nextElement();
        }

        // If more than one UA header - assume not a bot
        if (uaHeader != null && !uaHeaders.hasMoreElements()) {

            if (log.isDebugEnabled()) {
                log.debug(request.hashCode() + ": UserAgent=" + uaHeader);
            }

            if (uaPattern.matcher(uaHeader).matches()) {
                isBot = true;

                if (log.isDebugEnabled()) {
                    log.debug(request.hashCode() +
                            ": Bot found. UserAgent=" + uaHeader);
                }
            }
        }

        // If this is a bot, is the session ID known?
        if (isBot) {
            clientIp = request.getRemoteAddr();
            sessionId = clientIpSessionId.get(clientIp);
            if (sessionId != null) {
                request.setRequestedSessionId(sessionId);
                if (log.isDebugEnabled()) {
                    log.debug(request.hashCode() + ": SessionID=" +
                            sessionId);
                }
            }
        }
    }

    getNext().invoke(request, response);

    if (isBot) {
        if (sessionId == null) {
            // Has bot just created a session, if so make a note of it
            HttpSession s = request.getSession(false);
            if (s != null) {
                clientIpSessionId.put(clientIp, s.getId());
                sessionIdClientIp.put(s.getId(), clientIp);
                // #valueUnbound() will be called on session expiration
                s.setAttribute(this.getClass().getName(), this);
                s.setMaxInactiveInterval(sessionInactiveInterval);

                if (log.isDebugEnabled()) {
                    log.debug(request.hashCode() +
                            ": New bot session. SessionID=" + s.getId());
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug(request.hashCode() +
                        ": Bot session accessed. SessionID=" + sessionId);
            }
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:82,代码来源:CrawlerSessionManagerValve.java

示例7: getOrCreate

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public static HttpSessionImpl getOrCreate() {
    if (HttpSessionThreadLocal.get() == null) {
        if (sessionStore == null) {
            sessionStore = new DefaultHttpSessionStore();
        }

        HttpSession newSession = sessionStore.createSession();
        newSession.setMaxInactiveInterval(ServletWebApp.get().getWebappConfig().getSessionTimeout());
        sessionThreadLocal.set(newSession);
    }

    return get();
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:14,代码来源:HttpSessionThreadLocal.java

示例8: handleAuthentication

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public String handleAuthentication(boolean isFromBean, HttpSession httpSession)
        throws SAML2AuthnRequestException {
    httpSession.setAttribute(Constants.SESS_ATTR_DEFAULT_TIMEOUT,
            httpSession.getMaxInactiveInterval());
    // set session timeout temporally to 30 minutes for saml
    httpSession.setMaxInactiveInterval(30 * 60);
    return handleAuthentication(isFromBean);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:9,代码来源:AuthenticationHandler.java

示例9: rollbackDefaultTimeout

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
private void rollbackDefaultTimeout(HttpServletRequest httpRequest) {
    HttpSession session = httpRequest.getSession();
    Integer attributeInt = (Integer) session
            .getAttribute(Constants.SESS_ATTR_DEFAULT_TIMEOUT);
    if (attributeInt != null) {
        session.setMaxInactiveInterval(attributeInt.intValue());
        session.removeAttribute(Constants.SESS_ATTR_DEFAULT_TIMEOUT);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:10,代码来源:AuthorizationFilter.java

示例10: doGet

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		HttpSession session = request.getSession();
		session.setMaxInactiveInterval(5*60*60);

		EntityManager em = EMFUtil.getEMFactory().createEntityManager();

		String certificationQuery = "select certs from Certifications certs ORDER BY certs.certification ASC";
		String stateQuery = "select state from States state ORDER BY state.name ASC";
		String fieldQuery = "select f from Fields f ORDER BY f.name ASC";

		TypedQuery<Fields> qField = em.createQuery(fieldQuery, Fields.class);
		TypedQuery<States> qState = em.createQuery(stateQuery, States.class);
		TypedQuery<Certifications> qCertification = em.createQuery(certificationQuery, Certifications.class);

		try {

			List<States> stateList = qState.getResultList();
			List<Fields> fieldList = qField.getResultList();
			List<Certifications> certificationList = qCertification.getResultList();

			session.setAttribute("fieldList", fieldList);
			session.setAttribute("stateList", stateList);
			session.setAttribute("certificationList", certificationList);

			response.sendRedirect("job-search.jsp");
		} catch (Exception e) {
			logger.error("Exception at JobCriteriaServlet!", e);
			e.printStackTrace();
		} finally {
			em.close();
		}
	}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:34,代码来源:JobCriteriaServlet.java

示例11: terminateSession

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public static void terminateSession(HttpSession httpSession, boolean force) {
	if (httpSession != null) {
		if (force || Engine.authenticatedSessionManager.isAnonymous(httpSession)) {
			httpSession.setMaxInactiveInterval(1);
			if (Engine.theApp != null && Engine.theApp.contextManager != null) {
				Engine.theApp.contextManager.removeAll(httpSession.getId());
			}
		}
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:11,代码来源:HttpUtils.java

示例12: invoke

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {

	boolean isBot = false;
	String sessionId = null;
	String clientIp = null;

	if (log.isDebugEnabled()) {
		log.debug(request.hashCode() + ": ClientIp=" + request.getRemoteAddr() + ", RequestedSessionId="
				+ request.getRequestedSessionId());
	}

	// If the incoming request has a valid session ID, no action is required
	if (request.getSession(false) == null) {

		// Is this a crawler - check the UA headers
		Enumeration<String> uaHeaders = request.getHeaders("user-agent");
		String uaHeader = null;
		if (uaHeaders.hasMoreElements()) {
			uaHeader = uaHeaders.nextElement();
		}

		// If more than one UA header - assume not a bot
		if (uaHeader != null && !uaHeaders.hasMoreElements()) {

			if (log.isDebugEnabled()) {
				log.debug(request.hashCode() + ": UserAgent=" + uaHeader);
			}

			if (uaPattern.matcher(uaHeader).matches()) {
				isBot = true;

				if (log.isDebugEnabled()) {
					log.debug(request.hashCode() + ": Bot found. UserAgent=" + uaHeader);
				}
			}
		}

		// If this is a bot, is the session ID known?
		if (isBot) {
			clientIp = request.getRemoteAddr();
			sessionId = clientIpSessionId.get(clientIp);
			if (sessionId != null) {
				request.setRequestedSessionId(sessionId);
				if (log.isDebugEnabled()) {
					log.debug(request.hashCode() + ": SessionID=" + sessionId);
				}
			}
		}
	}

	getNext().invoke(request, response);

	if (isBot) {
		if (sessionId == null) {
			// Has bot just created a session, if so make a note of it
			HttpSession s = request.getSession(false);
			if (s != null) {
				clientIpSessionId.put(clientIp, s.getId());
				sessionIdClientIp.put(s.getId(), clientIp);
				// #valueUnbound() will be called on session expiration
				s.setAttribute(this.getClass().getName(), this);
				s.setMaxInactiveInterval(sessionInactiveInterval);

				if (log.isDebugEnabled()) {
					log.debug(request.hashCode() + ": New bot session. SessionID=" + s.getId());
				}
			}
		} else {
			if (log.isDebugEnabled()) {
				log.debug(request.hashCode() + ": Bot session accessed. SessionID=" + sessionId);
			}
		}
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:76,代码来源:CrawlerSessionManagerValve.java

示例13: setSessionTimeout

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public static void setSessionTimeout(HttpSession session) {
	int maxInactiveInterval;
	if (isTrustedHost()) {
		maxInactiveInterval = Settings.getInt(SettingCodes.SESSION_TIMEOUT_TRUSTED, Bundle.SETTINGS, DefaultSettings.SESSION_TIMEOUT_TRUSTED);
	} else {
		maxInactiveInterval = Settings.getInt(SettingCodes.SESSION_TIMEOUT, Bundle.SETTINGS, DefaultSettings.SESSION_TIMEOUT);
	}
	maxInactiveInterval *= 60;
	if (session != null) {
		session.setMaxInactiveInterval(maxInactiveInterval);
	} else {
		FacesContext context = FacesContext.getCurrentInstance();
		context.getExternalContext().setSessionMaxInactiveInterval(maxInactiveInterval);
	}
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:16,代码来源:WebUtil.java

示例14: sessionCreated

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
@Override
public void sessionCreated(HttpSessionEvent event) {

    HttpSession session = event.getSession();
    if (log.isDebugEnabled()) {
        log.debug(getTime() + " (session) Created: Session ID=" + session.getId() + "Default MaxInactiveInterval=" + session.getMaxInactiveInterval());
    }
    // Setting MaxInactiveInterval to 1 sec to make sure the ideal sessions will get invalidated in 1 sec.
    session.setMaxInactiveInterval(1);

    if (log.isDebugEnabled()) {
        log.debug("Session ID=" + session.getId() + "Modified MaxInactiveInterval=" + session.getMaxInactiveInterval());
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:15,代码来源:WebServiceSessionListener.java

示例15: getSession

import javax.servlet.http.HttpSession; //导入方法依赖的package包/类
public static HttpSession getSession() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext != null) {
        HttpSession hs = (HttpSession) facesContext.getExternalContext().getSession(true);
        hs.setMaxInactiveInterval(-1);
        return hs;
    }
    return null;
}
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:10,代码来源:SessionUtil.java


注:本文中的javax.servlet.http.HttpSession.setMaxInactiveInterval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。