Last active
September 6, 2017 10:04
-
-
Save bracki/4551987 to your computer and use it in GitHub Desktop.
Thrift HTTP transport implemented as a Filter for Twitter's Finagle.
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
class ThriftOverHttp extends Filter[ThriftClientRequest, Array[Byte], HttpRequest, HttpResponse] { | |
def apply(request: ThriftClientRequest, service: Service[HttpRequest, HttpResponse]) = { | |
val httpRequest = convertThriftRequestToHttpRequest(request) | |
val response = service(httpRequest) | |
response flatMap { res => | |
Future.value(res.getContent().array()) | |
} | |
} | |
private def convertThriftRequestToHttpRequest(request: ThriftClientRequest) = { | |
val content = ChannelBuffers.copiedBuffer(request.message) | |
val httpRequest = new DefaultHttpRequest( | |
HttpVersion.HTTP_1_1, | |
HttpMethod.POST, | |
"/") | |
httpRequest.setContent(content) | |
httpRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, content.readableBytes.toString) | |
httpRequest | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I am trying to use finagle along with your code to communicate with a flash client for a university project. Unfortunately I am struggling to get it to work could you include a usage example (I was trying to use it chained with and Then, but no success complaining that the arguments don't fit)?