From 50caa966d14cb1d9dbaf694ca21a8ce88476ec20 Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 11 Oct 2011 16:05:48 +0200 Subject: [PATCH 1/5] make akka-actor-tests compile again --- .../scala/akka/http/JettyContinuation.scala | 41 ++++++++++-------- akka-http/src/main/scala/akka/http/Mist.scala | 43 +++++++------------ .../scala/akka/http/Servlet30Context.scala | 30 +++++++------ .../src/test/scala/config/ConfigSpec.scala | 9 ++-- 4 files changed, 60 insertions(+), 63 deletions(-) diff --git a/akka-http/src/main/scala/akka/http/JettyContinuation.scala b/akka-http/src/main/scala/akka/http/JettyContinuation.scala index 7a0e6febac..fea864541e 100644 --- a/akka-http/src/main/scala/akka/http/JettyContinuation.scala +++ b/akka-http/src/main/scala/akka/http/JettyContinuation.scala @@ -9,13 +9,15 @@ package akka.http import org.eclipse.jetty.server._ import org.eclipse.jetty.continuation._ import Types._ +import akka.AkkaApplication /** * @author Garrick Evans */ trait JettyContinuation extends ContinuationListener { import javax.servlet.http.HttpServletResponse - import MistSettings._ + + protected def application: AkkaApplication val builder: () ⇒ tAsyncRequestContext val context: Option[tAsyncRequestContext] = Some(builder()) @@ -33,7 +35,7 @@ trait JettyContinuation extends ContinuationListener { // the fresh continuation (coming through getAsyncContinuation) // case (true, false, false) ⇒ { - continuation.setTimeout(DefaultTimeout) + continuation.setTimeout(application.MistSettings.DefaultTimeout) continuation.addContinuationListener(this) continuation.suspend @@ -45,7 +47,7 @@ trait JettyContinuation extends ContinuationListener { // case (true, true, false) ⇒ { - continuation.setTimeout(DefaultTimeout) + continuation.setTimeout(application.MistSettings.DefaultTimeout) continuation.addContinuationListener(this) Some(continuation) @@ -56,9 +58,9 @@ trait JettyContinuation extends ContinuationListener { // case (false, false, false) ⇒ { - continuation.setTimeout(continuation.getAttribute(TimeoutAttribute).asInstanceOf[Long]) + continuation.setTimeout(continuation.getAttribute(application.MistSettings.TimeoutAttribute).asInstanceOf[Long]) continuation.suspend - continuation.removeAttribute(TimeoutAttribute) + continuation.removeAttribute(application.MistSettings.TimeoutAttribute) None } @@ -68,8 +70,8 @@ trait JettyContinuation extends ContinuationListener { // case (false, true, false) ⇒ { - continuation.setTimeout(continuation.getAttribute(TimeoutAttribute).asInstanceOf[Long]) - continuation.removeAttribute(TimeoutAttribute) + continuation.setTimeout(continuation.getAttribute(application.MistSettings.TimeoutAttribute).asInstanceOf[Long]) + continuation.removeAttribute(application.MistSettings.TimeoutAttribute) None } @@ -85,13 +87,13 @@ trait JettyContinuation extends ContinuationListener { def suspended: Boolean = _continuation match { case None ⇒ false - case Some(continuation) ⇒ (continuation.isSuspended || (continuation.getAttribute(TimeoutAttribute) ne null)) + case Some(continuation) ⇒ (continuation.isSuspended || (continuation.getAttribute(application.MistSettings.TimeoutAttribute) ne null)) } def timeout(ms: Long): Boolean = _continuation match { case None ⇒ false case Some(continuation) ⇒ - continuation.setAttribute(TimeoutAttribute, ms) + continuation.setAttribute(application.MistSettings.TimeoutAttribute, ms) continuation.resume true } @@ -101,18 +103,21 @@ trait JettyContinuation extends ContinuationListener { // def onComplete(c: Continuation) = {} def onTimeout(c: Continuation) = { - c.getServletResponse.asInstanceOf[HttpServletResponse].addHeader(ExpiredHeaderName, ExpiredHeaderValue) + c.getServletResponse.asInstanceOf[HttpServletResponse].addHeader(application.MistSettings.ExpiredHeaderName, application.MistSettings.ExpiredHeaderValue) c.complete } } -object JettyContinuationMethodFactory extends RequestMethodFactory { - def Delete(f: () ⇒ tAsyncRequestContext): RequestMethod = new Delete(f) with JettyContinuation - def Get(f: () ⇒ tAsyncRequestContext): RequestMethod = new Get(f) with JettyContinuation - def Head(f: () ⇒ tAsyncRequestContext): RequestMethod = new Head(f) with JettyContinuation - def Options(f: () ⇒ tAsyncRequestContext): RequestMethod = new Options(f) with JettyContinuation - def Post(f: () ⇒ tAsyncRequestContext): RequestMethod = new Post(f) with JettyContinuation - def Put(f: () ⇒ tAsyncRequestContext): RequestMethod = new Put(f) with JettyContinuation - def Trace(f: () ⇒ tAsyncRequestContext): RequestMethod = new Trace(f) with JettyContinuation +class JettyContinuationMethodFactory(val _application: AkkaApplication) extends RequestMethodFactory { + trait App { + def application = _application + } + def Delete(f: () ⇒ tAsyncRequestContext): RequestMethod = new Delete(f) with JettyContinuation with App + def Get(f: () ⇒ tAsyncRequestContext): RequestMethod = new Get(f) with JettyContinuation with App + def Head(f: () ⇒ tAsyncRequestContext): RequestMethod = new Head(f) with JettyContinuation with App + def Options(f: () ⇒ tAsyncRequestContext): RequestMethod = new Options(f) with JettyContinuation with App + def Post(f: () ⇒ tAsyncRequestContext): RequestMethod = new Post(f) with JettyContinuation with App + def Put(f: () ⇒ tAsyncRequestContext): RequestMethod = new Put(f) with JettyContinuation with App + def Trace(f: () ⇒ tAsyncRequestContext): RequestMethod = new Trace(f) with JettyContinuation with App } diff --git a/akka-http/src/main/scala/akka/http/Mist.scala b/akka-http/src/main/scala/akka/http/Mist.scala index 8c181ea47b..1139575aa7 100644 --- a/akka-http/src/main/scala/akka/http/Mist.scala +++ b/akka-http/src/main/scala/akka/http/Mist.scala @@ -6,30 +6,17 @@ package akka.http import akka.event.EventHandler import akka.config.ConfigurationException - import javax.servlet.http.{ HttpServletResponse, HttpServletRequest } import javax.servlet.http.HttpServlet import javax.servlet.Filter import java.lang.UnsupportedOperationException import akka.actor.{ NullChannel, ActorRef, Actor } +import Types._ +import akka.AkkaApplication /** * @author Garrick Evans */ -object MistSettings { - import akka.config.Config._ - - val JettyServer = "jetty" - val TimeoutAttribute = "timeout" - - val ConnectionClose = config.getBool("akka.http.connection-close", true) - val RootActorBuiltin = config.getBool("akka.http.root-actor-builtin", true) - val RootActorID = config.getString("akka.http.root-actor-id", "_httproot") - val DefaultTimeout = config.getLong("akka.http.timeout", 1000) - val ExpiredHeaderName = config.getString("akka.http.expired-header-name", "Async-Timeout") - val ExpiredHeaderValue = config.getString("akka.http.expired-header-value", "expired") -} - /** * Structural type alias's required to work with both Servlet 3.0 and Jetty's Continuation API * @@ -60,14 +47,15 @@ object Types { def Headers(): Headers = Nil } -import Types._ + /** * */ trait Mist { import javax.servlet.ServletContext - import MistSettings._ + + protected def application: AkkaApplication /** * The root endpoint actor @@ -113,7 +101,7 @@ trait Mist { // shoot the message to the root endpoint for processing // IMPORTANT: the suspend method is invoked on the server thread not in the actor - val method = builder(() ⇒ suspend(ConnectionClose)) + val method = builder(() ⇒ suspend(application.MistSettings.ConnectionClose)) if (method.go) root ! method } @@ -125,9 +113,9 @@ trait Mist { val server = context.getServerInfo val (major, minor) = (context.getMajorVersion, context.getMinorVersion) factory = if (major >= 3) { - Some(Servlet30ContextMethodFactory) - } else if (server.toLowerCase startsWith JettyServer) { - Some(JettyContinuationMethodFactory) + Some(new Servlet30ContextMethodFactory(application)) + } else if (server.toLowerCase startsWith application.MistSettings.JettyServer) { + Some(new JettyContinuationMethodFactory(application)) } else { None } @@ -136,13 +124,15 @@ trait Mist { trait RootEndpointLocator { var root: ActorRef = null + + protected def application: AkkaApplication def configureRoot(address: String) { def findRoot(address: String): ActorRef = - Actor.registry.actorFor(address).getOrElse( + application.registry.actorFor(address).getOrElse( throw new ConfigurationException("akka.http.root-actor-id configuration option does not have a valid actor address [" + address + "]")) - root = if ((address eq null) || address == "") findRoot(MistSettings.RootActorID) else findRoot(address) + root = if ((address eq null) || address == "") findRoot(application.MistSettings.RootActorID) else findRoot(address) } } @@ -150,7 +140,7 @@ trait RootEndpointLocator { * AkkaMistServlet adds support to bridge Http and Actors in an asynchronous fashion * Async impls currently supported: Servlet3.0, Jetty Continuations */ -class AkkaMistServlet extends HttpServlet with Mist with RootEndpointLocator { +class AkkaMistServlet(val application: AkkaApplication) extends HttpServlet with Mist with RootEndpointLocator { import javax.servlet.{ ServletConfig } /** @@ -169,7 +159,7 @@ class AkkaMistServlet extends HttpServlet with Mist with RootEndpointLocator { * Proof-of-concept, use at own risk * Will be officially supported in a later release */ -class AkkaMistFilter extends Filter with Mist with RootEndpointLocator { +class AkkaMistFilter(val application: AkkaApplication) extends Filter with Mist with RootEndpointLocator { import javax.servlet.{ ServletRequest, ServletResponse, FilterConfig, FilterChain } /** @@ -205,7 +195,7 @@ object Endpoint { /** * leverage the akka config to tweak the dispatcher for our endpoints */ - lazy val Dispatcher = Dispatchers.fromConfig("akka.http.mist-dispatcher") + //lazy val Dispatcher = Dispatchers.fromConfig("akka.http.mist-dispatcher") type Hook = PartialFunction[String, ActorRef] @@ -276,7 +266,6 @@ trait Endpoint { this: Actor ⇒ class RootEndpoint extends Actor with Endpoint { import Endpoint._ - import MistSettings._ final val Root = "/" diff --git a/akka-http/src/main/scala/akka/http/Servlet30Context.scala b/akka-http/src/main/scala/akka/http/Servlet30Context.scala index 809e5229bd..e2436c3361 100644 --- a/akka-http/src/main/scala/akka/http/Servlet30Context.scala +++ b/akka-http/src/main/scala/akka/http/Servlet30Context.scala @@ -4,17 +4,18 @@ package akka.http -import javax.servlet.{ AsyncContext, AsyncListener, AsyncEvent }; +import javax.servlet.{ AsyncContext, AsyncListener, AsyncEvent } import Types._ - import akka.event.EventHandler +import akka.AkkaApplication /** * @author Garrick Evans */ trait Servlet30Context extends AsyncListener { import javax.servlet.http.HttpServletResponse - import MistSettings._ + + protected def application: AkkaApplication val builder: () ⇒ tAsyncRequestContext val context: Option[tAsyncRequestContext] = Some(builder()) @@ -22,7 +23,7 @@ trait Servlet30Context extends AsyncListener { protected val _ac: AsyncContext = { val ac = context.get.asInstanceOf[AsyncContext] - ac setTimeout DefaultTimeout + ac setTimeout application.MistSettings.DefaultTimeout ac addListener this ac } @@ -50,18 +51,21 @@ trait Servlet30Context extends AsyncListener { } def onStartAsync(e: AsyncEvent) {} def onTimeout(e: AsyncEvent) = { - e.getSuppliedResponse.asInstanceOf[HttpServletResponse].addHeader(ExpiredHeaderName, ExpiredHeaderValue) + e.getSuppliedResponse.asInstanceOf[HttpServletResponse].addHeader(application.MistSettings.ExpiredHeaderName, application.MistSettings.ExpiredHeaderValue) e.getAsyncContext.complete } } -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 +class Servlet30ContextMethodFactory(val _application: AkkaApplication) extends RequestMethodFactory { + trait App { + def application = _application + } + def Delete(f: () ⇒ tAsyncRequestContext): RequestMethod = new Delete(f) with Servlet30Context with App + def Get(f: () ⇒ tAsyncRequestContext): RequestMethod = new Get(f) with Servlet30Context with App + def Head(f: () ⇒ tAsyncRequestContext): RequestMethod = new Head(f) with Servlet30Context with App + def Options(f: () ⇒ tAsyncRequestContext): RequestMethod = new Options(f) with Servlet30Context with App + def Post(f: () ⇒ tAsyncRequestContext): RequestMethod = new Post(f) with Servlet30Context with App + def Put(f: () ⇒ tAsyncRequestContext): RequestMethod = new Put(f) with Servlet30Context with App + def Trace(f: () ⇒ tAsyncRequestContext): RequestMethod = new Trace(f) with Servlet30Context with App } diff --git a/akka-http/src/test/scala/config/ConfigSpec.scala b/akka-http/src/test/scala/config/ConfigSpec.scala index 67a26a42f0..caa8610e4a 100644 --- a/akka-http/src/test/scala/config/ConfigSpec.scala +++ b/akka-http/src/test/scala/config/ConfigSpec.scala @@ -4,18 +4,17 @@ package akka.config +import akka.testkit.AkkaSpec + import org.junit.runner.RunWith -import org.scalatest.WordSpec import org.scalatest.junit.JUnitRunner -import org.scalatest.matchers.MustMatchers @RunWith(classOf[JUnitRunner]) -class ConfigSpec extends WordSpec with MustMatchers { +class ConfigSpec extends AkkaSpec { "The default configuration file (i.e. akka-reference.conf)" should { "contain all configuration properties for akka-http that are used in code with their correct defaults" in { - import Config.config._ - + import application.config._ getBool("akka.http.connection-close") must equal(Some(true)) getString("akka.http.expired-header-name") must equal(Some("Async-Timeout")) getString("akka.http.hostname") must equal(Some("localhost")) From 4df5b801fa99feb27fbb35579cdd813c42f8e57e Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 12 Oct 2011 09:10:05 +0200 Subject: [PATCH 2/5] make everything except tutorial-second compile someone should look at remoting vs. timeout (i.e. which is sent around), because I removed that in some places. It might simply be irrelevant once we remove the Future special-casing. --- akka-http/src/test/scala/config/ConfigSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akka-http/src/test/scala/config/ConfigSpec.scala b/akka-http/src/test/scala/config/ConfigSpec.scala index caa8610e4a..5423dd8aa7 100644 --- a/akka-http/src/test/scala/config/ConfigSpec.scala +++ b/akka-http/src/test/scala/config/ConfigSpec.scala @@ -14,7 +14,7 @@ class ConfigSpec extends AkkaSpec { "The default configuration file (i.e. akka-reference.conf)" should { "contain all configuration properties for akka-http that are used in code with their correct defaults" in { - import application.config._ + import app.config._ getBool("akka.http.connection-close") must equal(Some(true)) getString("akka.http.expired-header-name") must equal(Some("Async-Timeout")) getString("akka.http.hostname") must equal(Some("localhost")) From e945dcfbe74e546fda39ddd40bfaba8951881aa7 Mon Sep 17 00:00:00 2001 From: Peter Vlugter Date: Wed, 12 Oct 2011 09:57:33 +0200 Subject: [PATCH 3/5] Fix actor ref spec --- akka-http/src/main/scala/akka/http/JettyContinuation.scala | 2 +- akka-http/src/main/scala/akka/http/Mist.scala | 6 ++---- akka-http/src/main/scala/akka/http/Servlet30Context.scala | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/akka-http/src/main/scala/akka/http/JettyContinuation.scala b/akka-http/src/main/scala/akka/http/JettyContinuation.scala index fea864541e..d6665b00e3 100644 --- a/akka-http/src/main/scala/akka/http/JettyContinuation.scala +++ b/akka-http/src/main/scala/akka/http/JettyContinuation.scala @@ -16,7 +16,7 @@ import akka.AkkaApplication */ trait JettyContinuation extends ContinuationListener { import javax.servlet.http.HttpServletResponse - + protected def application: AkkaApplication val builder: () ⇒ tAsyncRequestContext diff --git a/akka-http/src/main/scala/akka/http/Mist.scala b/akka-http/src/main/scala/akka/http/Mist.scala index 1139575aa7..829db96286 100644 --- a/akka-http/src/main/scala/akka/http/Mist.scala +++ b/akka-http/src/main/scala/akka/http/Mist.scala @@ -47,14 +47,12 @@ object Types { def Headers(): Headers = Nil } - - /** * */ trait Mist { import javax.servlet.ServletContext - + protected def application: AkkaApplication /** @@ -124,7 +122,7 @@ trait Mist { trait RootEndpointLocator { var root: ActorRef = null - + protected def application: AkkaApplication def configureRoot(address: String) { diff --git a/akka-http/src/main/scala/akka/http/Servlet30Context.scala b/akka-http/src/main/scala/akka/http/Servlet30Context.scala index e2436c3361..8f3c191d32 100644 --- a/akka-http/src/main/scala/akka/http/Servlet30Context.scala +++ b/akka-http/src/main/scala/akka/http/Servlet30Context.scala @@ -14,7 +14,7 @@ import akka.AkkaApplication */ trait Servlet30Context extends AsyncListener { import javax.servlet.http.HttpServletResponse - + protected def application: AkkaApplication val builder: () ⇒ tAsyncRequestContext From 32effb5083e57bae77de91e0db5eb0cb6d18665b Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 13 Oct 2011 13:16:41 +0200 Subject: [PATCH 4/5] make EventHandler non-global - add Logging trait for nicer interface - add EventHandlerLogging class for offering the nice interface from app.log - add eventHandler instance to app and use that for all internal logging (this means that some places (dispatchers, remoting) were infiltrated by app just to do logging, but I think we'll need app in there soon enough for other reasons) --- .../scala/akka/http/JettyContinuation.scala | 42 +++++++++---------- akka-http/src/main/scala/akka/http/Mist.scala | 40 +++++++++--------- .../scala/akka/http/Servlet30Context.scala | 31 +++++++------- 3 files changed, 55 insertions(+), 58 deletions(-) diff --git a/akka-http/src/main/scala/akka/http/JettyContinuation.scala b/akka-http/src/main/scala/akka/http/JettyContinuation.scala index d6665b00e3..8fcd6b21a9 100644 --- a/akka-http/src/main/scala/akka/http/JettyContinuation.scala +++ b/akka-http/src/main/scala/akka/http/JettyContinuation.scala @@ -16,8 +16,8 @@ import akka.AkkaApplication */ trait JettyContinuation extends ContinuationListener { import javax.servlet.http.HttpServletResponse - - protected def application: AkkaApplication + + def app: AkkaApplication val builder: () ⇒ tAsyncRequestContext val context: Option[tAsyncRequestContext] = Some(builder()) @@ -35,7 +35,7 @@ trait JettyContinuation extends ContinuationListener { // the fresh continuation (coming through getAsyncContinuation) // case (true, false, false) ⇒ { - continuation.setTimeout(application.MistSettings.DefaultTimeout) + continuation.setTimeout(app.MistSettings.DefaultTimeout) continuation.addContinuationListener(this) continuation.suspend @@ -47,7 +47,7 @@ trait JettyContinuation extends ContinuationListener { // case (true, true, false) ⇒ { - continuation.setTimeout(application.MistSettings.DefaultTimeout) + continuation.setTimeout(app.MistSettings.DefaultTimeout) continuation.addContinuationListener(this) Some(continuation) @@ -58,9 +58,9 @@ trait JettyContinuation extends ContinuationListener { // case (false, false, false) ⇒ { - continuation.setTimeout(continuation.getAttribute(application.MistSettings.TimeoutAttribute).asInstanceOf[Long]) + continuation.setTimeout(continuation.getAttribute(app.MistSettings.TimeoutAttribute).asInstanceOf[Long]) continuation.suspend - continuation.removeAttribute(application.MistSettings.TimeoutAttribute) + continuation.removeAttribute(app.MistSettings.TimeoutAttribute) None } @@ -70,8 +70,8 @@ trait JettyContinuation extends ContinuationListener { // case (false, true, false) ⇒ { - continuation.setTimeout(continuation.getAttribute(application.MistSettings.TimeoutAttribute).asInstanceOf[Long]) - continuation.removeAttribute(application.MistSettings.TimeoutAttribute) + continuation.setTimeout(continuation.getAttribute(app.MistSettings.TimeoutAttribute).asInstanceOf[Long]) + continuation.removeAttribute(app.MistSettings.TimeoutAttribute) None } @@ -87,13 +87,13 @@ trait JettyContinuation extends ContinuationListener { def suspended: Boolean = _continuation match { case None ⇒ false - case Some(continuation) ⇒ (continuation.isSuspended || (continuation.getAttribute(application.MistSettings.TimeoutAttribute) ne null)) + case Some(continuation) ⇒ (continuation.isSuspended || (continuation.getAttribute(app.MistSettings.TimeoutAttribute) ne null)) } def timeout(ms: Long): Boolean = _continuation match { case None ⇒ false case Some(continuation) ⇒ - continuation.setAttribute(application.MistSettings.TimeoutAttribute, ms) + continuation.setAttribute(app.MistSettings.TimeoutAttribute, ms) continuation.resume true } @@ -103,21 +103,19 @@ trait JettyContinuation extends ContinuationListener { // def onComplete(c: Continuation) = {} def onTimeout(c: Continuation) = { - c.getServletResponse.asInstanceOf[HttpServletResponse].addHeader(application.MistSettings.ExpiredHeaderName, application.MistSettings.ExpiredHeaderValue) + c.getServletResponse.asInstanceOf[HttpServletResponse].addHeader(app.MistSettings.ExpiredHeaderName, app.MistSettings.ExpiredHeaderValue) c.complete } } -class JettyContinuationMethodFactory(val _application: AkkaApplication) extends RequestMethodFactory { - trait App { - def application = _application - } - def Delete(f: () ⇒ tAsyncRequestContext): RequestMethod = new Delete(f) with JettyContinuation with App - def Get(f: () ⇒ tAsyncRequestContext): RequestMethod = new Get(f) with JettyContinuation with App - def Head(f: () ⇒ tAsyncRequestContext): RequestMethod = new Head(f) with JettyContinuation with App - def Options(f: () ⇒ tAsyncRequestContext): RequestMethod = new Options(f) with JettyContinuation with App - def Post(f: () ⇒ tAsyncRequestContext): RequestMethod = new Post(f) with JettyContinuation with App - def Put(f: () ⇒ tAsyncRequestContext): RequestMethod = new Put(f) with JettyContinuation with App - def Trace(f: () ⇒ tAsyncRequestContext): RequestMethod = new Trace(f) with JettyContinuation with App +class JettyContinuationMethodFactory(_app: AkkaApplication) extends RequestMethodFactory { + implicit val app = _app + def Delete(f: () ⇒ tAsyncRequestContext): RequestMethod = new Delete(f) with JettyContinuation + def Get(f: () ⇒ tAsyncRequestContext): RequestMethod = new Get(f) with JettyContinuation + def Head(f: () ⇒ tAsyncRequestContext): RequestMethod = new Head(f) with JettyContinuation + def Options(f: () ⇒ tAsyncRequestContext): RequestMethod = new Options(f) with JettyContinuation + def Post(f: () ⇒ tAsyncRequestContext): RequestMethod = new Post(f) with JettyContinuation + def Put(f: () ⇒ tAsyncRequestContext): RequestMethod = new Put(f) with JettyContinuation + def Trace(f: () ⇒ tAsyncRequestContext): RequestMethod = new Trace(f) with JettyContinuation } diff --git a/akka-http/src/main/scala/akka/http/Mist.scala b/akka-http/src/main/scala/akka/http/Mist.scala index 829db96286..6d530ad0f3 100644 --- a/akka-http/src/main/scala/akka/http/Mist.scala +++ b/akka-http/src/main/scala/akka/http/Mist.scala @@ -53,7 +53,7 @@ object Types { trait Mist { import javax.servlet.ServletContext - protected def application: AkkaApplication + protected def app: AkkaApplication /** * The root endpoint actor @@ -99,7 +99,7 @@ trait Mist { // shoot the message to the root endpoint for processing // IMPORTANT: the suspend method is invoked on the server thread not in the actor - val method = builder(() ⇒ suspend(application.MistSettings.ConnectionClose)) + val method = builder(() ⇒ suspend(app.MistSettings.ConnectionClose)) if (method.go) root ! method } @@ -111,9 +111,9 @@ trait Mist { val server = context.getServerInfo val (major, minor) = (context.getMajorVersion, context.getMinorVersion) factory = if (major >= 3) { - Some(new Servlet30ContextMethodFactory(application)) - } else if (server.toLowerCase startsWith application.MistSettings.JettyServer) { - Some(new JettyContinuationMethodFactory(application)) + Some(new Servlet30ContextMethodFactory(app)) + } else if (server.toLowerCase startsWith app.MistSettings.JettyServer) { + Some(new JettyContinuationMethodFactory(app)) } else { None } @@ -123,14 +123,14 @@ trait Mist { trait RootEndpointLocator { var root: ActorRef = null - protected def application: AkkaApplication + protected def app: AkkaApplication def configureRoot(address: String) { def findRoot(address: String): ActorRef = - application.registry.actorFor(address).getOrElse( + app.registry.actorFor(address).getOrElse( throw new ConfigurationException("akka.http.root-actor-id configuration option does not have a valid actor address [" + address + "]")) - root = if ((address eq null) || address == "") findRoot(application.MistSettings.RootActorID) else findRoot(address) + root = if ((address eq null) || address == "") findRoot(app.MistSettings.RootActorID) else findRoot(address) } } @@ -138,7 +138,7 @@ trait RootEndpointLocator { * AkkaMistServlet adds support to bridge Http and Actors in an asynchronous fashion * Async impls currently supported: Servlet3.0, Jetty Continuations */ -class AkkaMistServlet(val application: AkkaApplication) extends HttpServlet with Mist with RootEndpointLocator { +class AkkaMistServlet(val app: AkkaApplication) extends HttpServlet with Mist with RootEndpointLocator { import javax.servlet.{ ServletConfig } /** @@ -157,7 +157,7 @@ class AkkaMistServlet(val application: AkkaApplication) extends HttpServlet with * Proof-of-concept, use at own risk * Will be officially supported in a later release */ -class AkkaMistFilter(val application: AkkaApplication) extends Filter with Mist with RootEndpointLocator { +class AkkaMistFilter(val app: AkkaApplication) extends Filter with Mist with RootEndpointLocator { import javax.servlet.{ ServletRequest, ServletResponse, FilterConfig, FilterChain } /** @@ -294,6 +294,8 @@ class RootEndpoint extends Actor with Endpoint { trait RequestMethod { import java.io.IOException import javax.servlet.http.{ HttpServletResponse, HttpServletRequest } + + def app: AkkaApplication // required implementations val builder: () ⇒ tAsyncRequestContext @@ -358,7 +360,7 @@ trait RequestMethod { } } catch { case io: Exception ⇒ - EventHandler.error(io, this, io.getMessage) + app.eventHandler.error(io, this, io.getMessage) false } case None ⇒ false @@ -374,7 +376,7 @@ trait RequestMethod { } } catch { case io: IOException ⇒ - EventHandler.error(io, this, io.getMessage) + app.eventHandler.error(io, this, io.getMessage) } case None ⇒ {} } @@ -401,13 +403,13 @@ trait RequestMethod { def Unavailable(body: String, retry: Int): Boolean = complete(HttpServletResponse.SC_SERVICE_UNAVAILABLE, body, List(("Retry-After", retry.toString))) } -abstract class Delete(val builder: () ⇒ tAsyncRequestContext) extends RequestMethod -abstract class Get(val builder: () ⇒ tAsyncRequestContext) extends RequestMethod -abstract class Head(val builder: () ⇒ tAsyncRequestContext) extends RequestMethod -abstract class Options(val builder: () ⇒ tAsyncRequestContext) extends RequestMethod -abstract class Post(val builder: () ⇒ tAsyncRequestContext) extends RequestMethod -abstract class Put(val builder: () ⇒ tAsyncRequestContext) extends RequestMethod -abstract class Trace(val builder: () ⇒ tAsyncRequestContext) extends RequestMethod +abstract class Delete(val builder: () ⇒ tAsyncRequestContext)(implicit val app: AkkaApplication) extends RequestMethod +abstract class Get(val builder: () ⇒ tAsyncRequestContext)(implicit val app: AkkaApplication) extends RequestMethod +abstract class Head(val builder: () ⇒ tAsyncRequestContext)(implicit val app: AkkaApplication) extends RequestMethod +abstract class Options(val builder: () ⇒ tAsyncRequestContext)(implicit val app: AkkaApplication) extends RequestMethod +abstract class Post(val builder: () ⇒ tAsyncRequestContext)(implicit val app: AkkaApplication) extends RequestMethod +abstract class Put(val builder: () ⇒ tAsyncRequestContext)(implicit val app: AkkaApplication) extends RequestMethod +abstract class Trace(val builder: () ⇒ tAsyncRequestContext)(implicit val app: AkkaApplication) extends RequestMethod trait RequestMethodFactory { def Delete(f: () ⇒ tAsyncRequestContext): RequestMethod diff --git a/akka-http/src/main/scala/akka/http/Servlet30Context.scala b/akka-http/src/main/scala/akka/http/Servlet30Context.scala index 8f3c191d32..fd797b8a5c 100644 --- a/akka-http/src/main/scala/akka/http/Servlet30Context.scala +++ b/akka-http/src/main/scala/akka/http/Servlet30Context.scala @@ -6,7 +6,6 @@ package akka.http import javax.servlet.{ AsyncContext, AsyncListener, AsyncEvent } import Types._ -import akka.event.EventHandler import akka.AkkaApplication /** @@ -15,7 +14,7 @@ import akka.AkkaApplication trait Servlet30Context extends AsyncListener { import javax.servlet.http.HttpServletResponse - protected def application: AkkaApplication + def app: AkkaApplication val builder: () ⇒ tAsyncRequestContext val context: Option[tAsyncRequestContext] = Some(builder()) @@ -23,7 +22,7 @@ trait Servlet30Context extends AsyncListener { protected val _ac: AsyncContext = { val ac = context.get.asInstanceOf[AsyncContext] - ac setTimeout application.MistSettings.DefaultTimeout + ac setTimeout app.MistSettings.DefaultTimeout ac addListener this ac } @@ -36,7 +35,7 @@ trait Servlet30Context extends AsyncListener { true } catch { case e: IllegalStateException ⇒ - EventHandler.error(e, this, e.getMessage) + app.eventHandler.error(e, this, e.getMessage) false } } @@ -47,25 +46,23 @@ trait Servlet30Context extends AsyncListener { def onComplete(e: AsyncEvent) {} def onError(e: AsyncEvent) = e.getThrowable match { case null ⇒ - case t ⇒ EventHandler.error(t, this, t.getMessage) + case t ⇒ app.eventHandler.error(t, this, t.getMessage) } def onStartAsync(e: AsyncEvent) {} def onTimeout(e: AsyncEvent) = { - e.getSuppliedResponse.asInstanceOf[HttpServletResponse].addHeader(application.MistSettings.ExpiredHeaderName, application.MistSettings.ExpiredHeaderValue) + e.getSuppliedResponse.asInstanceOf[HttpServletResponse].addHeader(app.MistSettings.ExpiredHeaderName, app.MistSettings.ExpiredHeaderValue) e.getAsyncContext.complete } } -class Servlet30ContextMethodFactory(val _application: AkkaApplication) extends RequestMethodFactory { - trait App { - def application = _application - } - def Delete(f: () ⇒ tAsyncRequestContext): RequestMethod = new Delete(f) with Servlet30Context with App - def Get(f: () ⇒ tAsyncRequestContext): RequestMethod = new Get(f) with Servlet30Context with App - def Head(f: () ⇒ tAsyncRequestContext): RequestMethod = new Head(f) with Servlet30Context with App - def Options(f: () ⇒ tAsyncRequestContext): RequestMethod = new Options(f) with Servlet30Context with App - def Post(f: () ⇒ tAsyncRequestContext): RequestMethod = new Post(f) with Servlet30Context with App - def Put(f: () ⇒ tAsyncRequestContext): RequestMethod = new Put(f) with Servlet30Context with App - def Trace(f: () ⇒ tAsyncRequestContext): RequestMethod = new Trace(f) with Servlet30Context with App +class Servlet30ContextMethodFactory(_app: AkkaApplication) extends RequestMethodFactory { + implicit val app = _app + 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 } From ee57ef564c886978ca685af270e6bdcc958b8de8 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 13 Oct 2011 13:53:09 +0200 Subject: [PATCH 5/5] fix akka-docs compilation, remove duplicate applications from STM tests --- akka-http/src/main/scala/akka/http/JettyContinuation.scala | 2 +- akka-http/src/main/scala/akka/http/Mist.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/akka-http/src/main/scala/akka/http/JettyContinuation.scala b/akka-http/src/main/scala/akka/http/JettyContinuation.scala index 8fcd6b21a9..6d03d24636 100644 --- a/akka-http/src/main/scala/akka/http/JettyContinuation.scala +++ b/akka-http/src/main/scala/akka/http/JettyContinuation.scala @@ -16,7 +16,7 @@ import akka.AkkaApplication */ trait JettyContinuation extends ContinuationListener { import javax.servlet.http.HttpServletResponse - + def app: AkkaApplication val builder: () ⇒ tAsyncRequestContext diff --git a/akka-http/src/main/scala/akka/http/Mist.scala b/akka-http/src/main/scala/akka/http/Mist.scala index 6d530ad0f3..06eafdf650 100644 --- a/akka-http/src/main/scala/akka/http/Mist.scala +++ b/akka-http/src/main/scala/akka/http/Mist.scala @@ -294,7 +294,7 @@ class RootEndpoint extends Actor with Endpoint { trait RequestMethod { import java.io.IOException import javax.servlet.http.{ HttpServletResponse, HttpServletRequest } - + def app: AkkaApplication // required implementations