我正在尝试将我的WebSocket控制器代码迁移到Play 2.5并遵循ScalaWebSockets处的说明。我的路由配置出现编译错误。 我的WebSocket控制器代码如下
package controllers
import akka.actor.ActorSystem
import akka.stream.Materializer
import com.google.inject.Inject
import utils.silhouette.{AuthenticationController, AuthenticationEnvironment}
// This is needed to implicitly provide the Scala ActorSystem
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc._
import play.api.libs.streams._
import scala.concurrent.Future
abstract class IntegrationMonitorProvider @Inject() (implicit system: ActorSystem,
materializer: Materializer)
extends AuthenticationController{
def monitor = WebSocket.acceptOrResult[String, String] { request =>
implicit val req = Request(request, AnyContentAsEmpty)
SecuredRequestHandler { securedRequest =>
Future.successful(HandlerResult(Ok, Some(securedRequest.identity)))
}.map {
case HandlerResult(r, Some(user)) =>
Right(ActorFlow.actorRef(IntegrationMonitor.props(req.session.get("integration").get.toLong) _))
case HandlerResult(r, None) => Left(r)
}
}
}
打算支持WebSocket的各个控制器应该扩展它。这种模式在Play 2.4中运行良好,这个控制器代码也在编译。 但是我的路由器配置无法编译并出现以下错误
路由:56:方法申请参数不足:(request:play.api.mvc.RequestHeader)scala.concurrent.Future [play.api.mvc.Result,akka.stream.scaladsl.Flow [play]特征WebSocket中的.api.http.websocket.Message,play.api.http.websocket.Message,_]]]。 未指定的值参数请求。
Read from stdout:
GET /sample/monitor controllers.sample.Connection.monitor()
扩展IntegrationMonitorProvider的控制器如下所示
package controllers.sample
import javax.inject.Inject
import akka.actor.ActorSystem
import akka.stream.Materializer
import controllers.{IntegrationMonitor, IntegrationMonitorProvider}
import modules.oauth.{Credential, Metadata, TokenReader}
import play.Logger
import play.api.i18n.MessagesApi
import play.api.libs.json.JsResult
import play.api.mvc.{AnyContent, BodyParsers}
import utils.silhouette.{AuthenticationController, AuthenticationEnvironment}
// This is needed to implicitly provide the Scala ActorSystem
import play.api.libs.concurrent.Execution.Implicits._
import scala.concurrent.Future
class Connection @Inject()(val env: AuthenticationEnvironment, val messagesApi: MessagesApi)
(implicit system: ActorSystem,
materializer: Materializer)
extends IntegrationMonitorProvider with UrlCreator with DataReader {...
感谢您的任何帮助。
答案 0 :(得分:1)
我可以通过删除routes
即,
GET /sample/monitor controllers.sample.Connection.monitor
而不是
GET /sample/monitor controllers.sample.Connection.monitor()