Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bb22a60
Showing
4 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Todo: | ||
|
||
1. Implementar o verificador de assinatura como filtro | ||
2. Criar projeto bill_it-http para guardar o pacote http | ||
3. Acesso ao reposit�rio de chaves para obter identidade do usu�rio assim como chave privada (atende todo 1) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name := "hellofinagle" | ||
|
||
version := "1.0" | ||
|
||
scalaVersion := "2.9.1" | ||
|
||
fork in run := true | ||
|
||
resolvers ++= Seq("Twitter Repo" at "http://maven.twttr.com/", | ||
"Scala Tools Releases" at "https://repository.jboss.org/nexus/content/repositories/scala-tools-releases") | ||
|
||
libraryDependencies ++= Seq("com.twitter" % "finagle-core" % "1.9.2", | ||
"com.twitter" % "finagle-http" % "1.9.2", | ||
"com.twitter" % "util" % "1.11.8", | ||
"org.mockito" % "mockito-all" % "1.8.5" % "test" withSources(), | ||
"org.scala-tools.testing" %% "specs" % "1.6.9" % "test" withSources()) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resolvers += Classpaths.typesafeResolver | ||
|
||
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse" % "1.4.0") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package codemountain.finagle | ||
|
||
|
||
import org.jboss.netty.handler.codec.http.HttpRequest | ||
import com.twitter.util.Future | ||
import org.jboss.netty.handler.codec.http.DefaultHttpResponse | ||
import org.jboss.netty.util.CharsetUtil.UTF_8 | ||
import com.twitter.finagle.http.Status.{ Ok, MethodNotAllowed } | ||
import com.twitter.finagle.Service | ||
import org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1 | ||
import org.jboss.netty.handler.codec.http.HttpResponse | ||
import org.jboss.netty.buffer.ChannelBuffers.copiedBuffer | ||
import com.twitter.finagle.builder.ServerBuilder | ||
import com.twitter.finagle.http.Http | ||
import com.twitter.finagle.builder.Server | ||
import java.net.InetSocketAddress | ||
import com.twitter.finagle.http.Response | ||
import com.twitter.finagle.http.Request | ||
import com.twitter.finagle.http.path.Path | ||
import com.twitter.finagle.http.path._ | ||
import com.twitter.finagle.http.RichHttp | ||
import com.twitter.finagle.http.filter.ExceptionFilter | ||
import org.jboss.netty.handler.codec.http.HttpMethod | ||
import com.twitter.finagle.http.Method._ | ||
|
||
object Helpers { | ||
val methNotAllwd: PartialFunction[(HttpMethod, Request), Future[Response]] = { | ||
case (_, request) => | ||
val response = request.response | ||
response.status = MethodNotAllowed | ||
Future.value(response) | ||
} | ||
|
||
def ~~(body: PartialFunction[(HttpMethod, Request), Future[Response]]) = { | ||
new Service[Request, Response] { | ||
def apply(request: Request): Future[Response] = { | ||
|
||
val pf: PartialFunction[(HttpMethod, Request), Future[Response]] = { | ||
body orElse methNotAllwd | ||
} | ||
pf(request.method, request) | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
class SimpleService extends Service[HttpRequest, HttpResponse] { | ||
def apply(request: HttpRequest): Future[HttpResponse] = { | ||
val response = new DefaultHttpResponse(HTTP_1_1, Ok) | ||
Future.value(response) | ||
} | ||
} | ||
|
||
class AdvancedService extends Service[Request, Response] { | ||
def apply(request: Request): Future[Response] = { | ||
(Path(request.path)) match { | ||
case Root / "user" / Integer(id) => | ||
val response = request.response | ||
response.setContentString("The user id is %d\n\n" format id) | ||
Future.value(response) | ||
} | ||
} | ||
} | ||
|
||
object Simple { | ||
|
||
def main(args: Array[String]) { | ||
val service = new SimpleService | ||
val server: Server = ServerBuilder() | ||
.codec(new Http) | ||
.bindTo(new InetSocketAddress(8099)) | ||
.name("simple") | ||
.build(service) | ||
} | ||
|
||
} | ||
|
||
object Advanced { | ||
def main(args: Array[String]) { | ||
val advancedService = new AdvancedService | ||
|
||
val serve: Server = ServerBuilder() | ||
.codec(new RichHttp[Request](new Http())) | ||
.bindTo(new InetSocketAddress(8099)) | ||
.name("advanced") | ||
.build(ExceptionFilter andThen advancedService) | ||
|
||
} | ||
} | ||
|
||
object SuperAdvanced { | ||
import Helpers._ | ||
|
||
val superAd = ~~ { | ||
case (Get, request) => | ||
(Path(request.path)) match { | ||
case Root / "user" / Integer(id) => | ||
val response = request.response | ||
response.setContentString("The user id is %d\n\n" format id) | ||
Future.value(response) | ||
} | ||
} | ||
|
||
val serve: Server = ServerBuilder() | ||
.codec(new RichHttp[Request](new Http())) | ||
.bindTo(new InetSocketAddress(8099)) | ||
.name("suprAd") | ||
.build(ExceptionFilter andThen superAd) | ||
|
||
} |