Skip to content

Commit

Permalink
Add Guice-Servlet.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboissin committed Apr 9, 2011
1 parent c7e587a commit ca625b8
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 21 deletions.
8 changes: 8 additions & 0 deletions poc-scalatra/project/build.properties
Original file line number Diff line number Diff line change
@@ -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
25 changes: 16 additions & 9 deletions poc-scalatra/project/build/PocScalatra.scala
Original file line number Diff line number Diff line change
@@ -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"
}

Original file line number Diff line number Diff line change
@@ -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());
}


}
Original file line number Diff line number Diff line change
@@ -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")
}

}
12 changes: 12 additions & 0 deletions poc-scalatra/src/main/scala/poc/scalatra/service/BlipService.scala
Original file line number Diff line number Diff line change
@@ -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")


}
39 changes: 27 additions & 12 deletions poc-scalatra/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>

<servlet>
<servlet-name>WebApp</servlet-name>
<servlet-class>WebApp</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>WebApp</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>


<listener>
<listener-class>poc.scalatra.inject.MyGuiceServletConfig</listener-class>
</listener>

<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!--<servlet>-->
<!--<servlet-name>WebApp</servlet-name>-->
<!--<servlet-class>WebApp</servlet-class>-->
<!--</servlet>-->

<!--<servlet-mapping>-->
<!--<servlet-name>WebApp</servlet-name>-->
<!--<url-pattern>/hello/*</url-pattern>-->
<!--</servlet-mapping>-->
</web-app>

0 comments on commit ca625b8

Please sign in to comment.