Created
December 2, 2014 19:47
-
-
Save nidkil/3dc4a39ece1236a69514 to your computer and use it in GitHub Desktop.
Halt does not work with JacksonJsonSupport trait mixed in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import Keys._ | |
import org.scalatra.sbt._ | |
import org.scalatra.sbt.PluginKeys._ | |
import com.mojolly.scalate.ScalatePlugin._ | |
import ScalateKeys._ | |
object JsontestservletBuild extends Build { | |
val Organization = "com.nidkil" | |
val Name = "json-test-servlet" | |
val Version = "0.1.0-SNAPSHOT" | |
val ScalaVersion = "2.11.1" | |
val ScalatraVersion = "2.3.0" | |
lazy val project = Project ( | |
"json-test-servlet", | |
file("."), | |
settings = ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq( | |
organization := Organization, | |
name := Name, | |
version := Version, | |
scalaVersion := ScalaVersion, | |
resolvers += Classpaths.typesafeReleases, | |
libraryDependencies ++= Seq( | |
"org.json4s" %% "json4s-jackson" % "3.2.9", | |
"org.scalatra" %% "scalatra-json" % ScalatraVersion, | |
"org.scalatra" %% "scalatra" % ScalatraVersion, | |
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion, | |
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test", | |
"ch.qos.logback" % "logback-classic" % "1.1.2" % "runtime", | |
"org.eclipse.jetty" % "jetty-webapp" % "9.1.5.v20140505" % "container", | |
"org.eclipse.jetty" % "jetty-plus" % "9.1.5.v20140505" % "container", | |
"javax.servlet" % "javax.servlet-api" % "3.1.0" | |
), | |
scalateTemplateConfig in Compile <<= (sourceDirectory in Compile){ base => | |
Seq( | |
TemplateConfig( | |
base / "webapp" / "WEB-INF" / "templates", | |
Seq.empty, /* default imports should be added here */ | |
Seq( | |
Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true) | |
), /* add extra bindings here */ | |
Some("templates") | |
) | |
) | |
} | |
) | |
) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nidkil.jsontest | |
import org.json4s.{Formats, DefaultFormats} | |
import org.scalatra._ | |
import org.scalatra.json._ | |
import scalate.ScalateSupport | |
class JsonTestServlet extends ScalatraServlet with JacksonJsonSupport { | |
protected implicit val jsonFormats: Formats = DefaultFormats | |
case class HaltBody(status: Int, msg: String) | |
before() { | |
contentType = formats("json") | |
} | |
get("/halt") { | |
halt(502) | |
} | |
get("/halt-with-body") { | |
halt(502, "error msg") | |
} | |
get("/halt-custom-body") { | |
halt(502, HaltBody(502, "error msg")) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.nidkil.jsontest | |
import org.scalatra._ | |
import scalate.ScalateSupport | |
class NoJsonTestServlet extends ScalatraServlet { | |
case class HaltBody(status: Int, msg: String) | |
before() { | |
} | |
get("/halt") { | |
halt(502) | |
} | |
get("/halt-with-body") { | |
halt(502, "error msg") | |
} | |
get("/halt-custom-body") { | |
halt(502, HaltBody(502, "error msg")) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.nidkil.jsontest._ | |
import org.scalatra._ | |
import javax.servlet.ServletContext | |
class ScalatraBootstrap extends LifeCycle { | |
override def init(context: ServletContext) { | |
context.mount(new NoJsonTestServlet, "/nojson/*") | |
context.mount(new JsonTestServlet, "/json/*") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment