dubeejw commented on a change in pull request #2218: Port Controller from Spray
to Akka
URL:
https://github.com/apache/incubator-openwhisk/pull/2218#discussion_r130371088
##########
File path: common/scala/src/main/scala/whisk/http/BasicHttpService.scala
##########
@@ -86,39 +86,57 @@ trait BasicHttpService extends HttpService with
TransactionCounter {
*/
def loglevelForRoute(route: String): Logging.LogLevel = Logging.InfoLevel
+ /** Rejection handler to terminate connection on a bad request. Delegates
to Akka handler. */
+ val prioritizeRejections = recoverRejections { rejections =>
+ val priorityRejection = rejections.find {
+ case rejection: UnacceptedResponseContentTypeRejection => true
+ case _ => false
+ }
+
+ priorityRejection.map(rejection =>
Rejected(Seq(rejection))).getOrElse(Rejected(rejections))
+ }
+
+ val toStrict = mapInnerRoute { innerRoute =>
+ extractRequest { req =>
+ onSuccess(req.toStrict(1.second)) { strictReq =>
+ mapRequest(_ => strictReq) {
+ innerRoute
+ }
+ }
+ }
+ }
+
/**
* Receives a message and runs the router.
*/
- def receive = runRoute(
+ def route: Route = {
assignId { implicit transid =>
- DebuggingDirectives.logRequest(logRequestInfo _) {
- DebuggingDirectives.logRequestResponse(logResponseInfo _) {
- routes
+ handleRejections(customRejectionHandler) {
+ prioritizeRejections {
+ DebuggingDirectives.logRequest(logRequestInfo _) {
+ DebuggingDirectives.logRequestResult(logResponseInfo
_) {
+ toStrict {
+ routes
+ }
+ }
+ }
}
}
- })
+ }
+ }
+
+ def receive = {
+ case _ =>
+ }
/** Assigns transaction id to every request. */
protected val assignId = extract(_ => transid())
- /** Rejection handler to terminate connection on a bad request. Delegates
to Spray handler. */
-
- protected def customRejectionHandler(implicit transid: TransactionId) =
RejectionHandler {
- case rejections => {
- logging.info(this, s"[REJECT] $rejections")
- rejections match {
- case AuthenticationFailedRejection(cause, challengeHeaders) ::
_ =>
-
BasicHttpService.customRejectionHandler.apply(rejections.takeRight(1))
- case _ =>
BasicHttpService.customRejectionHandler.apply(rejections)
- }
- }
- }
-
/** Generates log entry for every request. */
protected def logRequestInfo(req: HttpRequest)(implicit tid:
TransactionId): LogEntry = {
val m = req.method.toString
val p = req.uri.path.toString
- val q = req.uri.query.toString
+ val q = req.uri.query().toString
Review comment:
Seems that the code won't compile without the parentheses.
```
missing argument list for method query in class Uri
Unapplied methods are only converted to functions when a function type is
expected.
You can make this conversion explicit by writing `query _` or `query(_,_)`
instead of `query`.
val query = ctx.request.uri.query
```
----------------------------------------------------------------
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