
org.fusesource.scalate.guice.ScalateAtmosphereServlet.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalate-guice Show documentation
Show all versions of scalate-guice Show documentation
Guice integration for a Jersey based Scalate web application
The newest version!
package org.fusesource.scalate.guice
import javax.servlet.ServletConfig
import com.google.inject.{Inject, Injector, Singleton}
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer
import org.atmosphere.cpr.AtmosphereServlet
import org.atmosphere.handler.ReflectorServletProcessor
/**
* Atmosphere servlet configured by Scalate/Guice
*
* @author Sven Jacobs
*/
@Singleton
class ScalateAtmosphereServlet @Inject() (private val injector: Injector) extends AtmosphereServlet {
/**
* Most of the code to set up AtmosphereServlet has been borrowed from
* {@link org.atmosphere.guice.AtmosphereGuiceServlet#detectSupportedFramework}
*/
override def detectSupportedFramework(sc: ServletConfig): Boolean = {
import AtmosphereServlet._
setDefaultBroadcasterClassName(JERSEY_BROADCASTER)
val guiceContainer = injector.getInstance(classOf[GuiceContainer])
// val resourceConfig = injector.getInstance(classOf[ResourceConfig])
val rsp = new ReflectorServletProcessor()
rsp.setServlet(guiceContainer)
// val props = resourceConfig.getProperties.asScala
//
// for ((name, value) <- props) {
// if (value.isInstanceOf[String]) {
// addInitParameter(name, value.asInstanceOf[String])
// }
// }
var mapping = sc.getInitParameter(PROPERTY_SERVLET_MAPPING)
if (mapping == null) mapping = "/*"
getAtmosphereConfig.setSupportSession(false)
addAtmosphereHandler(mapping, rsp)
true
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy