playframework-2.1

play framework 2.1 - scheduling async tasks

左心房为你撑大大i 提交于 2019-11-27 21:18:46
问题 In play's 2.0.x doc you can see how to schedule asynchronous tasks: http://www.playframework.org/documentation/2.0.4/ScalaAkka Akka.system.scheduler.schedule(0 seconds, 30 minutes, testActor, "tick") How can you achieve the same thing withthe recently releades Play 2.1??? The whole akka API seems to have changed... I've checked: https://github.com/playframework/Play20/wiki/Highlights https://github.com/playframework/Play20/wiki/Migration and also http://doc.akka.io/docs/akka/2.1.0-RC1/project

Play Framework 2.1: Use play.api.Configuration in Build.scala

↘锁芯ラ 提交于 2019-11-27 19:31:26
In the top answer to Play Framework 2: Read the application version defined in Build.scala it's suggested that the application version number be specified in conf/application.conf and loaded in Build.scala through play.api.Configuration . I'm using Play 2.1-RC2 and getting the following error message when building: [error] [...]/project/Build.scala:7: object Configuration is not a member of package play.api [error] val conf = play.api.Configuration.load(new File(".")) I think this might be caused by the fact that with Play 2.1 build dependencies have to be specified as plugins to SBT, and play

Scala play http filters: how to find the request body

最后都变了- 提交于 2019-11-27 18:05:15
问题 I'm trying to write a filter similar to the simple one described in http://www.playframework.com/documentation/2.1.1/ScalaHttpFilters but I need to access the request body. The documentation below states that "when we invoke next, we get back an Iteratee. You could wrap this in an Enumeratee to do some transformations if you wished." I'm trying to figure out how to wrap the Iteratee so I can get the request body as a string within the filter so I can log that as well. 回答1: I spent some time

How to execute DDL only when tables don't exist?

匆匆过客 提交于 2019-11-27 17:51:44
问题 I'm using Slick 1.0 with Play Framework 2.1 and MySQL. I'd like to control the ddl table creation so that it only takes place if the tables don't exist. That is to say that the tables should only get created the first time I start play. How to do it in Slick? 回答1: Since I like to control the creation of my tables individually and keep it DRY, I just tend to add a utility method to my apps: def createIfNotExists(tables: TableQuery[_ <: Table[_]]*)(implicit session: Session) { tables foreach

How do I specify a config file with sbt 0.12.2 for sbt test?

社会主义新天地 提交于 2019-11-27 14:48:36
问题 I have a Play! project with unit tests and I am trying to run tests on my staging environment using sbt. Before I upgraded to Play 2.1, when I was using Play 2.0.4 and sbt 0.11.3 I could do $ sbt -Dconfig.file=conf/staging.conf test . Now sbt test seems to use the default application.conf no matter what I specify for -Dconfig.file. sbt start -Dconfig.file=conf/staging.conf still works fine. Is this behavior a bug with sbt 0.12.2 or should I be specifying a config file for running tests in a

How to write Reads[T] and Writes[T] in scala Enumeration (play framework 2.1)

扶醉桌前 提交于 2019-11-27 11:13:34
问题 I'm a little bit lost with the new ScalaJson Feature in Play Framework 2.1. I would like to write Reads and Writes in my Enumeration. Here is my code : object EnumA extends Enumeration { type EnumA = Value val VAL1, VAL2, VAL3 = Value def parse(str:String) : EnumA = { str.toUpperCase() match { case "VAL1" => VAL1 case "VAL2" => VAL2 case "VAL3" => VAL3 case _ => null } }} Any idea ? Thanks. 回答1: Short answer: use something like Play Enumeration Utils. Long answer, instead of putting a Reads

Build.scala, % and %% symbols meaning

爷,独闯天下 提交于 2019-11-27 06:23:51
I'm new to Play! Framework 2.1 (java version) and have no experience with scala. I don't understand what are and what does % and %% mean in Build.scala. I googled about them but couldn't find their meaning. In my Build.scala file I have: "org.hibernate" % "hibernate-entitymanager" % "4.1.0.Final", "com.typesafe" %% "play-plugins-mailer" % "2.1" Why the first line uses a single % symbol and the second one uses two percent symbols %% ? What are they for? Mingyu From the official documentation: http://www.playframework.com/documentation/2.1.1/SBTDependencies Getting the right Scala version with %

Displaying image object from controller in the browser

烂漫一生 提交于 2019-11-27 03:38:03
问题 I use playframework 2.2.1 with Java, I am trying to pass BufferedImage or ByteArray or ByteArrayInputStream to view template in order to display it in browser directly from memory, without saving to server storage. in my view template I request an image: <img src="@{Application.getImage()}"/> my Application controller: public static Result getImage() throws IOException{ BufferedImage image = ImageIO.read(new File("public/img/1.jpg")); //some image manipulations ByteArrayOutputStream baos =

Routes with optional parameter - Play 2.1 Scala

自古美人都是妖i 提交于 2019-11-27 03:22:37
问题 So in Play 2.0 I had this: GET /tasks/add controllers.Tasks.addTask(parentId: Option[Long] = None) GET /tasks/:parentId/add controllers.Tasks.addTask(parentId: Option[Long]) With a controller method like this: def addTask(parentId: Option[Long]) = Action { Ok(views.html.addTask(taskForm, parentId)) } And it was working. As I migrated to 2.1, it seems to complain about these lines with: No URL path binder found for type Option[Long]. Try to implement an implicit PathBindable for this type.

How do I set params for WS.post() in play 2.1 Java

删除回忆录丶 提交于 2019-11-27 02:55:45
问题 I'm trying to perform a post with play.api.libs.ws.WS but I can't figure out how to set the params, my code: Promise<Response> promise = WS.url(Play.application().configuration() .getString("sms.service.url")).post(); .post takes (T body, play.api.http.Writeable wrt, play.api.http.ContentTypeOf ct) but I don't understand how I should pass the params there. The documentation only states: Promise<WS.Response> result = WS.url("http://localhost:9001").post("content"); How do I set the content eg.