Skip to content

Commit

Permalink
Update Finagle to 6.36 (TechEmpower#2233)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkostyukov authored and ashawnbandy-te-tfb committed Sep 9, 2016
1 parent a09ca72 commit 3a37d1a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
6 changes: 4 additions & 2 deletions frameworks/Scala/finagle/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name := "finagle"

scalaVersion := "2.11.8"

version := "1.0.1"
version := "1.0.2"

com.github.retronym.SbtOneJar.oneJarSettings

libraryDependencies ++= Seq(
"com.twitter" %% "finagle-http" % "6.34.0",
"com.twitter" %% "finagle-http" % "6.36.0",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.5.3"
)
1 change: 1 addition & 0 deletions frameworks/Scala/finagle/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("org.scala-sbt.plugins" % "sbt-onejar" % "0.8")
4 changes: 2 additions & 2 deletions frameworks/Scala/finagle/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

fw_depends java sbt

sbt update compile -batch
sbt 'oneJar' -batch

sbt run &
java -jar target/scala-2.11/*finagle*one-jar.jar &
17 changes: 9 additions & 8 deletions frameworks/Scala/finagle/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import java.text.{DateFormat, SimpleDateFormat}
import java.util.Date

import com.fasterxml.jackson.databind.ObjectMapper
Expand All @@ -13,14 +12,13 @@ import com.twitter.io.Buf
object Main extends App {

val mapper: ObjectMapper = new ObjectMapper().registerModule(DefaultScalaModule)
val dateFormat: DateFormat = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z")

val helloWorld: Buf = Buf.Utf8("Hello, World!")

val muxer: HttpMuxer = new HttpMuxer()
.withHandler("/json", Service.mk { req: Request =>
val rep = Response()
rep.content = Buf.Utf8(mapper.writeValueAsString(Map("message" -> "Hello, World!")))
rep.content = Buf.ByteArray.Owned(mapper.writeValueAsBytes(Map("message" -> "Hello, World!")))
rep.contentType = "application/json"

Future.value(rep)
Expand All @@ -34,13 +32,16 @@ object Main extends App {
})

val serverAndDate: SimpleFilter[Request, Response] = new SimpleFilter[Request, Response] {
def apply(req: Request, s: Service[Request, Response]): Future[Response] =
s(req).map { rep =>
rep.headerMap.set("Server", "Finagle")
rep.headerMap.set("Date", dateFormat.format(new Date()))

private[this] val addServerAndDate: Response => Response = { rep =>
rep.server = "Finagle"
rep.date = new Date()

rep
}
}

def apply(req: Request, s: Service[Request, Response]): Future[Response] =
s(req).map(addServerAndDate)
}

Await.ready(Http.server
Expand Down

0 comments on commit 3a37d1a

Please sign in to comment.