Skip to content

Instantly share code, notes, and snippets.

@agnaldo4j
Created October 31, 2015 22:23
Show Gist options
  • Save agnaldo4j/875aa2613ba493883510 to your computer and use it in GitHub Desktop.
Save agnaldo4j/875aa2613ba493883510 to your computer and use it in GitHub Desktop.
Implementação de servidor jetty embarcado com Java WebSocket API e Scalatra. :-)
def main(args: Array[String]) {
val port = restApiConfig.getInt("port")
println(restApiConfig.getString("resourceBase"))
val server = new Server(port)
val context = new WebAppContext()
context setContextPath "/"
context.setResourceBase(restApiConfig.getString("resourceBase"))
context.setInitParameter(ScalatraListener.LifeCycleKey, "com.opportunity.simple.restapi.ScalatraBootstrap")
context.addEventListener(new ScalatraListener)
context.addServlet(classOf[DefaultServlet],"/")
server.setHandler(context)
val wscontainer:ServerContainer = WebSocketServerContainerInitializer.configureContext(context)
wscontainer.setDefaultMaxSessionIdleTimeout(1000 * 60 * 30)
wscontainer.addEndpoint(classOf[MyEchoSocket])
server.start
server.join
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment