Scalatra 2.2.0-RC2 Released

Scalatra 2.2 has been in development since September. There were a few blocking bugs along the way, but the development team has now cut a second release candidate, Scalatra 2.2.0-RC2. If all goes well, Scalatra users will all get a Christmas present. See the full list of changes (below) if you want a sneek peak.

The full list of changes for the 2.2.0 release is now as follows:

Global

  • Removes jerkson support
  • Removes anti-xml support
  • Adds Jackson support
  • Adds common traits for pluggable json serialization, these traits allow library writers to write against a generic json interface. The application developer can then mix in the json support he wants and retain all functionality.
  • Defers reading request parameters until the last responsible moment (aka lazify)
  • Contrib project has been removed, all the modules have been moved into the main scalatra project

Core

  • Adds typed param support, previously in contrib
  • ApiFormats now also has a method responseFormat which looks at the content type of the response and falls back to the format of the request.
  • The default bootstrap file is renamed from Scalatra to ScalatraBootstrap
  • FileUpload can now be configured through init parameters
  • RouteMatchers don’t use any by-name params anymore
  • RouteMatcher now takes a requestPath as a param to the apply method
  • You are able to mount the same servlet more than once in the ScalatraBootstrap class
  • Added a new relativeUrl method which will compose a path for redirection and keep relative paths relative
  • Refactored the url method to allow for a more granular building of the path with regards to the context path and servlet path
  • Added a fullUrl method which will use the absolute path created by the url method to build a url with protocol, host, port and path + querystring
  • Added a isHttps method which also looks in the headers for a X-Forwarded-Proto header
  • Added a needsHttps method which looks in the init params for a key org.scalatra.ForceHttps for a boolean value (true/false), this is used by the fullUrl method to work out the protocol
  • Added a org.scalatra.HostName init parameter in which you can override the host name of this scalatra application, if unset the value from request.getServerName will be used
  • Added a org.scalatra.Port init parameter in which you can override the port of this scalatra application, if unset the value from request.getServerPort will be used
  • ApiFormats now also has a reverse mapping for the txt extension
  • Adds GZipSupport, contributed by @Marza
  • Folds TypedParamSupport into core making the params.getAs[Int] methods available everywhere

lift-json

  • Removed in favour of json4s support

Jackson

  • Removed in favour of json4s support

JSON

  • Previous lift-json support is replaced with json4s support.
  • Jackson integration is also provided through json4s
  • Replaces ProductToJsonSupport trait with a JValueResult trait which will try to serialize any value to json or xml when the accept headers or format parameter indicate the user wants json or xml.
  • Fix reading json from post without the right header
  • Include JValueResult by default in the NativeJsonSupport and JacksonJsonSupport
  • Make JValueResult only serialize Traversable and Product classes

Scalate

  • Adds ScalateRenderSupport trait taken from contrib

Databinding

  • Adds a databinding module for commands. The commands can have validations attached and will read data from headers, params and the request body (like json/xml) This is implemented using an infrastructure of type classes and uses scalaz validations to capture the validation information.

    class RegisterForm extends JacksonCommand { // you have to pick the json library of choice
    
      val login: Field[String] = asString("login").required.notBlank.minLength(6).validForFormat("\\w+".r)
    
      val name: Field[String] = asString("name")
    
      val email: Field[String] = asString("email").required.notBlank.validEmail
    
      val homepage: Field[String] = asString("homepage").validUrl
    
      val passwordConfirmation: FieldBinding = asString("passwordConfirmation").required.notBlank
    
      val password: FieldBinding = asString("password").required.notBlank.validConfirmation("passwordConfirmation", passwordConfirmation.value)
    
    }
    
  • Renames databinding to commands. This resolves the confusion created by the name databinding.

Akka

  • Updates akka to 2.0.4

Atmosphere

  • Adds an atmosphere integration This module adds support for websockets, long-polling, server-side events, ….

    class MyAtmoServlet {
      def receive = {
        case Connected =>
        case Disconnected(disconnector, Some(error)) =>
        case Error(Some(error)) =>
        case TextMessage(text) => send("ECHO: " + text)
        case JsonMessage(json) => broadcast(json)
      }
    }
    
  • Updates atmosphere to 1.0.6

  • Fixes atmosphere long-polling etc. A big thanks to @jfarcand

  • Fix ScalatraBroadcasterFactory#lookup to return null when nothing is found instead of throwing an exception

Swagger

  • Added serialization for AllowableValues in Swagger.scala. These are passed as strings in the AllowableValues object:

    // as List
    allowableValues = AllowableValues(1, 2, 3)
    
    // as range
    allowableValues = AllowableValues(0 to 1000)
    
  • Updated to support the swagger-1.1 spec

  • Allows for using either jackson or native json to generate the service description json

  • Auto-registers servlets and filters that extend the SwaggerSupport trait in the swagger manager.

  • Includes the swagger-core and swagger-annotations jars as transitive dependencies (batteries included)

  • The models property in the SwaggerSupport can now be Set as Map(classOf[Pet])

  • responseClass can now be set with a type parameter responseClass[Pet]

  • Data types in Parameter and ModelField definitions can now be defined as DataType[List[String]]

  • Make swagger optionally support authentication

  • Optionally integrate commands into swagger support to generate model and parameter definitions.

Swagger-Ext

  • Adds support for authorization through scentry to Swagger. Shows only actions a user is allowed to see. Example
  • Adds support for using commands with Swagger. This creates a model definition for the body parameters and parameter definitions for the query, path and header params as well as a parameter for the body model

    get("/id", endpoint("id"), nickname("getById"), parameters[MyCommand])
    
    class MyCommand extends JsonCommand {
      protected implicit val jsonFormats: Formats = DefaultFormats
    
      val name: Field[String] = asString("name").notBlank
    
      val age: Field[Int] = "age"
    
      val token: Field[String] = (
          asString("API-TOKEN").notBlank
            sourcedFrom ValueSource.Header
            description "The API token for this request"
            notes "Invalid data kills cute innocent kittens"
            allowableValues "123")
    
      val skip: Field[Int] = asInt("skip").sourcedFrom(ValueSource.Query).description("The offset for this collection index")
    
      val limit: Field[Int] = asType[Int]("limit").sourcedFrom(ValueSource.Query).withDefaultValue(20).description("the max number of items to return")
    }
    

Testing

  • Added a method ensureSessionIsSerializable method which will try to serialize every session value.

Specs

  • Deprecate scalatra-specs in anticipation of Scala 2.10 support.

Auth

  • Scentry is now lazily initialized so the order of the traits doesn’t matter anymore

SLF4J

  • Rename LogbackSupport to ScalatraSlf4jRequestLogging
  • Updates slf4j-api to 1.7.2