2010-11-20 22:48:06 -08:00
|
|
|
/**
|
2010-12-22 15:35:50 +01:00
|
|
|
* Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
|
2010-11-20 22:48:06 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.http
|
|
|
|
|
|
|
|
|
|
import javax.servlet. {AsyncContext, AsyncListener, AsyncEvent};
|
|
|
|
|
import Types._
|
|
|
|
|
|
2011-03-02 18:19:17 +01:00
|
|
|
import akka.actor.{EventHandler}
|
2010-11-20 22:48:06 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Garrick Evans
|
|
|
|
|
*/
|
2011-02-28 22:54:32 +01:00
|
|
|
trait Servlet30Context extends AsyncListener {
|
2010-11-20 22:48:06 -08:00
|
|
|
import javax.servlet.http.HttpServletResponse
|
2010-11-23 12:35:14 +01:00
|
|
|
import MistSettings._
|
2010-11-20 22:48:06 -08:00
|
|
|
|
2010-11-22 13:21:55 +01:00
|
|
|
val builder: () => tAsyncRequestContext
|
|
|
|
|
val context: Option[tAsyncRequestContext] = Some(builder())
|
|
|
|
|
def go = context.isDefined
|
2010-11-20 22:48:06 -08:00
|
|
|
|
2010-11-22 13:21:55 +01:00
|
|
|
protected val _ac: AsyncContext = {
|
2010-11-20 22:48:06 -08:00
|
|
|
val ac = context.get.asInstanceOf[AsyncContext]
|
2010-11-22 13:21:55 +01:00
|
|
|
ac setTimeout DefaultTimeout
|
|
|
|
|
ac addListener this
|
2010-11-20 22:48:06 -08:00
|
|
|
ac
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-22 13:21:55 +01:00
|
|
|
def suspended = true
|
2010-11-20 22:48:06 -08:00
|
|
|
|
2010-11-23 12:35:14 +01:00
|
|
|
def timeout(ms: Long): Boolean = {
|
2010-11-20 22:48:06 -08:00
|
|
|
try {
|
2010-11-22 13:21:55 +01:00
|
|
|
_ac setTimeout ms
|
2010-11-20 22:48:06 -08:00
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
catch {
|
2010-11-23 12:35:14 +01:00
|
|
|
case ex: IllegalStateException =>
|
2011-03-14 10:45:49 +01:00
|
|
|
EventHandler notify EventHandler.Error(ex, this)
|
2010-11-20 22:48:06 -08:00
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// AsyncListener
|
|
|
|
|
//
|
2010-11-23 12:35:14 +01:00
|
|
|
def onComplete(e: AsyncEvent) {}
|
|
|
|
|
def onError(e: AsyncEvent) = e.getThrowable match {
|
2011-02-28 22:54:32 +01:00
|
|
|
case null => {}
|
|
|
|
|
case t => {}
|
2010-11-20 22:48:06 -08:00
|
|
|
}
|
2010-11-23 12:35:14 +01:00
|
|
|
def onStartAsync(e: AsyncEvent) {}
|
|
|
|
|
def onTimeout(e: AsyncEvent) = {
|
2010-11-20 22:48:06 -08:00
|
|
|
e.getSuppliedResponse.asInstanceOf[HttpServletResponse].addHeader(ExpiredHeaderName, ExpiredHeaderValue)
|
|
|
|
|
e.getAsyncContext.complete
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-22 13:21:55 +01:00
|
|
|
object Servlet30ContextMethodFactory extends RequestMethodFactory {
|
|
|
|
|
def Delete(f: () => tAsyncRequestContext): RequestMethod = new Delete(f) with Servlet30Context
|
|
|
|
|
def Get(f: () => tAsyncRequestContext): RequestMethod = new Get(f) with Servlet30Context
|
|
|
|
|
def Head(f: () => tAsyncRequestContext): RequestMethod = new Head(f) with Servlet30Context
|
|
|
|
|
def Options(f: () => tAsyncRequestContext): RequestMethod = new Options(f) with Servlet30Context
|
|
|
|
|
def Post(f: () => tAsyncRequestContext): RequestMethod = new Post(f) with Servlet30Context
|
|
|
|
|
def Put(f: () => tAsyncRequestContext): RequestMethod = new Put(f) with Servlet30Context
|
|
|
|
|
def Trace(f: () => tAsyncRequestContext): RequestMethod = new Trace(f) with Servlet30Context
|
2010-11-20 22:48:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|