0

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!

Marin
  • 861
  • 1
  • 11
  • 27
  • Servlet **`2.3`** !? Are you really writing this against Jetty 4.x (from 1997)? That servlet spec was retired many years ago. Jetty 9.2 is on Servlet spec 3.1 (consider upgrading your `web.xml`. – Joakim Erdfelt Sep 02 '14 at 13:36
  • Changing web.xml doesn't solve the problem. – Marin Sep 02 '14 at 14:12

1 Answers1

0

I wish I could delete this question. All in all, I found the problem... the sbt compiler was using the wrong source code file... that is, since I'm not using an IDE, but Sublime Text 3 Beta, when I moved the file to another location, Sublime left the file in memory with the reference to the old location... so when I compiled the wrong version of the file was being used. A noob mistake.

Marin
  • 861
  • 1
  • 11
  • 27