diff --git a/poc-scalatra/project/build.properties b/poc-scalatra/project/build.properties new file mode 100644 index 0000000..81e9cf3 --- /dev/null +++ b/poc-scalatra/project/build.properties @@ -0,0 +1,8 @@ +#Project properties +#Fri Apr 08 20:36:08 CEST 2011 +project.organization=com.dbo +project.name=poc-scalatra +sbt.version=0.7.4 +project.version=1.0 +build.scala.versions=2.8.1 +project.initialize=false diff --git a/poc-scalatra/project/build/PocScalatra.scala b/poc-scalatra/project/build/PocScalatra.scala index 23e3a53..09f3bba 100644 --- a/poc-scalatra/project/build/PocScalatra.scala +++ b/poc-scalatra/project/build/PocScalatra.scala @@ -1,12 +1,19 @@ import sbt._ -class build(info: ProjectInfo) extends DefaultWebProject(info) { -// scalatra -val sonatypeNexusSnapshots = "Sonatype Nexus Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots" -val sonatypeNexusReleases = "Sonatype Nexus Releases" at "https://oss.sonatype.org/content/repositories/releases" -val scalatra = "org.scalatra" %% "scalatra" % "2.0.0.M3" - -// jetty -val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.22" % "test" -val servletApi = "org.mortbay.jetty" % "servlet-api" % "2.5-20081211" % "provided" + +class PocScalatra(info: ProjectInfo) extends DefaultWebProject(info) { + // scalatra + val sonatypeNexusSnapshots = "Sonatype Nexus Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots" + val sonatypeNexusReleases = "Sonatype Nexus Releases" at "https://oss.sonatype.org/content/repositories/releases" + val scalatra = "org.scalatra" %% "scalatra" % "2.0.0.M3" + + + val guice = "com.google.inject" % "guice" % "3.0" + val guiceServlet = "com.google.inject.extensions" % "guice-servlet" % "3.0" + val scalaGuice = "scala-guice" % "scala-guice" % "0.1" from "http://guice-maven.googlecode.com/svn/trunk/scala-guice/scala-guice_2.8.0-0.1.jar" + + + // jetty + val jetty6 = "org.mortbay.jetty" % "jetty" % "6.1.22" % "test" + val servletApi = "org.mortbay.jetty" % "servlet-api" % "2.5-20081211" % "provided" } diff --git a/poc-scalatra/src/main/scala/poc/scalatra/inject/MyGuiceServletConfig.scala b/poc-scalatra/src/main/scala/poc/scalatra/inject/MyGuiceServletConfig.scala new file mode 100644 index 0000000..6889a08 --- /dev/null +++ b/poc-scalatra/src/main/scala/poc/scalatra/inject/MyGuiceServletConfig.scala @@ -0,0 +1,20 @@ +package poc.scalatra.inject + +import com.google.inject.{Injector, Guice} +import com.google.inject.servlet.GuiceServletContextListener + + + +class MyGuiceServletConfig extends GuiceServletContextListener { + + override def contextInitialized(servletContextEvent: javax.servlet.ServletContextEvent) = { + println("contextInitialized") + getInjector() + } + + override def getInjector():Injector = { + Guice.createInjector(new MyServletModule()); + } + + +} \ No newline at end of file diff --git a/poc-scalatra/src/main/scala/poc/scalatra/inject/MyServletModule.scala b/poc-scalatra/src/main/scala/poc/scalatra/inject/MyServletModule.scala new file mode 100644 index 0000000..bfd31b3 --- /dev/null +++ b/poc-scalatra/src/main/scala/poc/scalatra/inject/MyServletModule.scala @@ -0,0 +1,15 @@ +package poc.scalatra.inject + +import com.google.inject.servlet.ServletModule +import poc.scalatra.service.BlipService + + +class MyServletModule extends ServletModule { + + override def configureServlets() { + println("configureServlets - ENTER") + serve("/blip/*").`with`(classOf[BlipService]) + println("configureServlets - LEAVE") + } + +} \ No newline at end of file diff --git a/poc-scalatra/src/main/scala/poc/scalatra/service/BlipService.scala b/poc-scalatra/src/main/scala/poc/scalatra/service/BlipService.scala new file mode 100644 index 0000000..36237f7 --- /dev/null +++ b/poc-scalatra/src/main/scala/poc/scalatra/service/BlipService.scala @@ -0,0 +1,12 @@ +package poc.scalatra.service + +import javax.servlet.http.{HttpServletRequest, HttpServletResponse, HttpServlet} + +@com.google.inject.Singleton +class BlipService extends HttpServlet { + + + override def doGet(request: HttpServletRequest, response: HttpServletResponse) = response.getWriter().println("BlipService") + + +} \ No newline at end of file diff --git a/poc-scalatra/src/main/webapp/WEB-INF/web.xml b/poc-scalatra/src/main/webapp/WEB-INF/web.xml index 3967414..079228d 100644 --- a/poc-scalatra/src/main/webapp/WEB-INF/web.xml +++ b/poc-scalatra/src/main/webapp/WEB-INF/web.xml @@ -1,17 +1,32 @@ + PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" + "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> - - -WebApp -WebApp - - - -WebApp -/* - + + + + poc.scalatra.inject.MyGuiceServletConfig + + + + guiceFilter + com.google.inject.servlet.GuiceFilter + + + + guiceFilter + /* + + + + + + + + + + +