Skip to content

Instantly share code, notes, and snippets.

@mente
Created September 16, 2011 14:12
Show Gist options
  • Save mente/1222206 to your computer and use it in GitHub Desktop.
Save mente/1222206 to your computer and use it in GitHub Desktop.
public void setSessionMode(String sessionMode) {
String mode = sessionMode;
if (mode == null) {
throw new IllegalArgumentException("sessionMode argument cannot be null.");
}
mode = sessionMode.toLowerCase();
if (!HTTP_SESSION_MODE.equals(mode) && !NATIVE_SESSION_MODE.equals(mode)) {
String msg = "Invalid sessionMode [" + sessionMode + "]. Allowed values are " +
"public static final String constants in the " + getClass().getName() + " class: '"
+ HTTP_SESSION_MODE + "' or '" + NATIVE_SESSION_MODE + "', with '" +
HTTP_SESSION_MODE + "' being the default.";
throw new IllegalArgumentException(msg);
}
boolean recreate = this.sessionMode == null || !this.sessionMode.equals(mode);
this.sessionMode = mode;
if (recreate) {
LifecycleUtils.destroy(getSessionManager());
SessionManager sessionManager = createSessionManager(mode);
setSessionManager(sessionManager);
}
}
/**
* @since 1.0
*/
public boolean isHttpSessionMode() {
return this.sessionMode == null || this.sessionMode.equals(HTTP_SESSION_MODE);
}
protected SessionManager createSessionManager(String sessionMode) {
if (sessionMode == null || sessionMode.equalsIgnoreCase(HTTP_SESSION_MODE)) {
if (log.isInfoEnabled()) {
log.info(HTTP_SESSION_MODE + " mode - enabling ServletContainerSessionManager (HTTP-only Sessions)");
}
return new ServletContainerSessionManager();
} else {
if (log.isInfoEnabled()) {
log.info(NATIVE_SESSION_MODE + " mode - enabling DefaultWebSessionManager (HTTP + heterogeneous-client sessions)");
}
return new DefaultWebSessionManager();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment