Server .codec(Http()) not working as specified in example code

322 views Asked by At

I am attempting to try out Finagle for the first time. I am new to Scala, so this question may seem easy to many of you.

I pulled 6.10.1-SNAPSHOT from GitHub, and attempted to implement the Robust Server example shown in the docs. The imports were not entirely clear to me, and I got all of them working except one. Note in the code below that there is one import that has an error along with one call to Http() which also has an error.

import com.twitter.finagle.http.Http

def main(args: Array[String]) {
    val handleExceptions = new HandleExceptions
    val authorize = new Authorize
    val respond = new Respond

    val myService: Service[HttpRequest, HttpResponse]
        = handleExceptions andThen authorize andThen respond

    val server: Server = ServerBuilder()
    .name("myService")
    .codec(Http()) // Error on this call to Http()
    .bindTo(new InetSocketAddress(8080))
    .build(myService)
}
2

There are 2 answers

0
Falmarri On BEST ANSWER

The guide that you're following (I'm assuming this one) is quite outdated. The new docs here http://twitter.github.io/scala_school/finagle.html should be better (although the examples still aren't great)

It looks like they moved the HTTP codec to com.twitter.finagle.Http

0
JohnC On

The example code is not up-to-date with 6.10.1-SNAPSHOT. The import issue can be resolved by referencing libraryDependencies in build.sbt which correspond to the version of Finagle which was used to build the example:

libraryDependencies ++= Seq(
  "com.twitter" % "finagle-core" % "6.6.2",
  "com.twitter" % "finagle-http" % "6.6.2",
  "com.twitter" % "util-core" % "6.5.0")