Created
August 27, 2012 04:19
-
-
Save LeifWarner/3485500 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.scalatra.servlet | |
import java.io.{NotSerializableException, OutputStream, ObjectOutputStream} | |
import javax.servlet.http.{HttpSessionAttributeListener, HttpSessionBindingEvent} | |
object NullOut extends OutputStream { | |
def write(b: Int) {} | |
} | |
object SessionSerializingListener extends HttpSessionAttributeListener { | |
//val oos = new ObjectOutputStream(System.out) | |
val oos = new ObjectOutputStream(NullOut) | |
def attributeAdded(event: HttpSessionBindingEvent) { | |
serializeSession(event) | |
} | |
def attributeRemoved(event: HttpSessionBindingEvent) { | |
serializeSession(event) | |
} | |
def attributeReplaced(event: HttpSessionBindingEvent) { | |
serializeSession(event) | |
} | |
def serializeSession(event: HttpSessionBindingEvent) { | |
try { | |
oos.writeObject(event.getValue) | |
} catch { | |
case e: NotSerializableException => | |
sys.error("Can't serialize session key '" + event.getName + "' value of type " + e.getMessage) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
servletContextHandler.getSessionHandler.addEventListener(SessionSerializingListener)