Created
March 11, 2014 17:19
-
-
Save isterin/9490550 to your computer and use it in GitHub Desktop.
Scalatra jetty 9.1.3 issue with standalone deployment
This file contains 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
object Runner { | |
// this is my entry object as specified in sbt project definition | |
def main(args: Array[String]) { | |
val port = if (System.getenv("PORT") != null) System.getenv("PORT").toInt else 8080 | |
val server = new Server(port) | |
val context = new WebAppContext() | |
context setContextPath "/" | |
context.setResourceBase("src/main/webapp") | |
context.addEventListener(new ScalatraListener) | |
context.addServlet(classOf[DefaultServlet], "/") | |
server.setHandler(context) | |
server.start() | |
server.join() | |
} | |
} |
This file contains 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
class SearchResource(private val searchService: SearchServiceInterface) extends ScalatraServlet with FutureSupport { | |
protected implicit def executor: ExecutionContext = GlobalContext.system.dispatcher | |
protected implicit def jsonFormats: Formats = DefaultFormats | |
get("/") { | |
new AsyncResult { | |
val is = Future { | |
val prom = Promise[String]() | |
new Thread { | |
Thread.sleep(500) | |
prom.success("SUCCESS") | |
} | |
Ok(Await.result(prom.future, 10 seconds)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment