use of org.apache.catalina.Session in project tomcat70 by apache.
the class HTMLManagerServlet method getSessionsForName.
protected List<Session> getSessionsForName(ContextName cn, StringManager smClient) {
if ((cn == null) || !(cn.getPath().startsWith("/") || cn.getPath().equals(""))) {
String path = null;
if (cn != null) {
path = cn.getPath();
}
throw new IllegalArgumentException(smClient.getString("managerServlet.invalidPath", RequestUtil.filter(path)));
}
Context ctxt = (Context) host.findChild(cn.getName());
if (null == ctxt) {
throw new IllegalArgumentException(smClient.getString("managerServlet.noContext", RequestUtil.filter(cn.getDisplayName())));
}
Manager manager = ctxt.getManager();
List<Session> sessions = new ArrayList<Session>();
sessions.addAll(Arrays.asList(manager.findSessions()));
if (manager instanceof DistributedManager && showProxySessions) {
// Add dummy proxy sessions
Set<String> sessionIds = ((DistributedManager) manager).getSessionIdsFull();
// Remove active (primary and backup) session IDs from full list
for (Session session : sessions) {
sessionIds.remove(session.getId());
}
// Left with just proxy sessions - add them
for (String sessionId : sessionIds) {
sessions.add(new DummyProxySession(sessionId));
}
}
return sessions;
}
use of org.apache.catalina.Session in project tomcat70 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
*/
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;
long now = System.currentTimeMillis();
for (int i = 0; i < sessions.length; i++) {
int time;
if (LAST_ACCESS_AT_START) {
time = (int) ((now - sessions[i].getLastAccessedTimeInternal()) / 1000L);
} else {
time = (int) ((now - sessions[i].getThisAccessedTimeInternal()) / 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 tomcat70 by apache.
the class ManagerBase method getSession.
/**
* Returns information about the session with the given session id.
*
* <p>The session information is organized as a HashMap, mapping
* session attribute names to the String representation of their values.
*
* @param sessionId Session id
*
* @return HashMap mapping session attribute names to the String
* representation of their values, or null if no session with the
* specified id exists, or if the session does not have any attributes
*/
public HashMap<String, String> getSession(String sessionId) {
Session s = sessions.get(sessionId);
if (s == null) {
if (log.isInfoEnabled()) {
log.info("Session not found " + sessionId);
}
return null;
}
Enumeration<String> ee = s.getSession().getAttributeNames();
if (ee == null || !ee.hasMoreElements()) {
return null;
}
HashMap<String, String> map = new HashMap<String, String>();
while (ee.hasMoreElements()) {
String attrName = ee.nextElement();
map.put(attrName, getSessionAttribute(sessionId, attrName));
}
return map;
}
use of org.apache.catalina.Session in project tomcat70 by apache.
the class PersistentManagerBase method findSession.
/**
* {@inheritDoc}
* <p>
* This method checks the persistence store if persistence is enabled,
* otherwise just uses the functionality from ManagerBase.
*/
@Override
public Session findSession(String id) throws IOException {
Session session = super.findSession(id);
// safely.
if (session != null) {
synchronized (session) {
session = super.findSession(session.getIdInternal());
if (session != null) {
// To keep any external calling code from messing up the
// concurrency.
session.access();
session.endAccess();
}
}
}
if (session != null)
return session;
// See if the Session is in the Store
session = swapIn(id);
return session;
}
use of org.apache.catalina.Session in project tomcat70 by apache.
the class PersistentValve method invoke.
// --------------------------------------------------------- Public Methods
/**
* Select the appropriate child Context to process this request,
* based on the specified request URI. If no matching Context can
* be found, return an appropriate HTTP error.
*
* @param request Request to be processed
* @param response Response to be produced
*
* @exception IOException if an input/output error occurred
* @exception ServletException if a servlet error occurred
*/
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
// Select the Context to be used for this Request
Context context = request.getContext();
if (context == null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sm.getString("standardHost.noContext"));
return;
}
// Update the session last access time for our session (if any)
String sessionId = request.getRequestedSessionId();
Manager manager = context.getManager();
if (sessionId != null && manager instanceof PersistentManager) {
Store store = ((PersistentManager) manager).getStore();
if (store != null) {
Session session = null;
try {
session = store.load(sessionId);
} catch (Exception e) {
container.getLogger().error("deserializeError");
}
if (session != null) {
if (!session.isValid() || isSessionStale(session, System.currentTimeMillis())) {
if (container.getLogger().isDebugEnabled()) {
container.getLogger().debug("session swapped in is invalid or expired");
}
session.expire();
store.remove(sessionId);
} else {
session.setManager(manager);
// session.setId(sessionId); Only if new ???
manager.add(session);
// ((StandardSession)session).activate();
session.access();
session.endAccess();
}
}
}
}
if (container.getLogger().isDebugEnabled()) {
container.getLogger().debug("sessionId: " + sessionId);
}
// Ask the next valve to process the request.
getNext().invoke(request, response);
// If still processing async, don't try to store the session
if (!request.isAsync()) {
// Read the sessionid after the response.
// HttpSession hsess = hreq.getSession(false);
Session hsess;
try {
hsess = request.getSessionInternal(false);
} catch (Exception ex) {
hsess = null;
}
String newsessionId = null;
if (hsess != null) {
newsessionId = hsess.getIdInternal();
}
if (container.getLogger().isDebugEnabled()) {
container.getLogger().debug("newsessionId: " + newsessionId);
}
if (newsessionId != null) {
try {
bind(context);
/* store the session and remove it from the manager */
if (manager instanceof PersistentManager) {
Session session = manager.findSession(newsessionId);
Store store = ((PersistentManager) manager).getStore();
if (store != null && session != null && session.isValid() && !isSessionStale(session, System.currentTimeMillis())) {
store.save(session);
((PersistentManager) manager).removeSuper(session);
session.recycle();
} else {
if (container.getLogger().isDebugEnabled()) {
container.getLogger().debug("newsessionId store: " + store + " session: " + session + " valid: " + (session == null ? "N/A" : Boolean.toString(session.isValid())) + " stale: " + isSessionStale(session, System.currentTimeMillis()));
}
}
} else {
if (container.getLogger().isDebugEnabled()) {
container.getLogger().debug("newsessionId Manager: " + manager);
}
}
} finally {
unbind();
}
}
}
}
Aggregations