Permalink
Browse files

cleanup ResponseConverter. now refactored to companion object Request…

…Adapter
  • Loading branch information...
1 parent 7143d02 commit 2c510b9f10cee0009e654197113e7e79d58978e4 Christopher Burnett committed Nov 20, 2012
@@ -26,27 +26,26 @@ class AppService(controllers: ControllerCollection)
def apply(rawRequest: FinagleRequest) = {
val adaptedRequest = RequestAdapter(rawRequest)
- val responseConverter = new FinatraResponseConverter
try {
attemptRequest(rawRequest)
} catch {
case e: Exception =>
logger.error(e, "Internal Server Error")
adaptedRequest.error = Some(e)
- responseConverter(controllers.errorHandler(adaptedRequest))
+ ResponseAdapter(controllers.errorHandler(adaptedRequest))
}
}
def attemptRequest(rawRequest: FinagleRequest) = {
val adaptedRequest = RequestAdapter(rawRequest)
- val responseConverter = new FinatraResponseConverter
+
controllers.dispatch(rawRequest) match {
case Some(response) =>
response.asInstanceOf[Future[FinagleResponse]]
case None =>
- responseConverter(controllers.notFoundHandler(adaptedRequest))
+ ResponseAdapter(controllers.notFoundHandler(adaptedRequest))
}
}
@@ -18,8 +18,15 @@ package com.twitter.finatra
import com.twitter.util.Future
import com.twitter.finagle.http.{Response => FinagleResponse}
+object ResponseAdapter {
+ def apply(resp: Future[Response]) = {
+ val adapter = new FinatraResponseConverter
+ adapter(resp)
+ }
+}
+
class FinatraResponseConverter {
- def apply(resp: Future[Response]):Future[FinagleResponse] = {
+ def apply(resp: Future[Response]): Future[FinagleResponse] = {
resp.map(_.build)
}
}

0 comments on commit 2c510b9

Please sign in to comment.