Skip to content

Instantly share code, notes, and snippets.

Created November 6, 2014 14:44
Show Gist options
  • Save anonymous/d8465f2e026e127af956 to your computer and use it in GitHub Desktop.
Save anonymous/d8465f2e026e127af956 to your computer and use it in GitHub Desktop.
object Main extends App {
val thriftService = new FooService.FinagledService(new FooServiceImpl, new TBinaryProtocol.Factory())
val httpService = new Service[HttpRequest, HttpResponse] {
def apply(req: HttpRequest): Future[HttpResponse] = {
val content = ChannelBuffers.wrappedBuffer(req.getContent)
val thriftFuture = thriftService.apply(content.array())
thriftFuture flatMap { res =>
val response = new DefaultHttpResponse(req.getProtocolVersion, HttpResponseStatus.OK)
response.setContent(ChannelBuffers.wrappedBuffer(res))
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.getContent.readableBytes.toString)
Future.value(response)
}
}
}
val server = Http.serve(":8080", httpService)
Await.ready(server)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment