Skip to content
Browse files

replace uses of scalatrabase with scalatra syntax

  • Loading branch information...
1 parent 16f9b98 commit 849110446fbf1023e729198d4cbbdedb951f99c3 @casualjim casualjim committed
Showing with 74 additions and 127 deletions.
  1. +4 −4 auth/src/main/scala/org/scalatra/auth/Scentry.scala
  2. +1 −1 auth/src/main/scala/org/scalatra/auth/ScentryAuthStore.scala
  3. +2 −2 auth/src/main/scala/org/scalatra/auth/ScentryStrategy.scala
  4. +2 −2 auth/src/main/scala/org/scalatra/auth/ScentrySupport.scala
  5. +2 −2 auth/src/main/scala/org/scalatra/auth/strategy/BasicAuthStrategy.scala
  6. +1 −1 auth/src/test/scala/org/scalatra/auth/ScentrySpec.scala
  7. +2 −2 commands/src/main/scala/org/scalatra/commands/CommandSupport.scala
  8. +1 −12 commands/src/main/scala/org/scalatra/commands/binding.scala
  9. +0 −6 commands/src/main/scala/org/scalatra/commands/json_commands.scala
  10. +1 −1 core/src/main/scala/org/scalatra/ApiFormats.scala
  11. +1 −1 core/src/main/scala/org/scalatra/CORSSupport.scala
  12. +1 −1 core/src/main/scala/org/scalatra/CookieSupport.scala
  13. +1 −1 core/src/main/scala/org/scalatra/CoreDsl.scala
  14. +2 −2 core/src/main/scala/org/scalatra/CsrfTokenSupport.scala
  15. +1 −1 core/src/main/scala/org/scalatra/GZipSupport.scala
  16. +1 −1 core/src/main/scala/org/scalatra/ScalatraBase.scala
  17. +1 −1 core/src/main/scala/org/scalatra/TypedParamSupport.scala
  18. +1 −1 core/src/main/scala/org/scalatra/UrlSupport.scala
  19. +1 −1 core/src/main/scala/org/scalatra/i18n/I18nSupport.scala
  20. +1 −1 core/src/main/scala/org/scalatra/package.scala
  21. +1 −1 core/src/main/scala/org/scalatra/servlet/AsyncSupport.scala
  22. +10 −41 core/src/main/scala/org/scalatra/util/conversion/conversions.scala
  23. +14 −4 core/src/test/scala/org/scalatra/GZipSupportTest.scala
  24. +3 −1 core/src/test/scala/org/scalatra/util/conversion/ConversionsSpecs.scala
  25. +2 −2 example/src/main/scala/org/scalatra/BasicAuthExample.scala
  26. +1 −1 json/src/main/scala/org/scalatra/json/JValueResult.scala
  27. +3 −20 json/src/main/scala/org/scalatra/json/JsonImplicitConversions.scala
  28. +1 −1 scalate/src/main/scala/org/scalatra/scalate/ScalateRenderSupport.scala
  29. +2 −2 slf4j/src/main/scala/org/scalatra/slf4j/ScalatraSlf4jRequestLogging.scala
  30. +2 −2 swagger-ext/src/main/scala/org/scalatra/swagger/SwaggerAuth.scala
  31. +1 −1 swagger-ext/src/main/scala/org/scalatra/swagger/SwaggerCommand.scala
  32. +1 −1 swagger-ext/src/test/scala/org/scalatra/swagger/SwaggerAuthSpec.scala
  33. +1 −1 swagger/src/main/scala/org/scalatra/swagger/JacksonSwaggerBase.scala
  34. +1 −1 swagger/src/main/scala/org/scalatra/swagger/NativeSwaggerBase.scala
  35. +2 −2 swagger/src/main/scala/org/scalatra/swagger/SwaggerBase.scala
  36. +2 −2 swagger/src/main/scala/org/scalatra/swagger/SwaggerSupport.scala
View
8 auth/src/main/scala/org/scalatra/auth/Scentry.scala
@@ -8,7 +8,7 @@ import org.scalatra.util.RicherString._
object Scentry {
- type StrategyFactory[UserType <: AnyRef] = ScalatraBase ScentryStrategy[UserType]
+ type StrategyFactory[UserType <: AnyRef] = ScalatraSyntax ScentryStrategy[UserType]
private val _globalStrategies = new mutable.HashMap[String, StrategyFactory[_ <: AnyRef]]()
@@ -29,14 +29,14 @@ object Scentry {
}
class Scentry[UserType <: AnyRef](
- app: ScalatraBase,
+ app: ScalatraSyntax,
serialize: PartialFunction[UserType, String],
deserialize: PartialFunction[String, UserType],
private[this] var _store: ScentryAuthStore) {
private[this] lazy val logger = Logger(getClass)
type StrategyType = ScentryStrategy[UserType]
- type StrategyFactory = ScalatraBase StrategyType
+ type StrategyFactory = ScalatraSyntax StrategyType
import Scentry._
@@ -57,7 +57,7 @@ class Scentry[UserType <: AnyRef](
def redirect(uri: String) { app.redirect(uri) }
def register(strategy: => ScentryStrategy[UserType]) {
- register(strategy.name, ((_: ScalatraBase) => strategy))
+ register(strategy.name, ((_: ScalatraSyntax) => strategy))
}
def register(name: String, strategyFactory: StrategyFactory) {
View
2 auth/src/main/scala/org/scalatra/auth/ScentryAuthStore.scala
@@ -15,7 +15,7 @@ object ScentryAuthStore {
def invalidate()
}
- class CookieAuthStore(app: ScalatraBase with CookieSupport)(implicit cookieOptions: CookieOptions = CookieOptions(path = "/")) extends ScentryAuthStore {
+ class CookieAuthStore(app: ScalatraSyntax with CookieSupport)(implicit cookieOptions: CookieOptions = CookieOptions(path = "/")) extends ScentryAuthStore {
def get = app.cookies.get(Scentry.scentryAuthKey) getOrElse ""
View
4 auth/src/main/scala/org/scalatra/auth/ScentryStrategy.scala
@@ -7,7 +7,7 @@ import javax.servlet.http.{HttpSession, HttpServletRequest, Cookie}
trait ScentryStrategy[UserType <: AnyRef] {
- protected def app: ScalatraBase
+ protected def app: ScalatraSyntax
def name: String = "NameMe"
def registerWith(registrar: Scentry[UserType]) {
@@ -15,7 +15,7 @@ trait ScentryStrategy[UserType <: AnyRef] {
else registrar.register(name, createStrategy _)
}
- def createStrategy(app: ScalatraBase): this.type = {
+ def createStrategy(app: ScalatraSyntax): this.type = {
throwOverrideException
}
View
4 auth/src/main/scala/org/scalatra/auth/ScentrySupport.scala
@@ -12,7 +12,7 @@ trait ScentryConfig {
}
trait ScentrySupport[UserType <: AnyRef] extends Handler with Initializable with CookieSupport {
- self: ScalatraBase
+ self: ScalatraSyntax
type ScentryConfiguration <: ScentryConfig
@@ -39,7 +39,7 @@ trait ScentrySupport[UserType <: AnyRef] extends Handler with Initializable with
private def initializeScentry = {
val store = self match {
case a: SessionSupport => new ScentryAuthStore.SessionAuthStore(a.session)
- case a: ScalatraBase with CookieSupport => new ScentryAuthStore.CookieAuthStore(a)
+ case a: ScalatraSyntax with CookieSupport => new ScentryAuthStore.CookieAuthStore(a)
case _ => throw new ScalatraException("Scentry needs either SessionSupport or CookieSupport mixed in.")
}
request.setAttribute(Scentry.ScentryRequestKey, new Scentry[UserType](self, toSession, fromSession, store))
View
4 auth/src/main/scala/org/scalatra/auth/strategy/BasicAuthStrategy.scala
@@ -24,7 +24,7 @@ trait RemoteAddress { self: ScentryStrategy[_] =>
* for more details on usage check:
* https://gist.github.com/732347
*/
-trait BasicAuthSupport[UserType <: AnyRef] { self: (ScalatraBase with ScentrySupport[UserType]) =>
+trait BasicAuthSupport[UserType <: AnyRef] { self: (ScalatraSyntax with ScentrySupport[UserType]) =>
def realm: String
@@ -71,7 +71,7 @@ object BasicAuthStrategy {
def password = credentials map { _._2 } getOrElse null
}
}
-abstract class BasicAuthStrategy[UserType <: AnyRef](protected val app: ScalatraBase, realm: String)
+abstract class BasicAuthStrategy[UserType <: AnyRef](protected val app: ScalatraSyntax, realm: String)
extends ScentryStrategy[UserType]
with RemoteAddress {
View
2 auth/src/test/scala/org/scalatra/auth/ScentrySpec.scala
@@ -79,7 +79,7 @@ object ScentrySpec extends Specification with Mockito {
override def unauthenticated() { unauthenticatedCalled = true }
}
"allow registration of global strategies" in {
- Scentry.register("Bogus", (_: ScalatraBase) => s)
+ Scentry.register("Bogus", (_: ScalatraSyntax) => s)
Scentry.globalStrategies("Bogus").asInstanceOf[Scentry[User]#StrategyFactory](context) must be_==(s)
}
View
4 commands/src/main/scala/org/scalatra/commands/CommandSupport.scala
@@ -14,7 +14,7 @@ import grizzled.slf4j.Logger
/**
* Support for [[org.scalatra.commands.Command]] binding and validation.
*/
-trait CommandSupport extends ParamsValueReaderProperties { this: ScalatraBase =>
+trait CommandSupport extends ParamsValueReaderProperties { this: ScalatraSyntax =>
type CommandType <: Command
@@ -70,6 +70,6 @@ trait CommandSupport extends ParamsValueReaderProperties { this: ScalatraBase =>
}
-trait ParamsOnlyCommandSupport extends CommandSupport { this: ScalatraBase =>
+trait ParamsOnlyCommandSupport extends CommandSupport { this: ScalatraSyntax =>
type CommandType = ParamsOnlyCommand
}
View
13 commands/src/main/scala/org/scalatra/commands/binding.scala
@@ -34,7 +34,7 @@ object Binding {
type S = Nothing
implicit def sourceManifest: Manifest[S] = null
implicit def sourceZero: DefaultValue[S] = null
- implicit def typeConverter: (S) => Option[T] = null
+ implicit def typeConverter: TypeConverter[S, T] = null
def apply(toBind: Either[String, Option[S]]): Binding = null
def validateWith(validators:BindingValidator[T]*): Binding =
@@ -173,17 +173,6 @@ trait BindingImplicits extends DefaultImplicitConversions with BindingValidatorI
implicit def stringToSeqDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[String, Seq[Date]] =
stringToSeq(stringToDate)
- implicit def stringSeqToHeadDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[Seq[String], Date] =
- seqHead(stringToDate)
-
- implicit def stringSeqToHeadDateTime(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[Seq[String], DateTime] =
- seqHead(stringToDateTime)
-
- implicit def stringSeqToSeqDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[Seq[String], Seq[Date]] =
- seqToSeq(stringToDate)
-
- implicit def stringSeqToSeqDateTime(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[Seq[String], Seq[DateTime]] =
- seqToSeq(stringToDateTime)
}
object BindingImplicits extends BindingImplicits
View
6 commands/src/main/scala/org/scalatra/commands/json_commands.scala
@@ -18,12 +18,6 @@ trait JsonBindingImplicits extends BindingImplicits with JsonImplicitConversions
implicit def jsonToDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[JValue, Date] =
safeOption(_.extractOpt[String].flatMap(df.parse).map(_.toDate))
- implicit def jsonToSeqDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[JValue, Seq[Date]] =
- jsonToSeq(jsonToDate)
-
- implicit def jsonToSeqDateTime(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[JValue, Seq[DateTime]] =
- jsonToSeq(jsonToDateTime)
-
}
trait JsonTypeConverterFactory[T] extends TypeConverterFactory[T] with JsonBindingImplicits {
View
2 core/src/main/scala/org/scalatra/ApiFormats.scala
@@ -22,7 +22,7 @@ object ApiFormats {
* $ - Maps formats to content types and vice versa
* $ - Augments the content-type inferrer to use the format
*/
-trait ApiFormats extends ScalatraBase {
+trait ApiFormats extends ScalatraSyntax {
/**
* A map of suffixes to content types.
*/
View
2 core/src/main/scala/org/scalatra/CORSSupport.scala
@@ -61,7 +61,7 @@ object CorsSupport {
"Content-Type").mkString(",")
}
-trait CorsSupport extends Handler with Initializable { self: ScalatraBase
+trait CorsSupport extends Handler with Initializable { self: ScalatraSyntax
import CorsSupport._
View
2 core/src/main/scala/org/scalatra/CookieSupport.scala
@@ -115,7 +115,7 @@ object CookieSupport {
val CookieOptionsKey = "org.scalatra.CookieOptions"
}
trait CookieSupport extends Handler with Initializable {
- self: ScalatraBase =>
+ self: ScalatraSyntax =>
import CookieSupport._
implicit def cookieOptions: CookieOptions = servletContext.get(CookieOptionsKey).orNull.asInstanceOf[CookieOptions]
View
2 core/src/main/scala/org/scalatra/CoreDsl.scala
@@ -117,7 +117,7 @@ trait CoreDsl extends Handler with Control with ServletApiImplicits {
* and a block as the action body. The return value of the block is
* rendered through the pipeline and sent to the client as the response body.
*
- * See [[org.scalatra.ScalatraBase#renderResponseBody]] for the detailed
+ * See [[org.scalatra.ScalatraSyntax#renderResponseBody]] for the detailed
* behaviour and how to handle your response body more explicitly, and see
* how different return types are handled.
*
View
4 core/src/main/scala/org/scalatra/CsrfTokenSupport.scala
@@ -36,7 +36,7 @@ object CsrfTokenSupport {
* request is prepared with `prepareCsrfToken`.
*/
trait CsrfTokenSupport {
- this: ScalatraBase with SessionSupport =>
+ this: ScalatraSyntax with SessionSupport =>
/**
* The key used to store the token on the session, as well as the parameter
@@ -85,7 +85,7 @@ trait CsrfTokenSupport {
protected def prepareCSRFToken() = prepareCsrfToken()
}
-trait XsrfTokenSupport { this: ScalatraBase with SessionSupport with CookieSupport =>
+trait XsrfTokenSupport { this: ScalatraSyntax with SessionSupport with CookieSupport =>
import XsrfTokenSupport._
/**
View
2 core/src/main/scala/org/scalatra/GZipSupport.scala
@@ -12,7 +12,7 @@ import javax.servlet.http.HttpServletResponseWrapper
* Scalatra handler for gzipped responses.
*/
trait GZipSupport extends Handler with Initializable {
- self: ScalatraBase =>
+ self: ScalatraSyntax =>
abstract override def handle(req: HttpServletRequest, res: HttpServletResponse) {
View
2 core/src/main/scala/org/scalatra/ScalatraBase.scala
@@ -31,7 +31,7 @@ object ScalatraBase {
val ForceHttpsKey = "org.scalatra.ForceHttps"
import collection.JavaConverters._
- def getServletRegistration(app: ScalatraBase) = {
+ def getServletRegistration(app: ScalatraSyntax) = {
val registrations = app.servletContext.getServletRegistrations.values().asScala.toList
registrations.find(_.getClassName == app.getClass.getName)
}
View
2 core/src/main/scala/org/scalatra/TypedParamSupport.scala
@@ -1,4 +1,4 @@
package org.scalatra
@deprecated("This got folded into core, so you can remove the TypeParamSupport trait safely.", "2.2")
-trait TypedParamSupport extends ScalatraBase
+trait TypedParamSupport extends ScalatraSyntax
View
2 core/src/main/scala/org/scalatra/UrlSupport.scala
@@ -4,5 +4,5 @@ package org.scalatra
* Provides utility methods for the creation of URL strings.
* Supports context-relative and session-aware URLs. Should behave similarly to JSTL's <c:url> tag.
*/
-@deprecated("This functionality has been subsumed by ScalatraBase.", "2.1.0") // Since 2.1
+@deprecated("This functionality has been subsumed by ScalatraSyntax.", "2.1.0") // Since 2.1
trait UrlSupport
View
2 core/src/main/scala/org/scalatra/i18n/I18nSupport.scala
@@ -13,7 +13,7 @@ object I18nSupport {
trait I18nSupport {
- this: ScalatraBase with CookieSupport =>
+ this: ScalatraSyntax with CookieSupport =>
import I18nSupport._
View
2 core/src/main/scala/org/scalatra/package.scala
@@ -22,7 +22,7 @@ package object scalatra
val MultiParamsKey = "org.scalatra.MultiParams"
- @deprecated("Use org.scalatra.servlet.ServletBase if you depend on the Servlet API, or org.scalatra.ScalatraBase if you don't.", "2.1.0")
+ @deprecated("Use org.scalatra.servlet.ServletBase if you depend on the Servlet API, or org.scalatra.ScalatraSyntax if you don't.", "2.1.0")
type ScalatraKernel = servlet.ServletBase
// class OptionDefaults[T](value: Option[T]) {
View
2 core/src/main/scala/org/scalatra/servlet/AsyncSupport.scala
@@ -36,7 +36,7 @@ trait AsyncSupport extends ServletBase {
* The block of these methods is executed in a lightweight event-driven thread
* from Akka's dispatchers
*
- * See [[org.scalatra.ScalatraBase#renderResponseBody]] for the detailed
+ * See [[org.scalatra.ScalatraSyntax#renderResponseBody]] for the detailed
* behaviour and how to handle your response body more explicitly, and see
* how different return types are handled.
*
View
51 core/src/main/scala/org/scalatra/util/conversion/conversions.scala
@@ -8,15 +8,19 @@ import scala.util.control.Exception.allCatch
import scala._
/**
- * Support types and implicits for [[org.scalatra.common.conversions.TypeConverter]].
+ * Support types and implicits for [[org.scalatra.util.conversion.TypeConverter]].
*/
trait TypeConverterSupport {
- implicit def safe[S, T](f: S => T): TypeConverter[S, T] = (s) => allCatch opt f(s)
+ implicit def safe[S, T](f: S => T): TypeConverter[S, T] = new TypeConverter[S, T] {
+ def apply(s: S): Option[T] = allCatch opt f(s)
+ }
/**
* Implicit convert a `(String) => Option[T]` function into a `TypeConverter[T]`
*/
- implicit def safeOption[S, T](f: S => Option[T]) = (s: S) => allCatch.withApply(_ => None)(f(s))
+ implicit def safeOption[S, T](f: S => Option[T]): TypeConverter[S, T] = new TypeConverter[S, T] {
+ def apply(v1: S): Option[T] = allCatch.withApply(_ => None)(f(v1))
+ }
}
@@ -25,8 +29,6 @@ object TypeConverterSupport extends TypeConverterSupport
trait BigDecimalImplicitConversions extends TypeConverterSupport { self: DefaultImplicitConversions =>
implicit val stringToBigDecimal: TypeConverter[String, BigDecimal] = safe(BigDecimal(_))
implicit val stringToSeqBigDecimal: TypeConverter[String, Seq[BigDecimal]] = stringToSeq(stringToBigDecimal)
- implicit val stringSeqToBigDecimal: TypeConverter[Seq[String], BigDecimal] = seqHead(stringToBigDecimal)
- implicit val stringSeqToSeqBigDecimal: TypeConverter[Seq[String], Seq[BigDecimal]] = seqToSeq(stringToBigDecimal)
}
/**
@@ -36,7 +38,7 @@ trait BigDecimalImplicitConversions extends TypeConverterSupport { self: Default
trait DefaultImplicitConversions extends TypeConverterSupport {
implicit val stringToBoolean: TypeConverter[String, Boolean] = safe { s => s.toUpperCase match {
- case "ON" | "TRUE" | "OK" | "1" | "CHECKED" => true
+ case "ON" | "TRUE" | "OK" | "1" | "CHECKED" | "YES" | "ENABLE" | "ENABLED" => true
case _ => false
} }
@@ -77,45 +79,12 @@ trait DefaultImplicitConversions extends TypeConverterSupport {
def stringToSeq[T:Manifest](elementConverter: TypeConverter[String, T], separator: String = ","): TypeConverter[String, Seq[T]] =
safe(s => s.split(separator).toSeq.flatMap(e => elementConverter(e.trim)))
- def seqHead[T:Manifest](elementConverter: TypeConverter[String, T]): TypeConverter[Seq[String], T] =
+ implicit def seqHead[T](implicit elementConverter: TypeConverter[String, T], mf: Manifest[T]): TypeConverter[Seq[String], T] =
safeOption(_.headOption.flatMap(elementConverter(_)))
- def seqToSeq[T:Manifest](elementConverter: TypeConverter[String, T]): TypeConverter[Seq[String], Seq[T]] =
+ implicit def seqToSeq[T](implicit elementConverter: TypeConverter[String, T], mf: Manifest[T]): TypeConverter[Seq[String], Seq[T]] =
safe(_.flatMap(elementConverter(_)))
- implicit val stringSeqToBoolean: TypeConverter[Seq[String], Boolean] = seqHead(stringToBoolean)
-
- implicit val stringSeqToFloat: TypeConverter[Seq[String], Float] = seqHead(stringToFloat)
-
- implicit val stringSeqToDouble: TypeConverter[Seq[String], Double] = seqHead(stringToDouble)
-
-
- implicit val stringSeqToByte: TypeConverter[Seq[String], Byte] = seqHead(stringToByte)
-
- implicit val stringSeqToShort: TypeConverter[Seq[String], Short] = seqHead(stringToShort)
-
- implicit val stringSeqToInt: TypeConverter[Seq[String], Int] = seqHead(stringToInt)
-
- implicit val stringSeqToLong: TypeConverter[Seq[String], Long] = seqHead(stringToLong)
-
- implicit val stringSeqToString: TypeConverter[Seq[String], String] = seqHead(stringToSelf)
-
- implicit val stringSeqToSeqBoolean: TypeConverter[Seq[String], Seq[Boolean]] = seqToSeq(stringToBoolean)
-
- implicit val stringSeqToSeqFloat: TypeConverter[Seq[String], Seq[Float]] = seqToSeq(stringToFloat)
-
- implicit val stringSeqToSeqDouble: TypeConverter[Seq[String], Seq[Double]] = seqToSeq(stringToDouble)
-
- implicit val stringSeqToSeqByte: TypeConverter[Seq[String], Seq[Byte]] = seqToSeq(stringToByte)
-
- implicit val stringSeqToSeqShort: TypeConverter[Seq[String], Seq[Short]] = seqToSeq(stringToShort)
-
- implicit val stringSeqToSeqInt: TypeConverter[Seq[String], Seq[Int]] = seqToSeq(stringToInt)
-
- implicit val stringSeqToSeqLong: TypeConverter[Seq[String], Seq[Long]] = seqToSeq(stringToLong)
-
- implicit val stringSeqToSeqString: TypeConverter[Seq[String], Seq[String]] = seqToSeq(stringToSelf)
-
}
object Conversions extends DefaultImplicitConversions {
View
18 core/src/test/scala/org/scalatra/GZipSupportTest.scala
@@ -5,12 +5,16 @@ import java.io.InputStream
import java.util.zip.GZIPInputStream
import org.scalatra.test.scalatest.ScalatraFunSuite
import org.scalatest.matchers._
+import javax.servlet.ServletConfig
+import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
/**
* Test servlet using GZipSupport.
*/
-class GZipSupportTestServlet extends ScalatraServlet with GZipSupport {
-
+class GZipSupportTestServlet extends ScalatraServlet with GZipSupportAppBase
+class GZipSupportTestApp(config: ServletConfig, req: HttpServletRequest, res: HttpServletResponse) extends ScalatraApp(config, req, res) with GZipSupportAppBase
+trait GZipSupportAppBase extends ScalatraSyntax with GZipSupport {
+
get("/") {
Helper.body
}
@@ -23,8 +27,14 @@ class GZipSupportTestServlet extends ScalatraServlet with GZipSupport {
/**
* Test suite.
*/
-class GZipSupportTest extends ScalatraFunSuite with ShouldMatchers {
- addServlet(classOf[GZipSupportTestServlet], "/*")
+class GZipSupportServletTest extends GZipSupportTest {
+ mount(classOf[GZipSupportTestServlet], "/*")
+}
+class GZipSupportAppTest extends GZipSupportTest {
+ mount(new GZipSupportTestApp(_, _, _), "/*")
+}
+abstract class GZipSupportTest extends ScalatraFunSuite with ShouldMatchers {
+
test("should return response gzipped") {
session {
View
4 core/src/test/scala/org/scalatra/util/conversion/ConversionsSpecs.scala
@@ -38,7 +38,9 @@ class ConversionsSpecs extends Specification {
case class A(i: Int)
- val stringToOptionA = (s: String) => Option(s).map((v: String) => A(v.toInt))
+ val stringToOptionA = new TypeConverter[String, A] {
+ def apply(s: String) = Option(s).map(v => A(v.toInt))
+ }
val converted: TypeConverter[String, A] = stringToOptionA
View
4 example/src/main/scala/org/scalatra/BasicAuthExample.scala
@@ -8,7 +8,7 @@ object BasicAuthExample {
case class MyUser(id: String)
- class OurBasicAuthStrategy(protected override val app: ScalatraBase, realm: String)
+ class OurBasicAuthStrategy(protected override val app: ScalatraSyntax, realm: String)
extends BasicAuthStrategy[MyUser](app, realm) {
protected def validate(userName: String, password: String): Option[MyUser] = {
@@ -20,7 +20,7 @@ object BasicAuthExample {
}
trait AuthenticationSupport extends ScentrySupport[MyUser] with BasicAuthSupport[MyUser] {
- self: ScalatraBase =>
+ self: ScalatraSyntax =>
val realm = "Scalatra Basic Auth Example"
View
2 json/src/main/scala/org/scalatra/json/JValueResult.scala
@@ -8,7 +8,7 @@ import org.scalatra.ActionResult
import java.io.{FileInputStream, File}
import org.scalatra.ActionResult
-trait JValueResult extends ScalatraBase { self: JsonSupport[_] =>
+trait JValueResult extends ScalatraSyntax { self: JsonSupport[_] =>
implicit protected def jsonFormats: Formats
View
23 json/src/main/scala/org/scalatra/json/JsonImplicitConversions.scala
@@ -38,26 +38,9 @@ trait JsonImplicitConversions extends TypeConverterSupport {
def jsonToDateFormat(format: => DateFormat): TypeConverter[JValue, Date] =
safeOption(_.extractOpt[String] map format.parse)
- def jsonToSeq[T:Manifest](elementConverter: TypeConverter[JValue, T], separator: String = ","): TypeConverter[JValue, Seq[T]] =
+ implicit def jsonToSeq[T](implicit elementConverter: TypeConverter[JValue, T], mf: Manifest[T]): TypeConverter[JValue, Seq[T]] =
safe(_.extract[List[T]])
-
-
- implicit val jsonToSeqBoolean: TypeConverter[JValue, Seq[Boolean]] = jsonToSeq(jsonToBoolean)
-
- implicit val jsonToSeqFloat: TypeConverter[JValue, Seq[Float]] = jsonToSeq(jsonToFloat)
-
- implicit val jsonToSeqDouble: TypeConverter[JValue, Seq[Double]] = jsonToSeq(jsonToDouble)
-
- implicit val jsonToSeqByte: TypeConverter[JValue, Seq[Byte]] = jsonToSeq(jsonToByte)
- implicit val jsonToSeqShort: TypeConverter[JValue, Seq[Short]] = jsonToSeq(jsonToShort)
-
- implicit val jsonToSeqInt: TypeConverter[JValue, Seq[Int]] = jsonToSeq(jsonToInt)
-
- implicit val jsonToSeqLong: TypeConverter[JValue, Seq[Long]] = jsonToSeq(jsonToLong)
-
- implicit val jsonToSeqString: TypeConverter[JValue, Seq[String]] = jsonToSeq(jsonToSelf)
-
import JsonConversions._
implicit def jsonToValTypeConversion(source: JValue) = new JsonValConversion(source)
@@ -65,8 +48,8 @@ trait JsonImplicitConversions extends TypeConverterSupport {
implicit def jsonToDateConversion(source: JValue) = new JsonDateConversion(source, jsonToDate(_))
implicit def jsonToSeqConversion(source: JValue) = new {
- def asSeq[T](separator: String)(implicit mf: Manifest[T], tc: TypeConverter[JValue, T]): Option[Seq[T]] =
- jsonToSeq[T](tc, separator).apply(source)
+ def asSeq[T](implicit mf: Manifest[T], tc: TypeConverter[JValue, T]): Option[Seq[T]] =
+ jsonToSeq[T].apply(source)
}
}
View
2 scalate/src/main/scala/org/scalatra/scalate/ScalateRenderSupport.scala
@@ -1,7 +1,7 @@
package org.scalatra
package scalate
-trait ScalateRenderSupport { self: ScalatraBase with ScalateSupport =>
+trait ScalateRenderSupport { self: ScalatraSyntax with ScalateSupport =>
val templateBaseDirectory = "/WEB-INF/scalate/templates"
val scalateExtension = "ssp"
View
4 slf4j/src/main/scala/org/scalatra/slf4j/ScalatraSlf4jRequestLogging.scala
@@ -20,13 +20,13 @@ object ScalatraSlf4jRequestLogging {
}
-trait ScalatraSlf4jRequestLogging extends ScalatraBase with Handler {
+trait ScalatraSlf4jRequestLogging extends ScalatraSyntax with Handler {
private[this] val logger = Logger("REQUEST")
import ScalatraSlf4jRequestLogging._
abstract override def handle(req: HttpServletRequest, res: HttpServletResponse) {
- val realMultiParams = req.getParameterMap.asInstanceOf[JMap[String, Array[String]]].asScala.toMap transform { (k, v) v: Seq[String] }
+ val realMultiParams = req.getParameterMap.asScala.toMap transform { (k, v) v: Seq[String] }
withRequest(req) {
request(MultiParamsKey) = MultiMap(Map() ++ realMultiParams)
request(CgiParamsKey) = readCgiParams(req)
View
4 swagger-ext/src/main/scala/org/scalatra/swagger/SwaggerAuth.scala
@@ -22,7 +22,7 @@ class SwaggerWithAuth(val swaggerVersion: String, val apiVersion: String) extend
}
}
-trait SwaggerAuthBase[TypeForUser <: AnyRef] extends SwaggerBaseBase { self: ScalatraBase with JsonSupport[_] with CorsSupport with ScentrySupport[TypeForUser] =>
+trait SwaggerAuthBase[TypeForUser <: AnyRef] extends SwaggerBaseBase { self: ScalatraSyntax with JsonSupport[_] with CorsSupport with ScentrySupport[TypeForUser] =>
protected type ApiType = AuthApi[TypeForUser]
protected implicit def swagger: SwaggerEngine[AuthApi[AnyRef]]
protected def docToJson(doc: ApiType): JValue = doc.toJValue(userOption)
@@ -134,7 +134,7 @@ case class AuthOperation[TypeForUser <: AnyRef](httpMethod: HttpMethod,
errorResponses: List[Error] = Nil,
allows: Option[TypeForUser] => Boolean = (_: Option[TypeForUser]) => true) extends SwaggerOperation
-trait SwaggerAuthSupport[TypeForUser <: AnyRef] extends SwaggerSupportBase with SwaggerSupportSyntax { self: ScalatraBase with ScentrySupport[TypeForUser] =>
+trait SwaggerAuthSupport[TypeForUser <: AnyRef] extends SwaggerSupportBase with SwaggerSupportSyntax { self: ScalatraSyntax with ScentrySupport[TypeForUser] =>
protected def allows(value: Option[TypeForUser] => Boolean) = swaggerMeta(Symbols.Allows, value)
private def allowAll = (u: Option[TypeForUser]) => true
View
2 swagger-ext/src/main/scala/org/scalatra/swagger/SwaggerCommand.scala
@@ -60,7 +60,7 @@ object SwaggerCommandSupport {
Model(cmd.commandName, cmd.commandDescription, Map(modelFields:_*))
}
}
-trait SwaggerCommandSupport { this: ScalatraBase with SwaggerSupportBase with SwaggerSupportSyntax with CommandSupport =>
+trait SwaggerCommandSupport { this: ScalatraSyntax with SwaggerSupportBase with SwaggerSupportSyntax with CommandSupport =>
protected def parameters[T <: CommandType : Manifest] =
swaggerMeta(Symbols.Parameters, parametersFromCommand[T])
View
2 swagger-ext/src/test/scala/org/scalatra/swagger/SwaggerAuthSpec.scala
@@ -19,7 +19,7 @@ object SwaggerAuthSpec {
class SpecSwagger extends SwaggerWithAuth("1.1", "1")
- class HeaderOrQueryToken(protected val app: ScalatraBase) extends ScentryStrategy[User] {
+ class HeaderOrQueryToken(protected val app: ScalatraSyntax) extends ScentryStrategy[User] {
override def name = "header_or_query_token"
private def token = (app.request.header("API-TOKEN") orElse app.params.get("api_token")).flatMap(_.blankOption)
override def isValid = token.isDefined
View
2 swagger/src/main/scala/org/scalatra/swagger/JacksonSwaggerBase.scala
@@ -3,4 +3,4 @@ package swagger
import json.JacksonJsonSupport
-trait JacksonSwaggerBase extends ScalatraBase with JacksonJsonSupport with CorsSupport with SwaggerBase
+trait JacksonSwaggerBase extends ScalatraSyntax with JacksonJsonSupport with CorsSupport with SwaggerBase
View
2 swagger/src/main/scala/org/scalatra/swagger/NativeSwaggerBase.scala
@@ -5,4 +5,4 @@ package swagger
import json.NativeJsonSupport
-trait NativeSwaggerBase extends ScalatraBase with NativeJsonSupport with CorsSupport with SwaggerBase
+trait NativeSwaggerBase extends ScalatraSyntax with NativeJsonSupport with CorsSupport with SwaggerBase
View
4 swagger/src/main/scala/org/scalatra/swagger/SwaggerBase.scala
@@ -8,7 +8,7 @@ import json.JsonSupport
/**
* Trait that serves the resource and operation listings, as specified by the Swagger specification.
*/
-trait SwaggerBaseBase { self: ScalatraBase with JsonSupport[_] with CorsSupport =>
+trait SwaggerBaseBase { self: ScalatraSyntax with JsonSupport[_] with CorsSupport =>
protected type ApiType <: SwaggerApi[_]
@@ -52,7 +52,7 @@ trait SwaggerBaseBase { self: ScalatraBase with JsonSupport[_] with CorsSupport
}
-trait SwaggerBase extends SwaggerBaseBase { self: ScalatraBase with JsonSupport[_] with CorsSupport =>
+trait SwaggerBase extends SwaggerBaseBase { self: ScalatraSyntax with JsonSupport[_] with CorsSupport =>
type ApiType = Api
protected def docToJson(doc: Api): JValue = doc.toJValue
protected implicit def swagger: SwaggerEngine[ApiType]
View
4 swagger/src/main/scala/org/scalatra/swagger/SwaggerSupport.scala
@@ -21,7 +21,7 @@ trait SwaggerSupportBase {
protected def operations(route: Route, method: HttpMethod): List[SwaggerOperation]
}
-trait SwaggerSupportSyntax extends Initializable with CorsSupport { this: ScalatraBase with SwaggerSupportBase =>
+trait SwaggerSupportSyntax extends Initializable with CorsSupport { this: ScalatraSyntax with SwaggerSupportBase =>
protected implicit def swagger: SwaggerEngine[_]
protected def applicationName: Option[String] = None
@@ -136,7 +136,7 @@ trait SwaggerSupportSyntax extends Initializable with CorsSupport { this: Scalat
/**
* Provides the necessary support for adding documentation to your routes.
*/
-trait SwaggerSupport extends ScalatraBase with SwaggerSupportBase with SwaggerSupportSyntax {
+trait SwaggerSupport extends ScalatraSyntax with SwaggerSupportBase with SwaggerSupportSyntax {

0 comments on commit 8491104

Please sign in to comment.
Something went wrong with that request. Please try again.