Method overloaded value using alternatives: when calling Call.absoluteURL with request
Here is my code
class AuthAction(callbackUri:String) extends ActionBuilder[UserRequest] with ActionRefiner[Request,UserRequest]{
override def refine[A](request: Request[A]): Future[Either[Result,UserRequest[A]]] = {
val redirectUri = routes.Application.callback(None, None).absoluteURL(request)
getUser(request) match {
case Some(user) => Future.successful(Right(new UserRequest(user,request)))
case _ => Future.successful(Left(oauthLogin(callbackUri,redirectUri)(request)))
}
}
}
When I try to compile this code, I get the following error
[error] (secure: Boolean)(implicit request: play.api.mvc.RequestHeader)String <and>
[error] (x$1: play.mvc.Http.Request)String
[error] cannot be applied to (play.api.mvc.Request[A])
[error] val redirectUri = routes.Application.callback(None, None).absoluteURL(request)
is it something to do with implicit parameters? What's going on here?
source to share
He wants play.mvc.Http.Request
and you are trying to move in play.api.mvc.Request
. They are incompatible.
Edit: To answer the question you ask in the comment ... Well, I'm not sure which parameter you are talking about. There are two variants of this function:
The one that seems like you are trying to call -
absoluteURL(request: play.mvc.Http.Request)
- does not take any implicit parameters, it only needs the request
type you want .
The other - absoluteURL(secure: Boolean)(implicit request: play.api.mvc.RequestHeader)
- has an implicit parameter, which is also different from what you have ( RequestHeader
, not request
).
If you declare a variable containing this RequestHeader
as implicit
and it is in scope, you can call the last function without explicitly specifying it:
implicit val requestHeader = createMyRequestHeader()
routes.Application.callback(None, None).absoluteURL(true)
or you can still pass it explicitly, as if you were using a normal parameter (in which case you don't need to declare it implicitly):
routes.Application.callback(None, None).absoluteURL(true)(requestHeader)
source to share