Skip to content

Commit

Permalink
Prevent hanging instances when session archiving fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
nullterminated committed Jun 30, 2013
1 parent 33bdde7 commit b76ba9c
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package er.persistentsessionstorage;

import org.apache.log4j.Logger;

import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WORequest;
import com.webobjects.appserver.WOSession;
import com.webobjects.appserver.WOSessionStore;
import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.foundation.NSMutableDictionary;
import com.webobjects.foundation.NSTimestamp;

import er.extensions.appserver.ERXApplication;
import er.extensions.eof.ERXEC;
import er.persistentsessionstorage.model.ERSessionInfo;

public class ERPersistentSessionStore extends WOSessionStore {
private static final Logger log = Logger.getLogger(ERPersistentSessionStore.class);

@Override
public WOSession removeSessionWithID(String s) {
Expand Down Expand Up @@ -43,7 +48,26 @@ public void saveSessionForContext(WOContext context) {
}
NSTimestamp expires = new NSTimestamp(System.currentTimeMillis() + session.timeOutMillis());
info.setExpirationDate(expires);
info.archiveDataFromSession(session);
try {
/*
* An error here can later hang the instance when the session is restored.
* If the session fails to archive, delete it.
*/
info.archiveDataFromSession(session);
} catch (Exception e) {
log.error("Error archiving session! Deleting session.");
ERXApplication app = ERXApplication.erxApplication();
NSMutableDictionary extraInfo = app.extraInformationForExceptionInContext(e, context);
app.reportException(e, context, extraInfo);
/*
* If the session info is new, just don't save it.
* Otherwise, we need to delete the session.
*/
if(!info.isNewObject()) {
removeSessionWithID(session.sessionID());
}
return;
}
ec.saveChanges();
}

Expand Down

0 comments on commit b76ba9c

Please sign in to comment.