tanin47
(Tanin Na Nakorn)
1
For my use case, I want to get all the links in the email and check them against Playframework’s conf/routes
.
I wonder if there’s a function within Playframework’s library that I can use for, given a path, verifying that the path is valid.
Thank you
tanin47
(Tanin Na Nakorn)
2
Well, I just had time to figure it out, so let me post it here.
We can inject router.Routes
and use:
// URLEncodedUtils is already included by Play
import org.apache.http.client.utils.URLEncodedUtils
val url = new URL(fullUrl)
val params = URLEncodedUtils.parse(url.toURI,"UTF-8").asScala.groupBy(_.getName).mapValues(_.map(_.getValue).toList)
val handlerOpt = playRoute.get.routes.lift.apply(new RequestHeader {
override def connection: RemoteConnection = ???
override def method: String = "GET"
override def version: String = ???
override def headers: Headers = ???
override def attrs: TypedMap = ???
override def target: RequestTarget = new RequestTarget {
override def uri: URI = ???
override def uriString: String = ???
override def queryMap: Map[String, Seq[String]] = params
override def path: String = url.getPath.stripSuffix("/")
}
})
It will return Option[Handler]
. If it is None
, then it is an invalid path.