use of org.apache.catalina.Session in project tomcat by apache.
the class ApplicationHttpRequest method isRequestedSessionIdValid.
/**
* Returns true if the request specifies a JSESSIONID that is valid within
* the context of this ApplicationHttpRequest, false otherwise.
*
* @return true if the request specifies a JSESSIONID that is valid within
* the context of this ApplicationHttpRequest, false otherwise.
*/
@Override
public boolean isRequestedSessionIdValid() {
if (crossContext) {
String requestedSessionId = getRequestedSessionId();
if (requestedSessionId == null)
return false;
if (context == null)
return false;
Manager manager = context.getManager();
if (manager == null)
return false;
Session session = null;
try {
session = manager.findSession(requestedSessionId);
} catch (IOException e) {
// Ignore
}
if ((session != null) && session.isValid()) {
return true;
} else {
return false;
}
} else {
return super.isRequestedSessionIdValid();
}
}
use of org.apache.catalina.Session in project tomcat by apache.
the class Request method changeSessionId.
/**
* Changes the session ID of the session associated with this request.
*
* @return the old session ID before it was changed
* @see javax.servlet.http.HttpSessionIdListener
* @since Servlet 3.1
*/
@Override
public String changeSessionId() {
Session session = this.getSessionInternal(false);
if (session == null) {
throw new IllegalStateException(sm.getString("coyoteRequest.changeSessionId"));
}
Manager manager = this.getContext().getManager();
manager.changeSessionId(session);
String newSessionId = session.getId();
this.changeSessionId(newSessionId);
return newSessionId;
}
use of org.apache.catalina.Session in project tomcat by apache.
the class ManagerServlet method sessions.
/**
* Session information for the web application at the specified context path.
* Displays a profile of session thisAccessedTime listing number
* of sessions for each 10 minute interval up to 10 hours.
*
* @param writer Writer to render to
* @param cn Name of the application to list session information for
* @param idle Expire all sessions with idle time > idle for this context
* @param smClient i18n support for current client's locale
*/
protected void sessions(PrintWriter writer, ContextName cn, int idle, StringManager smClient) {
if (debug >= 1) {
log("sessions: Session information for web application '" + cn + "'");
if (idle >= 0)
log("sessions: Session expiration for " + idle + " minutes '" + cn + "'");
}
if (!validateContextName(cn, writer, smClient)) {
return;
}
String displayPath = cn.getDisplayName();
try {
Context context = (Context) host.findChild(cn.getName());
if (context == null) {
writer.println(smClient.getString("managerServlet.noContext", RequestUtil.filter(displayPath)));
return;
}
Manager manager = context.getManager();
if (manager == null) {
writer.println(smClient.getString("managerServlet.noManager", RequestUtil.filter(displayPath)));
return;
}
int maxCount = 60;
int histoInterval = 1;
int maxInactiveInterval = context.getSessionTimeout();
if (maxInactiveInterval > 0) {
histoInterval = maxInactiveInterval / maxCount;
if (histoInterval * maxCount < maxInactiveInterval)
histoInterval++;
if (0 == histoInterval)
histoInterval = 1;
maxCount = maxInactiveInterval / histoInterval;
if (histoInterval * maxCount < maxInactiveInterval)
maxCount++;
}
writer.println(smClient.getString("managerServlet.sessions", displayPath));
writer.println(smClient.getString("managerServlet.sessiondefaultmax", "" + maxInactiveInterval));
Session[] sessions = manager.findSessions();
int[] timeout = new int[maxCount + 1];
int notimeout = 0;
int expired = 0;
for (int i = 0; i < sessions.length; i++) {
int time = (int) (sessions[i].getIdleTimeInternal() / 1000L);
if (idle >= 0 && time >= idle * 60) {
sessions[i].expire();
expired++;
}
time = time / 60 / histoInterval;
if (time < 0)
notimeout++;
else if (time >= maxCount)
timeout[maxCount]++;
else
timeout[time]++;
}
if (timeout[0] > 0)
writer.println(smClient.getString("managerServlet.sessiontimeout", "<" + histoInterval, "" + timeout[0]));
for (int i = 1; i < maxCount; i++) {
if (timeout[i] > 0)
writer.println(smClient.getString("managerServlet.sessiontimeout", "" + (i) * histoInterval + " - <" + (i + 1) * histoInterval, "" + timeout[i]));
}
if (timeout[maxCount] > 0) {
writer.println(smClient.getString("managerServlet.sessiontimeout", ">=" + maxCount * histoInterval, "" + timeout[maxCount]));
}
if (notimeout > 0)
writer.println(smClient.getString("managerServlet.sessiontimeout.unlimited", "" + notimeout));
if (idle >= 0)
writer.println(smClient.getString("managerServlet.sessiontimeout.expired", ">" + idle, "" + expired));
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.sessions[" + displayPath + "]", t);
writer.println(smClient.getString("managerServlet.exception", t.toString()));
}
}
use of org.apache.catalina.Session in project tomcat by apache.
the class ReplicationValve method resetReplicationRequest.
/**
* Fix memory leak for long sessions with many changes, when no backup member exists!
* @param request current request after response is generated
* @param isCrossContext check crosscontext threadlocal
*/
protected void resetReplicationRequest(Request request, boolean isCrossContext) {
Session contextSession = request.getSessionInternal(false);
if (contextSession instanceof DeltaSession) {
resetDeltaRequest(contextSession);
((DeltaSession) contextSession).setPrimarySession(true);
}
if (isCrossContext) {
List<DeltaSession> sessions = crossContextSessions.get();
if (sessions != null && sessions.size() > 0) {
Iterator<DeltaSession> iter = sessions.iterator();
for (; iter.hasNext(); ) {
Session session = iter.next();
resetDeltaRequest(session);
if (session instanceof DeltaSession) {
((DeltaSession) contextSession).setPrimarySession(true);
}
}
}
}
}
use of org.apache.catalina.Session in project tomcat by apache.
the class ManagerBase method createSession.
@Override
public Session createSession(String sessionId) {
if ((maxActiveSessions >= 0) && (getActiveSessions() >= maxActiveSessions)) {
rejectedSessions++;
throw new TooManyActiveSessionsException(sm.getString("managerBase.createSession.ise"), maxActiveSessions);
}
// Recycle or create a Session instance
Session session = createEmptySession();
// Initialize the properties of the new session and return it
session.setNew(true);
session.setValid(true);
session.setCreationTime(System.currentTimeMillis());
session.setMaxInactiveInterval(getContext().getSessionTimeout() * 60);
String id = sessionId;
if (id == null) {
id = generateSessionId();
}
session.setId(id);
sessionCounter++;
SessionTiming timing = new SessionTiming(session.getCreationTime(), 0);
synchronized (sessionCreationTiming) {
sessionCreationTiming.add(timing);
sessionCreationTiming.poll();
}
return (session);
}
Aggregations