On the reference of this question, I try the below code in Scala:
import net.sf.uadetector._
def check = Action { implicit request =>
println(request.headers)
var parser = UADetectorServiceFactory.getOnlineUpdatingParser();
println(parser)
val agent = parser.parse(request.headers.get("User-Agent").getOrElse(""))
println(agent)
val which = agent.getUserAgentType(); // this can be ROBOT, BROWSER, etc.
println(which)
Ok(write(Map("result" -> true)))
}
and
libraryDependencies += "net.sf.uadetector" % "uadetector-core" %
"0.9.16"
but I am getting an error:
not found: value UADetectorServiceFactory
var parser = UADetectorServiceFactory.getOnlineUpdatingParser();
^
Am I missing something?
did i am missing something?
Yes, you have imported everything from net.sf.uadetector
package, but UADetectorServiceFactory resides in net.sf.uadetector.service
Add
import net.sf.uadetector.service.UADetectorServiceFactory
or
import net.sf.uadetector.service._
And compilation should be okay
did i am missing something?
Yes, I got what I am missing, but getUserAgentType
is not still working so I used getType()
in place of that.
import net.sf.uadetector.service._
import net.sf.uadetector._
def check = Action { implicit request =>
var parser = UADetectorServiceFactory.getOnlineUpdatingParser()
println(parser)
val agent = parser.parse(request.headers.get("User-Agent").getOrElse(""))
println(agent)
val which = agent.getType()
println(which)
Ok(write(Map("result" -> true)))
}
and needed two library dependencies to run the code above:
"net.sf.uadetector" % "uadetector-core" % "0.9.16",
"net.sf.uadetector" % "uadetector-resources" % "2013.04",