Skip to content

Instantly share code, notes, and snippets.

@kdrakon
Created February 19, 2014 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdrakon/9103167 to your computer and use it in GitHub Desktop.
Save kdrakon/9103167 to your computer and use it in GitHub Desktop.
Using Spray (1.2.0) with Jetty 9 Embedded
spray.servlet {
boot-class = "com.blah.RestServletBoot"
request-timeout = 30 s
}
object Main extends App {
val jettyServer = new Server(8080)
/** Serve some HTML along side the Spray Servlet **/
val htmlHandler = new ResourceHandler()
// here, my HTML files are in a 'web' folder under src/main/resources/web
htmlHandler.setResourceBase(ClassLoader.getSystemResource("web").toString())
htmlHandler.setDirectoriesListed(true)
/** Serve the Spray Servlet **/
val sprayHandler = new ServletContextHandler(ServletContextHandler.SESSIONS)
// the Initializer below will look at your application.conf for spray.servlet.boot-class, so make sure you have it defined
sprayHandler.addEventListener(new Initializer())
sprayHandler.addServlet(classOf[ Servlet30ConnectorServlet ], "/*")
val handlers = new HandlerList()
handlers.setHandlers((Array(htmlHandler, sprayHandler).toArray[ Handler ]))
jettyServer.setHandler(handlers)
jettyServer.start()
jettyServer.join()
}
class RestServletBoot extends WebBoot {
implicit val system = ActorSystem("SpraySystem")
// RestManager is your Akka actor to handle the HTTP requests, which is not provided here in the gist
implicit val serviceActor = system.actorOf(Props(classOf[ RestManager ]), "restManager")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment