Permalink
Browse files

cleanup ResponseConverter. now refactored to companion object Request…

…Adapter
  • Loading branch information...
1 parent 7143d02 commit e51dce94e2eb44aaa1086c4274aeec43c5459f4c 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))
}
}
@@ -23,8 +23,6 @@ import collection.mutable.ListBuffer
class Controller(statsReceiver: StatsReceiver = NullStatsReceiver) extends Logging {
- val responseConverter = new FinatraResponseConverter
-
val routes = new RouteVector[(HttpMethod, PathPattern, Request => Future[Response])]
var notFoundHandler: Option[(Request) => Future[Response]] = None
@@ -62,7 +60,7 @@ class Controller(statsReceiver: StatsReceiver = NullStatsReceiver) extends Loggi
val req = RequestAdapter(request)
findRouteAndMatch(req, method) match {
case Some((method, pattern, callback)) =>
- Some(responseConverter(callback(req))).asInstanceOf[Option[FinagleResponse]]
+ Some(ResponseAdapter(callback(req))).asInstanceOf[Option[FinagleResponse]]
case None => orCallback(request)
}
}
@@ -1,25 +0,0 @@
-/**
- * Copyright (C) 2012 Twitter Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.twitter.finatra
-
-import com.twitter.util.Future
-import com.twitter.finagle.http.{Response => FinagleResponse}
-
-class FinatraResponseConverter {
- def apply(resp: Future[Response]):Future[FinagleResponse] = {
- resp.map(_.build)
- }
-}

0 comments on commit e51dce9

Please sign in to comment.