From a24e0dee836eb17b08064a8173824e29c0ceab28 Mon Sep 17 00:00:00 2001 From: BenWhitehead Date: Mon, 2 Feb 2015 22:27:25 -0800 Subject: [PATCH] Generify all locations where request used to be constrained to HttpRequest but no longer is with finch 0.4.0 --- README.md | 2 +- build.sbt | 2 +- .../github/benwhitehead/finch/FinchServer.scala | 16 +++++++++------- .../io/github/benwhitehead/finch/package.scala | 2 +- .../benwhitehead/finch/request/package.scala | 6 +++--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 77c1b31..5b0d220 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,6 @@ Compiled for scala 2.10 and 2.11 resolvers += "BenWhitehead" at "http://storage.googleapis.com/benwhitehead_me/maven/public" libraryDependencies ++= Seq( - "io.github.benwhitehead.finch" %% "finch-server" % "0.7.0" + "io.github.benwhitehead.finch" %% "finch-server" % "0.7.1" ) ``` diff --git a/build.sbt b/build.sbt index add1cce..c6070c3 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ organization := "io.github.benwhitehead.finch" name := "finch-server" -version := "0.7.0" +version := "0.7.1" crossScalaVersions := Seq("2.10.3", "2.11.4") diff --git a/src/main/scala/io/github/benwhitehead/finch/FinchServer.scala b/src/main/scala/io/github/benwhitehead/finch/FinchServer.scala index e2b3ebd..b379911 100644 --- a/src/main/scala/io/github/benwhitehead/finch/FinchServer.scala +++ b/src/main/scala/io/github/benwhitehead/finch/FinchServer.scala @@ -18,7 +18,6 @@ package io.github.benwhitehead.finch import com.twitter.app.App import com.twitter.conversions.storage.intToStorageUnitableWholeNumber import com.twitter.finagle._ -import com.twitter.finagle.httpx.service.NotFoundService import com.twitter.finagle.netty3.Netty3ListenerTLSConfig import com.twitter.finagle.ssl.Ssl import com.twitter.server.Lifecycle.Warmup @@ -26,12 +25,13 @@ import com.twitter.server.{Admin, AdminHttpServer, Lifecycle, Stats} import com.twitter.util.Await import io.finch._ import io.github.benwhitehead.finch.filters._ +import io.github.benwhitehead.finch.request.DelegateService import java.io.{File, FileNotFoundException, FileOutputStream} import java.lang.management.ManagementFactory import java.net.{InetSocketAddress, SocketAddress} -trait FinchServer[Request <: HttpRequest] extends App +trait FinchServer[Request] extends App with SLF4JLogging with AdminHttpServer with Admin @@ -134,10 +134,10 @@ trait FinchServer[Request <: HttpRequest] extends App } def getService(serviceName: String): Service[HttpRequest, HttpResponse] = { - new StatsFilter(serviceName) andThen - AccessLog andThen - errorHandler andThen - filter andThen + new StatsFilter(serviceName) ! + AccessLog ! + errorHandler ! + filter ! (endpoint orElse NotFound) } @@ -148,7 +148,9 @@ trait FinchServer[Request <: HttpRequest] extends App } val NotFound = new Endpoint[Request, HttpResponse] { - lazy val underlying = new NotFoundService[Request] + lazy val underlying = DelegateService { + io.finch.response.NotFound() + } def route = { case _ => underlying } } diff --git a/src/main/scala/io/github/benwhitehead/finch/package.scala b/src/main/scala/io/github/benwhitehead/finch/package.scala index 2ed322b..52a407f 100644 --- a/src/main/scala/io/github/benwhitehead/finch/package.scala +++ b/src/main/scala/io/github/benwhitehead/finch/package.scala @@ -23,7 +23,7 @@ import io.finch.response.BadRequest package object finch { - trait TypedEndpoint[Request <: HttpRequest] extends Endpoint[Request, HttpResponse] + trait TypedEndpoint[Request] extends Endpoint[Request, HttpResponse] trait HttpEndpoint extends TypedEndpoint[HttpRequest] class BadRequest extends Exception // 400 diff --git a/src/main/scala/io/github/benwhitehead/finch/request/package.scala b/src/main/scala/io/github/benwhitehead/finch/request/package.scala index ee6eb75..ef8db46 100644 --- a/src/main/scala/io/github/benwhitehead/finch/request/package.scala +++ b/src/main/scala/io/github/benwhitehead/finch/request/package.scala @@ -7,19 +7,19 @@ import io.finch.request.RequestReader package object request { - class ReaderService[Req <: HttpRequest, T](reader: RequestReader[T]) extends Service[Req, T] { + class ReaderService[Req, T](reader: RequestReader[T])(implicit view: (Req) => HttpRequest) extends Service[Req, T] { final def apply(request: Req): Future[T] = reader(request) } object ReaderService { /* TODO: See if it's possible to improve the type info here so that SimpleReaderService isn't needed */ - def apply[Req <: HttpRequest, T](f: => RequestReader[T]) = new ReaderService[Req, T](f) + def apply[Req, T](f: => RequestReader[T])(implicit view: (Req) => HttpRequest) = new ReaderService[Req, T](f) } object SimpleReaderService { def apply[T](f: => RequestReader[T]) = new ReaderService[HttpRequest, T](f) } object DelegateService { - def apply[Req <: HttpRequest, T](f: => T) = new Service[Req, T] { + def apply[Req, T](f: => T) = new Service[Req, T] { def apply(req: Req): Future[T] = { f.toFuture }