Created
November 6, 2014 14:44
-
-
Save anonymous/d8465f2e026e127af956 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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