Created
February 19, 2014 22:38
-
-
Save kdrakon/9103167 to your computer and use it in GitHub Desktop.
Using Spray (1.2.0) with Jetty 9 Embedded
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
spray.servlet { | |
boot-class = "com.blah.RestServletBoot" | |
request-timeout = 30 s | |
} |
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 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