我今天將Play應用程序從2.5升級到2.6,並且ActionBuilder出現問題。文檔狀態:Play 2.6 ActionBuilder
Scala ActionBuilder trait已被修改爲將body的類型指定爲類型參數,並添加抽象解析器成員作爲默認身體解析器。您將需要修改您的ActionBuilder並直接傳遞正文解析器。
可悲的是我還沒有發現任何例子,我不知道如何解決這個問題:
class AuthenticatedRequest[A](val token: ProfileTokenData, request: Request[A]) extends WrappedRequest[A](request)
trait Secured {
object SetExtractor {
def unapplySeq[T](s: Set[T]): Option[Seq[T]] = Some(s.toSeq)
}
def Authenticated = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] = {
request.jwtSession.claimData.asOpt[JWTToken] match {
case Some(token) => block(new AuthenticatedRequest(ProfileTokenData(null, token.sub, AuthRole.None), request)).map(_.refreshJwtSession(request))
case _ => Future.successful(Unauthorized)
}
}
}
def Registered = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] =
this.processJWTToken(request, block, Seq(AuthRole.Admin, AuthRole.Customer, AuthRole.Registered))
}
def Customer = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] =
this.processJWTToken(request, block, Seq(AuthRole.Admin, AuthRole.Customer))
}
def Admin = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] =
this.processJWTToken(request, block, Seq(AuthRole.Admin))
}
}
有誰知道whic BodyParser我要傳遞的第二個參數?