Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Finagle - Http request (with compression)
package com.twitter.finagle.example.misc
import com.twitter.finagle.Service
import com.twitter.finagle.builder._
import com.twitter.finagle.http._
import com.twitter.util.Future
import java.net.InetSocketAddress
import org.jboss.netty.buffer.ChannelBuffers
import org.jboss.netty.handler.codec.http._
import org.jboss.netty.util.CharsetUtil.UTF_8
import scala.collection.mutable.Buffer
import org.jboss.netty.util.CharsetUtil
import java.net.URL
object Tutorial3Client {
def main(args: Array[String]) {
val clientCodec = Http(_compressionLevel = 6, _decompressionEnabled = true)
val client = ClientBuilder()
.codec(clientCodec)
.name("EchoClient")
.hosts("localhost:8080")
.hostConnectionLimit(10)
.build()
val request = RequestBuilder()
.setHeader(HttpHeaders.Names.USER_AGENT, "MyBot")
.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE)
.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, "gzip,deflate,sdch")
.url(new URL("http://localhost:8080/?a=111111111111111111111"))
.buildGet()
client(request) onSuccess { result =>
println("success: " + result)
} onFailure { error =>
error.printStackTrace()
} ensure {
client.release()
}
}
}
object Tutorial3Server {
def main(args: Array[String]) {
class EchoService extends Service[HttpRequest, HttpResponse] {
def apply(request: HttpRequest) = {
val response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)
val params = new QueryStringDecoder(request.getUri()).getParameters()
val responseContent = params.toString()
println(request.getHeaders())
response.setContent(ChannelBuffers.copiedBuffer(responseContent, CharsetUtil.UTF_8))
Future.value(response)
}
}
val echoServer: Server = ServerBuilder()
.codec(Http(_compressionLevel = 6))
.bindTo(new InetSocketAddress(8080))
.name("EchoServer")
.build(new EchoService())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.