markusthoemmes commented on a change in pull request #2218: Port Controller
from Spray to Akka
URL:
https://github.com/apache/incubator-openwhisk/pull/2218#discussion_r127038196
##########
File path: common/scala/src/main/scala/whisk/http/BasicHttpService.scala
##########
@@ -19,56 +19,64 @@ package whisk.http
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps
+import scala.concurrent.Await
+import scala.collection.immutable.Seq
+import scala.concurrent.ExecutionContext.Implicits.global
import akka.actor.Actor
-import akka.actor.ActorContext
import akka.actor.ActorSystem
import akka.actor.Props
import akka.event.Logging
-import akka.io.IO
import akka.japi.Creator
-import akka.pattern.ask
import akka.util.Timeout
-import spray.can.Http
-import spray.http.ContentType
-import spray.http.HttpEntity
-import spray.http.HttpRequest
-import spray.http.HttpResponse
-import spray.http.MediaTypes.`text/plain`
-import spray.httpx.SprayJsonSupport.sprayJsonMarshaller
-import spray.httpx.marshalling
-import spray.httpx.marshalling.ToResponseMarshallable.isMarshallable
-import spray.routing.AuthenticationFailedRejection
-import spray.routing.Directive.pimpApply
-import spray.routing.Directives
-import spray.routing.HttpService
-import spray.routing.RejectionHandler
-import spray.routing.Route
-import spray.routing.directives.DebuggingDirectives
-import spray.routing.directives.LogEntry
-import spray.routing.directives.LoggingMagnet.forMessageFromFullShow
+import akka.http.scaladsl.server.Directives
+import akka.http.scaladsl.server.directives.DebuggingDirectives
+import akka.http.scaladsl.server.directives.LogEntry
+import akka.http.scaladsl.model.HttpResponse
+import akka.http.scaladsl.server.Route
+import akka.http.scaladsl.model.HttpRequest
+import akka.http.scaladsl.model._
+import akka.http.scaladsl.server.RejectionHandler
+import akka.http.scaladsl.server.UnacceptedResponseContentTypeRejection
+import akka.http.scaladsl.marshalling.Marshal
+import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
+import akka.http.scaladsl.server.RouteResult.Rejected
+
import whisk.common.LogMarker
import whisk.common.LogMarkerToken
import whisk.common.Logging
import whisk.common.LoggingMarkers
import whisk.common.TransactionCounter
import whisk.common.TransactionId
+import akka.stream.ActorMaterializer
/**
- * This trait extends the spray HttpService trait with logging and transaction
counting
+ * This trait extends the Akka Directives and Actor with logging and
transaction counting
* facilities common to all OpenWhisk REST services.
*/
-trait BasicHttpService extends HttpService with TransactionCounter {
+trait BasicHttpService extends Directives with Actor with TransactionCounter {
/**
* Gets the actor context.
*/
- implicit def actorRefFactory: ActorContext
+ //implicit def actorRefFactory: ActorContext
/**
* Gets the logging
*/
implicit def logging: Logging
+ implicit val mat = ActorMaterializer()
+
+ /** Rejection handler to terminate connection on a bad request. Delegates
to Akka handler. */
+ implicit def customRejectionHandler(implicit transid: TransactionId) =
+ RejectionHandler.default.mapRejectionResponse {
+ case resp @ HttpResponse(_, _, ent: HttpEntity.Strict, _) =>
+ val timeout = 1.second
+ val marshalledError =
Marshal(ErrorResponse(ent.data.utf8String, transid)).to[ResponseEntity]
+ val marshalledRes =
Await.result(marshalledError.flatMap(_.toStrict(timeout)), timeout)
Review comment:
Blocking here could lead us to terrible performance, why is it needed?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services