* Adopt suggestions from bug 441: http://helma.org/bugs/show_bug.cgi?id=441
- Catch FileNotFoundException in loadSessions() and suppress error message - Catch NotSerializableException in storeSessions() in order to continue serializing. * Use logError() for error logging. * Minor code improvements.
This commit is contained in:
parent
b7f0aa4ee2
commit
96605d1c69
1 changed files with 14 additions and 11 deletions
|
@ -138,9 +138,7 @@ public class SessionManager {
|
||||||
while (e.hasMoreElements()) {
|
while (e.hasMoreElements()) {
|
||||||
Session s = (Session) e.nextElement();
|
Session s = (Session) e.nextElement();
|
||||||
|
|
||||||
if (s == null) {
|
if (s != null && username.equals(s.getUID())) {
|
||||||
continue;
|
|
||||||
} else if (username.equals(s.getUID())) {
|
|
||||||
// append to list if session is logged in and fits the given username
|
// append to list if session is logged in and fits the given username
|
||||||
list.add(new SessionBean(s));
|
list.add(new SessionBean(s));
|
||||||
}
|
}
|
||||||
|
@ -159,9 +157,7 @@ public class SessionManager {
|
||||||
for (Enumeration e = sessions.elements(); e.hasMoreElements();) {
|
for (Enumeration e = sessions.elements(); e.hasMoreElements();) {
|
||||||
Session s = (Session) e.nextElement();
|
Session s = (Session) e.nextElement();
|
||||||
|
|
||||||
if (s == null) {
|
if (s != null && s.isLoggedIn()) {
|
||||||
continue;
|
|
||||||
} else if (s.isLoggedIn()) {
|
|
||||||
// returns a session if it is logged in and has not been
|
// returns a session if it is logged in and has not been
|
||||||
// returned before (so for each logged-in user is only added once)
|
// returned before (so for each logged-in user is only added once)
|
||||||
INode node = s.getUserNode();
|
INode node = s.getUserNode();
|
||||||
|
@ -178,9 +174,9 @@ public class SessionManager {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Dump session state to a file.
|
||||||
*
|
*
|
||||||
*
|
* @param f the file to write session into, or null to use the default sesssion store.
|
||||||
* @param f ...
|
|
||||||
*/
|
*/
|
||||||
public void storeSessionData(File f) {
|
public void storeSessionData(File f) {
|
||||||
if (f == null) {
|
if (f == null) {
|
||||||
|
@ -195,7 +191,12 @@ public class SessionManager {
|
||||||
p.writeInt(sessions.size());
|
p.writeInt(sessions.size());
|
||||||
|
|
||||||
for (Enumeration e = sessions.elements(); e.hasMoreElements();) {
|
for (Enumeration e = sessions.elements(); e.hasMoreElements();) {
|
||||||
p.writeObject(e.nextElement());
|
try {
|
||||||
|
p.writeObject(e.nextElement());
|
||||||
|
} catch (NotSerializableException nsx) {
|
||||||
|
// not serializable, skip this session
|
||||||
|
app.logError("Error serializing session.", nsx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +204,7 @@ public class SessionManager {
|
||||||
ostream.close();
|
ostream.close();
|
||||||
app.logEvent("stored " + sessions.size() + " sessions in file");
|
app.logEvent("stored " + sessions.size() + " sessions in file");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
app.logEvent("error storing session data: " + e.toString());
|
app.logError("error storing session data.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,8 +252,10 @@ public class SessionManager {
|
||||||
istream.close();
|
istream.close();
|
||||||
sessions = newSessions;
|
sessions = newSessions;
|
||||||
app.logEvent("loaded " + newSessions.size() + " sessions from file");
|
app.logEvent("loaded " + newSessions.size() + " sessions from file");
|
||||||
|
} catch (FileNotFoundException fnf) {
|
||||||
|
// suppress error message if session file doesn't exist
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
app.logEvent("error loading session data: " + e.toString());
|
app.logError("error loading session data.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue