javax.servlet.http.HttpSession.getCreationTime()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中javax.servlet.http.HttpSession.getCreationTime()方法的一些代码示例,展示了HttpSession.getCreationTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpSession.getCreationTime()方法的具体详情如下:
包路径:javax.servlet.http.HttpSession
类名称:HttpSession
方法名:getCreationTime

HttpSession.getCreationTime介绍

[英]Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
[中]返回创建此会话的时间,从1970年1月1日格林威治标准时间午夜起以毫秒为单位。

代码示例

代码示例来源:origin: perwendel/spark

/**
 * @return the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
 */
public long creationTime() {
  return session.getCreationTime();
}

代码示例来源:origin: jfinal/jfinal

public long getCreationTime() {
  return session.getCreationTime();
}

代码示例来源:origin: jfinal/jfinal

public long getCreationTime() {
  return session.getCreationTime();
}

代码示例来源:origin: apache/shiro

public Date getStartTimestamp() {
  return new Date(httpSession.getCreationTime());
}

代码示例来源:origin: javamelody/javamelody

public static long getSessionAgeSum() {
  if (!instanceCreated) {
    return -1;
  }
  final long now = System.currentTimeMillis();
  long result = 0;
  for (final HttpSession session : SESSION_MAP_BY_ID.values()) {
    try {
      result += now - session.getCreationTime();
    } catch (final Exception e) {
      // Tomcat can throw "java.lang.IllegalStateException: getCreationTime: Session already invalidated"
      continue;
    }
  }
  return result;
}

代码示例来源:origin: apache/ignite

/**
 * @param id Session ID.
 * @param ses Session.
 */
WebSession(String id, HttpSession ses) {
  assert id != null;
  assert ses != null;
  this.id = id;
  createTime = ses.getCreationTime();
  accessTime = ses.getLastAccessedTime();
  maxInactiveInterval = ses.getMaxInactiveInterval();
  isNew = ses.isNew();
  attrs = new HashMap<>();
  Enumeration<String> names = ses.getAttributeNames();
  while (names.hasMoreElements()) {
    String name = names.nextElement();
    attrs.put(name, ses.getAttribute(name));
  }
}

代码示例来源:origin: spring-projects/spring-session

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    long creationTime = wrappedRequest.getSession().getCreationTime();
    assertThat(creationTime).isEqualTo(expectedCreationTime);
  }
});

代码示例来源:origin: apache/ignite

entity = new WebSessionEntity(id, ses.getCreationTime(), accessTime,
  ses.getMaxInactiveInterval());

代码示例来源:origin: spring-projects/spring-session

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    HttpSession session = wrappedRequest.getSession();
    session.invalidate();
    try {
      session.getCreationTime();
      fail("Expected Exception");
    }
    catch (IllegalStateException ignored) {
    }
  }
});

代码示例来源:origin: javamelody/javamelody

final long now = System.currentTimeMillis();
lastAccess = new Date(now - session.getLastAccessedTime());
age = new Date(now - session.getCreationTime());
expirationDate = new Date(
    session.getLastAccessedTime() + session.getMaxInactiveInterval() * 1000L);

代码示例来源:origin: javamelody/javamelody

void unregisterSessionIfNeeded(HttpSession session) {
  if (session != null) {
    try {
      session.getCreationTime();
      // https://issues.jenkins-ci.org/browse/JENKINS-20532
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=413019
      session.getLastAccessedTime();
    } catch (final IllegalStateException e) {
      // session.getCreationTime() lance IllegalStateException si la session est invalidée
      synchronized (session) {
        sessionDestroyed(new HttpSessionEvent(session));
      }
    }
  }
}

代码示例来源:origin: spring-projects/spring-session

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    long lastAccessed = wrappedRequest.getSession().getLastAccessedTime();
    assertThat(lastAccessed)
        .isGreaterThan(wrappedRequest.getSession().getCreationTime());
  }
});

代码示例来源:origin: alibaba/druid

public WebSessionStat getSessionStat(HttpServletRequest request) {
  if (!isSessionStatEnable()) {
    return null;
  }
  WebSessionStat sessionStat = null;
  String sessionId = getSessionId(request);
  if (sessionId != null) {
    sessionStat = webAppStat.getSessionStat(sessionId, true);
  }
  if (sessionStat != null) {
    long currentMillis = System.currentTimeMillis();
    String userAgent = request.getHeader("user-agent");
    if (sessionStat.getCreateTimeMillis() == -1L) {
      HttpSession session = request.getSession(false);
      if (session != null) {
        sessionStat.setCreateTimeMillis(session.getCreationTime());
      } else {
        sessionStat.setCreateTimeMillis(currentMillis);
      }
      webAppStat.computeUserAgent(userAgent);
      webAppStat.incrementSessionCount();
    }
    sessionStat.setUserAgent(userAgent);
    String ip = getRemoteAddress(request);
    sessionStat.addRemoteAddress(ip);
  }
  return sessionStat;
}

代码示例来源:origin: spring-projects/spring-session

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    long creationTime = wrappedRequest.getSession().getCreationTime();
    long now = System.currentTimeMillis();
    assertThat(now - creationTime).isGreaterThanOrEqualTo(0).isLessThan(5000);
    SessionRepositoryFilterTests.this.request.setAttribute(CREATE_ATTR,
        creationTime);
  }
});

代码示例来源:origin: spring-projects/spring-session

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    long lastAccessed = wrappedRequest.getSession().getLastAccessedTime();
    assertThat(lastAccessed).isCloseTo(
        wrappedRequest.getSession().getCreationTime(), Offset.offset(5L));
    SessionRepositoryFilterTests.this.request.setAttribute(ACCESS_ATTR,
        lastAccessed);
  }
});

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public long getCreationTime() {
  return session.getCreationTime();
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

@Override
public long getCreationTime() {
  return _session.getCreationTime();
}

代码示例来源:origin: webx/citrus

public String generateLongLiveToken(HttpSession session) {
    String sessionId = assertNotNull(session, "session").getId();
    byte[] digest = DigestUtils.md5(session.getCreationTime() + sessionId);
    return StringUtil.bytesToString(digest);
  }
}

代码示例来源:origin: webx/citrus

public String generateLongLiveToken(HttpSession session) {
    String sessionId = assertNotNull(session, "session").getId();
    byte[] digest = DigestUtils.md5(session.getCreationTime() + sessionId);
    return StringUtil.bytesToString(digest);
  }
}

代码示例来源:origin: com.alibaba/druid

public WebSessionStat getSessionStat(HttpServletRequest request) {
  if (!isSessionStatEnable()) {
    return null;
  }
  WebSessionStat sessionStat = null;
  String sessionId = getSessionId(request);
  if (sessionId != null) {
    sessionStat = webAppStat.getSessionStat(sessionId, true);
  }
  if (sessionStat != null) {
    long currentMillis = System.currentTimeMillis();
    String userAgent = request.getHeader("user-agent");
    if (sessionStat.getCreateTimeMillis() == -1L) {
      HttpSession session = request.getSession(false);
      if (session != null) {
        sessionStat.setCreateTimeMillis(session.getCreationTime());
      } else {
        sessionStat.setCreateTimeMillis(currentMillis);
      }
      webAppStat.computeUserAgent(userAgent);
      webAppStat.incrementSessionCount();
    }
    sessionStat.setUserAgent(userAgent);
    String ip = getRemoteAddress(request);
    sessionStat.addRemoteAddress(ip);
  }
  return sessionStat;
}

相关文章