Reputation: 241
I am trying to migrate my WebSocket Controller code to Play 2.5 and have followed instructions at ScalaWebSockets. I am getting compiler errors for my route configurations. My WebSocket controller code is as follows
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)
}
}
}
The individual Controllers intending to support WebSocket is supposed to extend this. This pattern was working fine with Play 2.4, and this controller code is compiling too. But my router config is failing to compile with following errors
routes:56: not enough arguments for method apply: (request: play.api.mvc.RequestHeader)scala.concurrent.Future[Either[play.api.mvc.Result,akka.stream.scaladsl.Flow[play.api.http.websocket.Message, play.api.http.websocket.Message, _]]] in trait WebSocket. Unspecified value parameter request.
Read from stdout:
GET /sample/monitor controllers.sample.Connection.monitor()
The controller that is extending the IntegrationMonitorProvider is as below
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 {...
Appreciate any help with this.
Upvotes: 1
Views: 647
Reputation: 3300
I can fix the problem by removing the parenthesis in routes
That is,
GET /sample/monitor controllers.sample.Connection.monitor
instead of
GET /sample/monitor controllers.sample.Connection.monitor()
Upvotes: 1