Permalink
Browse files

merge 2.2.x_2.10

  • Loading branch information...
2 parents 9d76540 + 57db379 commit 7e6aea6fd56f1d10ea4df1755138cd19f06666c9 @casualjim casualjim committed Apr 6, 2013
Showing with 634 additions and 408 deletions.
  1. +1 −2 atmosphere/src/main/scala/org/atmosphere/cpr/ScalatraBroadcasterFactory.scala
  2. +144 −143 atmosphere/src/test/scala/org/scalatra/atmosphere/AtmosphereSpec.scala
  3. +2 −1 commands/src/main/scala/org/scalatra/commands/CommandHandler.scala
  4. +2 −4 commands/src/main/scala/org/scalatra/commands/binding.scala
  5. +7 −4 commands/src/main/scala/org/scalatra/commands/executors.scala
  6. +2 −1 commands/src/main/scala/org/scalatra/commands/field.scala
  7. +2 −2 commands/src/main/scala/org/scalatra/commands/package.scala
  8. +19 −0 commands/src/test/scala/org/scalatra/validation/ValidationSerializerSpec.scala
  9. +2 −2 core/src/main/scala/org/scalatra/ScalatraBase.scala
  10. +17 −12 core/src/main/scala/org/scalatra/ScalatraServlet.scala
  11. +2 −1 notes/2.2.1.markdown
  12. +29 −52 project/build.scala
  13. +6 −0 publishing.sbt
  14. +3 −2 specs2/src/main/scala/org/scalatra/test/specs2/BaseScalatraSpec.scala
  15. +2 −2 specs2/src/main/scala/org/scalatra/test/specs2/MutableScalatraSpec.scala
  16. +2 −2 specs2/src/main/scala/org/scalatra/test/specs2/ScalatraSpec.scala
  17. +1 −1 specs2/src/test/scala/org/scalatra/test/specs2/ScalatraSpecSpec.scala
  18. +2 −2 swagger/src/main/scala/org/scalatra/swagger/Swagger.scala
  19. +3 −1 swagger/src/main/scala/org/scalatra/swagger/reflect/ManifestFactory.scala
  20. +126 −121 swagger/src/main/scala/org/scalatra/swagger/reflect/Reflector.scala
  21. +121 −34 swagger/src/main/scala/org/scalatra/swagger/reflect/ScalaSigReader.scala
  22. +122 −13 swagger/src/main/scala/org/scalatra/swagger/reflect/descriptors.scala
  23. +15 −3 swagger/src/main/scala/org/scalatra/swagger/reflect/package.scala
  24. +1 −0 test/src/main/scala/org/scalatra/test/EmbeddedJettyContainer.scala
  25. +1 −3 version.sbt
@@ -15,8 +15,7 @@ object ScalatraBroadcasterFactory {
}
class ScalatraBroadcasterFactory(cfg: AtmosphereConfig)(implicit wireFormat: WireFormat, system: ActorSystem) extends BroadcasterFactory {
- BroadcasterFactory.config = cfg
- if (BroadcasterFactory.factory == null) BroadcasterFactory.factory = this
+ BroadcasterFactory.setBroadcasterFactory(this, cfg)
private[this] val logger = Logger[ScalatraBroadcasterFactory]
private[this] val store: ConcurrentMap[Any, Broadcaster] = new ConcurrentHashMap[Any, Broadcaster]().asScala
@@ -1,153 +1,154 @@
-package org.scalatra
-package atmosphere
-import test.specs2.MutableScalatraSpec
-import json.JacksonJsonSupport
-import org.json4s._
-import JsonDSL._
-import org.atmosphere.wasync._
-import java.io.{IOException, StringReader, Reader}
-import java.util.concurrent.{TimeUnit, CountDownLatch}
-import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
-import _root_.akka.actor.ActorSystem
-import org.specs2.specification.{Step, Fragments}
-import scala.concurrent.duration._
-import org.specs2.time.NoTimeConversions
-
-
-class AtmosphereSpecServlet(implicit override protected val scalatraActorSystem: ActorSystem) extends ScalatraServlet with JacksonJsonSupport with AtmosphereSupport {
- implicit protected def jsonFormats: Formats = DefaultFormats
- import scala.concurrent.ExecutionContext.Implicits.global
-
- get("/echo") {
- "echo ok"
- }
-
-
- atmosphere("/test1") {
- new AtmosphereClient {
- def receive: AtmoReceive = {
- case Connected =>
- println("connected client")
- broadcast("connected", to = Everyone)
- case TextMessage(txt) =>
- println("text message: " + txt)
- send(("seen" -> txt):JValue)
- case JsonMessage(json) =>
- println("json message: " + json)
- send(("seen" -> "test1") ~ ("data" -> json))
- case m =>
- println("Got unknown message " + m.getClass + " " + m.toString)
- }
- }
- }
-
- error {
- case t: Throwable => t.printStackTrace()
- }
-
- override def handle(request: HttpServletRequest, response: HttpServletResponse) {
- withRequestResponse(request, response) {
- println(request.headers)
- println("routeBasePath: " + routeBasePath(request))
- println("requestPath: " + requestPath(request))
-
- super.handle(request, response)
- }
- }
-}
-
-object WaSync {
-
- val Get = Request.METHOD.GET
- val Post = Request.METHOD.POST
- val Trace = Request.METHOD.TRACE
- val Put = Request.METHOD.PUT
- val Delete = Request.METHOD.DELETE
- val Options = Request.METHOD.OPTIONS
-
- val WebSocket = Request.TRANSPORT.WEBSOCKET
- val Sse = Request.TRANSPORT.SSE
- val Streaming = Request.TRANSPORT.STREAMING
- val LongPolling = Request.TRANSPORT.LONG_POLLING
-
- type ErrorHandler = PartialFunction[Throwable, Unit]
-
- def printIOException: ErrorHandler = {
- case e: IOException => e.printStackTrace()
- }
-
- implicit def scalaFunction2atmoFunction[T](fn: T => Unit) = new Function[T] { def on(t: T) { fn(t) } }
- implicit def scalaFunction2atmoEncoder[T, S](fn: T => S) = new Encoder[T, S] { def encode(s: T): S = fn(s) }
- implicit def scalaFunction2atmoDecoder[T, S](fn: T => S) = new Decoder[T, S] { def decode(s: T): S = fn(s) }
- implicit def errorHandler2atmoFunction(fn: PartialFunction[Throwable, Unit]) = new Function[Throwable] {
- def on(t: Throwable) {
- if (fn.isDefinedAt(t)) fn(t)
- else throw t
- }
- }
-
-}
-
-class AtmosphereSpec extends MutableScalatraSpec with NoTimeConversions {
-
- import WaSync._
- implicit val system = ActorSystem("scalatra")
-
- mount(new AtmosphereSpecServlet, "/*")
-
-
- implicit val formats = DefaultFormats
-
- private val stringEncoder = (s: String) => s
- private val stringDecoder = (s: String) => s
-
- sequential
-
- "To support Atmosphere, Scalatra" should {
-
- "allow regular requests" in {
- get("/echo") {
- status must_== 200
- body must_== "echo ok"
- }
- }
-
- "allow one client to connect" in {
+//package org.scalatra
+//package atmosphere
+//
+//import test.specs2.MutableScalatraSpec
+//import json.JacksonJsonSupport
+//import org.json4s._
+//import JsonDSL._
+//import org.atmosphere.wasync._
+//import java.io.{IOException, StringReader, Reader}
+//import java.util.concurrent.{TimeUnit, CountDownLatch}
+//import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
+//import _root_.akka.actor.ActorSystem
+//import org.specs2.specification.{Step, Fragments}
+//import _root_.akka.util.duration._
+//import org.specs2.time.NoTimeConversions
+//import org.atmosphere.wasync.Transport.EVENT_TYPE
+//import scala.annotation.switch
+//
+//class AtmosphereSpecServlet(implicit override protected val scalatraActorSystem: ActorSystem) extends ScalatraServlet with JacksonJsonSupport with AtmosphereSupport {
+// implicit protected def jsonFormats: Formats = DefaultFormats
+//
+// get("/echo") {
+// "echo ok"
+// }
+//
+//
+// atmosphere("/test1") {
+// new AtmosphereClient {
+// def receive: AtmoReceive = {
+// case Connected =>
+// println("connected client")
+// broadcast("connected", to = Everyone)
+// case TextMessage(txt) =>
+// println("text message: " + txt)
+// send(("seen" -> txt):JValue)
+// case JsonMessage(json) =>
+// println("json message: " + json)
+// send(("seen" -> "test1") ~ ("data" -> json))
+// case m =>
+// println("Got unknown message " + m.getClass + " " + m.toString)
+// }
+// }
+// }
+//
+// error {
+// case t: Throwable => t.printStackTrace()
+// }
+//
+// override def handle(request: HttpServletRequest, response: HttpServletResponse) {
+// withRequestResponse(request, response) {
+// println(request.headers)
+// println("routeBasePath: " + routeBasePath(request))
+// println("requestPath: " + requestPath(request))
+//
+// super.handle(request, response)
+// }
+// }
+//}
+//
+//object WaSync {
+//
+// val Get = Request.METHOD.GET
+// val Post = Request.METHOD.POST
+// val Trace = Request.METHOD.TRACE
+// val Put = Request.METHOD.PUT
+// val Delete = Request.METHOD.DELETE
+// val Options = Request.METHOD.OPTIONS
+//
+// val WebSocket = Request.TRANSPORT.WEBSOCKET
+// val Sse = Request.TRANSPORT.SSE
+// val Streaming = Request.TRANSPORT.STREAMING
+// val LongPolling = Request.TRANSPORT.LONG_POLLING
+//
+// type ErrorHandler = PartialFunction[Throwable, Unit]
+//
+// def printIOException: ErrorHandler = {
+// case e: IOException => e.printStackTrace()
+// }
+//
+// implicit def scalaFunction2atmoFunction[T](fn: T => Unit): Function[T] = new Function[T] { def on(t: T) { fn(t) } }
+// implicit def scalaFunction2atmoEncoder[T, S](fn: T => S): Encoder[T, S] = new Encoder[T, S] { def encode(s: T): S = fn(s) }
+//
+//
+// implicit def scalaFunction2atmoDecoder[T <: AnyRef, S](fn: T => S): Decoder[T, S] = new Decoder[T, S] {
+// def decode(e: EVENT_TYPE, s: T): S = fn(s)
+// }
+// implicit def errorHandler2atmoFunction(fn: PartialFunction[Throwable, Unit]): Function[Throwable] = new Function[Throwable] {
+// def on(t: Throwable) {
+// if (fn.isDefinedAt(t)) fn(t)
+// else throw t
+// }
+// }
+//
+//}
+//
+//class AtmosphereSpec extends MutableScalatraSpec with NoTimeConversions {
+//
+// import WaSync._
+// implicit val system = ActorSystem("scalatra")
+//
+// mount(new AtmosphereSpecServlet, "/*")
+//
+//
+// implicit val formats = DefaultFormats
+//
+// private val stringEncoder: Encoder[String, String] = (s: String) => s
+// private val stringDecoder: Decoder[String, String] = (s: String) => s
+//
+// sequential
+//
+// "To support Atmosphere, Scalatra" should {
+//
+// "allow regular requests" in {
+// get("/echo") {
+// status must_== 200
+// body must_== "echo ok"
+// }
+// }
+//
+// "allow one client to connect" in {
// val latch = new CountDownLatch(2)
// val client = ClientFactory.getDefault.newClient()
-// val req = (client.newRequestBuilder()
-// method Get
-// uri (baseUrl + "/test1")
-//
-// transport LongPolling)
+// val req = (client.newRequestBuilder().transport(LongPolling).method(Get).uri(baseUrl + "/test1"))
// val opts = new org.atmosphere.wasync.Options.OptionsBuilder().reconnect(false).build()
// val conn = client.create(opts)
// conn.on(new Function[AnyRef] {
// def on(t: AnyRef) {
// println("Got Anyref " + t)
// }
// })
-// (conn
-// on { (s: String) =>
-// println("Got String: " + s)
-// latch.countDown()
-// }
-//// on printIOException
-// open req.build()
-// fire "hello"
-// fire """{"id":1}"""
-// done())
-//
-// latch.await(5, TimeUnit.SECONDS) must beTrue
-
- pending
- }
- }
- private def stopSystem {
- system.shutdown()
- system.awaitTermination(1 minutes)
- }
-
- override def map(fs: => Fragments): Fragments = super.map(fs) ^ Step(stopSystem)
-}
+//// (conn
+//// on { (s: String) =>
+//// println("Got String: " + s)
+//// latch.countDown()
+//// }
+////// on printIOException
+//// open req.build()
+//// fire "hello"
+//// fire """{"id":1}"""
+//// done())
+////
+//// latch.await(5, TimeUnit.SECONDS) must beTrue
+//
+// pending
+// }
+// }
+// private def stopSystem {
+// system.shutdown()
+// system.awaitTermination(1 minutes)
+// }
+//
+// override def map(fs: => Fragments): Fragments = super.map(fs) ^ Step(stopSystem)
+//}
@@ -5,7 +5,8 @@ import scala.util.control.Exception.allCatch
import grizzled.slf4j.Logger
import validation._
import scalaz._
-import Scalaz._
+import syntax.std.option._
+import syntax.validation._
@deprecated("This approach is not fully type-safe. The compiler can't enforce that the handle method returns a `S`. Please use the `>>` or `apply` method on a command.", "2.2.1")
trait CommandHandler {
@@ -5,10 +5,8 @@ import org.scalatra.util.conversion._
import validation._
import java.util.Date
import scalaz._
-import Scalaz._
+import syntax.std.option._
import org.joda.time.DateTime
-import java.util.concurrent.atomic.AtomicReference
-import scala.util.matching.Regex
class BindingException(message: String) extends ScalatraException(message)
@@ -58,7 +56,7 @@ object Binding {
type S = I
override def toString() = {
- "Binding[%s, %s](name: %s, original: %s, value: %s)".format(sourceManifest.erasure.getSimpleName, valueManifest.erasure.getSimpleName, name, validation, original)
+ "Binding[%s, %s](name: %s, value: %s, original: %s)".format(sourceManifest.erasure.getSimpleName, valueManifest.erasure.getSimpleName, name, validation, original)
}
def transform(transformer: (T) => T): Binding =
@@ -1,7 +1,7 @@
package org.scalatra.commands
import scalaz._
-import Scalaz._
+import syntax.validation._
import org.scalatra.validation._
import grizzled.slf4j.Logger
import mojolly.inflector.InflectorImports._
@@ -55,8 +55,9 @@ abstract class BlockingExecutor[T <: Command, S](handle: T => ModelValidation[S]
res match {
case Succ(r)
+ def plur(count: Int) = if (count == 1) "failure" else "failures"
val resultLog = r.fold(
- { failures s"with ${failures.tail.size + 1} failures\n${failures.list}" },
+ { failures s"with ${failures.tail.size + 1} ${failures.list.size}\n${failures.list}" },
{ _ "successfully" })
logger.debug(s"Command [${cmd.getClass.getName}] executed $resultLog")
r
@@ -109,8 +110,9 @@ abstract class AsyncExecutor[T <: Command, S](handle: T => Future[ModelValidatio
res onSuccess {
case r
+ def plur(count: Int) = if (count == 1) "failure" else "failures"
val resultLog = r.fold(
- { failures s"with ${failures.list.size} ${"failure".plural(failures.list.size)}.\n${failures.list}" },
+ { failures s"with ${failures.list.size} ${plur(failures.list.size)}.\n${failures.list}" },
{ _ "successfully" })
logger.debug(s"Command [${cmd.getClass.getName}] executed $resultLog")
}
@@ -124,7 +126,8 @@ abstract class AsyncExecutor[T <: Command, S](handle: T => Future[ModelValidatio
val f = cmd.errors.map(_.validation) collect {
case Failure(e) e
}
- logger.debug(s"Command [${cmd.getClass.getName}] executed with ${f.size} ${"failure".plural(f.size)}.\n${f.toList}")
+ def failures = if (f.size == 1) "failure" else "failures"
+ logger.debug(s"Command [${cmd.getClass.getName}] executed with ${f.size} ${failures}.\n${f.toList}")
Future.successful(NonEmptyList(f.head, f.tail: _*).fail)
}
}
@@ -4,7 +4,8 @@ package commands
import validation._
import util.conversion._
import scalaz._
-import Scalaz._
+import syntax.validation._
+import syntax.std.option._
import mojolly.inflector.InflectorImports._
import org.scalatra.util.RicherString._
Oops, something went wrong.

0 comments on commit 7e6aea6

Please sign in to comment.