--- a/src/main/scala/Main.scala Wed Aug 24 14:18:55 2011 -0400
+++ b/src/main/scala/Main.scala Wed Aug 24 14:27:37 2011 -0400
@@ -63,6 +63,9 @@
}
+import VirtualTrainerApp._
+import org.w3.virtualtrainer.util.RequestLogger
+
object VirtualTrainerAppMain {
val logger:Logger = LoggerFactory.getLogger(this.getClass)
@@ -76,23 +79,9 @@
val port = args.toList.headOption map { _.toInt } getOrElse 2719
- import javax.servlet._
- import javax.servlet.http._
- import VirtualTrainerApp._
-
- unfiltered.jetty.Http(port).filter {
- new Filter {
- def destroy():Unit = ()
- def doFilter(request:ServletRequest, response:ServletResponse, chain:FilterChain):Unit = {
- val r:HttpServletRequest = request.asInstanceOf[HttpServletRequest]
- val method = r.getMethod
- val uri = r.getRequestURI
- logger.info("%s %s" format (method, uri))
- chain.doFilter(request, response)
- }
- def init(filterConfig:FilterConfig):Unit = ()
- }
- }.context("/scripts"){ ctx:ContextBuilder =>
+ unfiltered.jetty.Http(port)
+ .filter(new RequestLogger {})
+ .context("/scripts"){ ctx:ContextBuilder =>
ctx.resources(fromClasspath("scripts/").toURI.toURL)
}.context("/styles"){ ctx:ContextBuilder =>
ctx.resources(fromClasspath("styles/").toURI.toURL)
--- a/src/main/scala/Util.scala Wed Aug 24 14:18:55 2011 -0400
+++ b/src/main/scala/Util.scala Wed Aug 24 14:27:37 2011 -0400
@@ -59,4 +59,24 @@
dir
}
+}
+
+import javax.servlet._
+import javax.servlet.http._
+
+trait RequestLogger extends Filter {
+
+ val logger:Logger = LoggerFactory.getLogger(this.getClass)
+
+ def destroy():Unit = ()
+
+ def doFilter(request:ServletRequest, response:ServletResponse, chain:FilterChain):Unit = {
+ val r:HttpServletRequest = request.asInstanceOf[HttpServletRequest]
+ val method = r.getMethod
+ val uri = r.getRequestURI
+ logger.info("%s %s" format (method, uri))
+ chain.doFilter(request, response)
+ }
+
+ def init(filterConfig:FilterConfig):Unit = ()
}
\ No newline at end of file