I am a little stuck with the book Scala in Action now on Chapter 7.
There is an example application build in the book that uses Jetty Server and Scalaz. The point is that once the Jetty server is started and a GET request is sent to a specific url, Scalaz should use pattern matching with the help of MethodParts extractor object.
However, whenever I try to access the url, the result is a 404.
I am using SBT 0.13.5 and jetty version 9.2.2.v20140723. Version of Scalaz is 6.0.3. And I'm running Java 8.
I was wondering, what could be the problem? As far as I learned from the book, no other configuration is necessary since Scalaz uses pattern matching to match URLs.
Could it be something is not properly configured with Jetty? Or something else that I am missing?
The pattern matching part of code:
def handle(implicit request: Request[Stream], servletRequest: HttpServletRequest): Option[Response[Stream]] =
request match {
case MethodParts(GET, "card" :: "create" :: Nil) =>
Some(OK(ContentType, "text/html") << strict << CreateStory(param("message")))
case _ => None
}
The main part of the Application class value:
val application = new ServletApplication[Stream, Stream]{
def application(implicit servlet: HttpServlet, servletRequest: HttpServletRequest,
request: Request[Stream]) = {
def found(x: Iterator[Byte]): Response[Stream] = OK << x.toStream
handle | HttpServlet.resource(found, NotFound.xhtml)
}
}
The Web.xml file:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Scalaz</servlet-name>
<servlet-class>
scalaz.http.servlet.StreamStreamServlet
</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>
com.kanban.application.WeKanbanApplication
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Scalaz</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Librabry dependency that provides Jetty: https://github.com/earldouglas/xsbt-web-plugin
Thank you!