Skip to content

Commit

Permalink
Remove finagle-http
Browse files Browse the repository at this point in the history
Problem

finagle-http is deprecated in favor of finagle-httpx and should be
removed.

See our blog post on upgrading to Netty 4 for more information[1]. Drop
by finaglers[2] if you have any questions.

Solution

Remove finagle-http and convert its dependents to finagle-httpx.

[1] https://finagle.github.io/blog/2014/10/20/upgrading-finagle-to-netty-4/
[2] https://groups.google.com/d/forum/finaglers

RB_ID=746510
  • Loading branch information
luciferous authored and jenkins committed Sep 28, 2015
1 parent 150bbf1 commit 47bf5da
Show file tree
Hide file tree
Showing 125 changed files with 91 additions and 10,758 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Note that ``RB_ID=#`` correspond to associated messages in commits.
6.x
-----

Deprecations
~~~~~~~~~~~~

* finagle-http: Deprecated in favor of finagle-httpx and now removed.

New Features
~~~~~~~~~~~~

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class GenSerialServerDispatcher[Req, Rep, In, Out](trans: Transport[In,
* since the entire request is present. For streaming requests,
* `eos.setDone()` must be called at the end of stream (in HTTP, this is on
* receipt of last chunk). Refer to the implementation in
* [[com.twitter.finagle.http.codec.HttpServerDispatcher]].
* [[com.twitter.finagle.httpx.codec.HttpServerDispatcher]].
*/
protected def dispatch(req: Out, eos: Promise[Unit]): Future[Rep]
protected def handle(rep: Rep): Future[Unit]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ implement [[com.twitter.finagle.Client Client]] and/or
Thus a simple HTTP server is built like this:
{{{
import com.twitter.finagle.{Http, Service}
import com.twitter.finagle.{Httpx, Service}
import org.jboss.netty.handler.codec.http.{
HttpRequest, HttpResponse, DefaultHttpResponse}
import org.jboss.netty.handler.codec.http.HttpVersion._
Expand Down
1 change: 0 additions & 1 deletion finagle-example/src/main/scala/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ scala_library(name='scala',
'finagle/finagle-cacheresolver',
'finagle/finagle-core',
'finagle/finagle-example/src/main/thrift:thrift-scala',
'finagle/finagle-http',
'finagle/finagle-httpx',
'finagle/finagle-kestrel',
'finagle/finagle-memcached',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.twitter.finagle.example.http

import com.twitter.finagle.builder.ClientBuilder
import com.twitter.finagle.http.Http
import com.twitter.finagle.httpx._
import java.net.InetSocketAddress
import org.jboss.netty.handler.codec.http._
import org.jboss.netty.handler.codec.http.HttpResponseStatus._
import com.twitter.finagle.{Service, SimpleFilter}
import com.twitter.io.Charsets
import com.twitter.util.Future
Expand All @@ -21,22 +19,22 @@ object HttpClient {
/**
* Convert HTTP 4xx and 5xx class responses into Exceptions.
*/
class HandleErrors extends SimpleFilter[HttpRequest, HttpResponse] {
def apply(request: HttpRequest, service: Service[HttpRequest, HttpResponse]) = {
class HandleErrors extends SimpleFilter[Request, Response] {
def apply(request: Request, service: Service[Request, Response]) = {
// flatMap asynchronously responds to requests and can "map" them to both
// success and failure values:
service(request) flatMap { response =>
response.getStatus match {
case OK => Future.value(response)
case FORBIDDEN => Future.exception(new InvalidRequest)
case _ => Future.exception(new Exception(response.getStatus.getReasonPhrase))
response.status match {
case Status.Ok => Future.value(response)
case Status.Forbidden => Future.exception(new InvalidRequest)
case _ => Future.exception(new Exception(response.status.reason))
}
}
}
}

def main(args: Array[String]) {
val clientWithoutErrorHandling: Service[HttpRequest, HttpResponse] = ClientBuilder()
val clientWithoutErrorHandling: Service[Request, Response] = ClientBuilder()
.codec(Http())
.hosts(new InetSocketAddress(8080))
.hostConnectionLimit(1)
Expand All @@ -45,7 +43,7 @@ object HttpClient {
val handleErrors = new HandleErrors

// compose the Filter with the client:
val client: Service[HttpRequest, HttpResponse] = handleErrors andThen clientWithoutErrorHandling
val client: Service[Request, Response] = handleErrors andThen clientWithoutErrorHandling

println("))) Issuing two requests in parallel: ")
val request1 = makeAuthorizedRequest(client)
Expand All @@ -57,19 +55,18 @@ object HttpClient {
}
}

private[this] def makeAuthorizedRequest(client: Service[HttpRequest, HttpResponse]) = {
val authorizedRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/")
authorizedRequest.headers().add(HttpHeaders.Names.AUTHORIZATION, "open sesame")
private[this] def makeAuthorizedRequest(client: Service[Request, Response]) = {
val authorizedRequest = Request(Version.Http11, Method.Get, "/")
authorizedRequest.headerMap.add(Fields.Authorization, "open sesame")

client(authorizedRequest) onSuccess { response =>
val responseString = response.getContent.toString(Charsets.Utf8)
val responseString = response.contentString
println("))) Received result for authorized request: " + responseString)
}
}

private[this] def makeUnauthorizedRequest(client: Service[HttpRequest, HttpResponse]) = {
val unauthorizedRequest = new DefaultHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, "/")
private[this] def makeUnauthorizedRequest(client: Service[Request, Response]) = {
val unauthorizedRequest = Request(Version.Http11, Method.Get, "/")

// use the onFailure callback since we convert HTTP 4xx and 5xx class
// responses to Exceptions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.twitter.finagle.example.http

import com.twitter.finagle.builder.{Server, ServerBuilder}
import com.twitter.finagle.httpx._
import com.twitter.finagle.{Service, SimpleFilter}
import org.jboss.netty.handler.codec.http._
import org.jboss.netty.handler.codec.http.HttpResponseStatus._
import org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1
import org.jboss.netty.buffer.ChannelBuffers.copiedBuffer
import com.twitter.io.Charsets.Utf8
import com.twitter.util.Future
import java.net.InetSocketAddress
import com.twitter.finagle.builder.{Server, ServerBuilder}
import com.twitter.finagle.http.Http

/**
* This example demonstrates a sophisticated HTTP server that handles exceptions
Expand All @@ -22,19 +18,19 @@ object HttpServer {
* A simple Filter that catches exceptions and converts them to appropriate
* HTTP responses.
*/
class HandleExceptions extends SimpleFilter[HttpRequest, HttpResponse] {
def apply(request: HttpRequest, service: Service[HttpRequest, HttpResponse]) = {
class HandleExceptions extends SimpleFilter[Request, Response] {
def apply(request: Request, service: Service[Request, Response]) = {

// `handle` asynchronously handles exceptions.
service(request) handle { case error =>
val statusCode = error match {
case _: IllegalArgumentException =>
FORBIDDEN
Status.Forbidden
case _ =>
INTERNAL_SERVER_ERROR
Status.InternalServerError
}
val errorResponse = new DefaultHttpResponse(HTTP_1_1, statusCode)
errorResponse.setContent(copiedBuffer(error.getStackTraceString, Utf8))
val errorResponse = Response(Version.Http11, statusCode)
errorResponse.contentString = error.getStackTraceString

errorResponse
}
Expand All @@ -45,9 +41,9 @@ object HttpServer {
* A simple Filter that checks that the request is valid by inspecting the
* "Authorization" header.
*/
class Authorize extends SimpleFilter[HttpRequest, HttpResponse] {
def apply(request: HttpRequest, continue: Service[HttpRequest, HttpResponse]) = {
if ("open sesame" == request.headers().get(HttpHeaders.Names.AUTHORIZATION)) {
class Authorize extends SimpleFilter[Request, Response] {
def apply(request: Request, continue: Service[Request, Response]) = {
if (Some("open sesame") == request.headerMap.get(Fields.Authorization)) {
continue(request)
} else {
Future.exception(new IllegalArgumentException("You don't know the secret"))
Expand All @@ -58,10 +54,10 @@ object HttpServer {
/**
* The service itself. Simply echos back "hello world"
*/
class Respond extends Service[HttpRequest, HttpResponse] {
def apply(request: HttpRequest) = {
val response = new DefaultHttpResponse(HTTP_1_1, OK)
response.setContent(copiedBuffer("hello world", Utf8))
class Respond extends Service[Request, Response] {
def apply(request: Request) = {
val response = Response(Version.Http11, Status.Ok)
response.contentString = "hello world"
Future.value(response)
}
}
Expand All @@ -72,7 +68,7 @@ object HttpServer {
val respond = new Respond

// compose the Filters and Service together:
val myService: Service[HttpRequest, HttpResponse] = handleExceptions andThen authorize andThen respond
val myService: Service[Request, Response] = handleExceptions andThen authorize andThen respond

val server: Server = ServerBuilder()
.codec(Http())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package com.twitter.finagle.example.stress
import com.google.common.util.concurrent.AtomicLongMap
import com.twitter.finagle.Service
import com.twitter.finagle.builder.ClientBuilder
import com.twitter.finagle.http.Http
import com.twitter.finagle.httpx.{Http, Method, Request, Response, Status, Version}
import com.twitter.finagle.stats.SummarizingStatsReceiver
import com.twitter.util.{Stopwatch, Future}
import java.net.{InetSocketAddress, URI}
import java.util.concurrent.atomic.AtomicInteger
import org.jboss.netty.handler.codec.http._
import scala.collection.JavaConverters._

/**
Expand All @@ -23,14 +22,14 @@ object Stress {
val totalRequests = args(2).toInt

val errors = new AtomicInteger(0)
val responses = AtomicLongMap.create[HttpResponseStatus]()
val responses = AtomicLongMap.create[Status]()

val request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getPath)
HttpHeaders.setHost(request, uri.getHost)
val request = Request(Version.Http11, Method.Get, uri.getPath)
request.headerMap.set("Host", uri.getHost)

val statsReceiver = new SummarizingStatsReceiver

val client: Service[HttpRequest, HttpResponse] = ClientBuilder()
val client: Service[Request, Response] = ClientBuilder()
.codec(Http())
.hosts(new InetSocketAddress(uri.getHost, uri.getPort))
.hostConnectionCoresize(concurrency)
Expand All @@ -44,7 +43,7 @@ object Stress {
val requests = Future.parallel(concurrency) {
Future.times(totalRequests / concurrency) {
client(request) onSuccess { response =>
responses.incrementAndGet(response.getStatus)
responses.incrementAndGet(response.status)
} handle { case e =>
errors.incrementAndGet()
} ensure {
Expand Down
14 changes: 0 additions & 14 deletions finagle-http/BUILD

This file was deleted.

2 changes: 0 additions & 2 deletions finagle-http/GROUPS

This file was deleted.

5 changes: 0 additions & 5 deletions finagle-http/OWNERS

This file was deleted.

18 changes: 0 additions & 18 deletions finagle-http/src/main/scala/BUILD

This file was deleted.

Loading

0 comments on commit 47bf5da

Please sign in to comment.