playframework-2.3

Unit testing file upload in a controller with Java Play Framework 2.3.x

烂漫一生 提交于 2019-12-04 06:32:44
After working most of the day I feel like I am fairly close to a solution on how to test a controller method which accepts file uploads from JUnit. My juint test code is as follows: Map<String, String> postData = makePostMap(uploadForm); File file = new File("test/resources/shared/uploads/blank.csv"); TemporaryFile temporaryFile = new TemporaryFile(file); MultipartFormData.FilePart filePath = new MultipartFormData.FilePart( "file", "file.csv", new scala.Some<>("text/csv"), temporaryFile); List<MultipartFormData.FilePart> fileParts = Lists.newArrayList(filePath); scala.collection.immutable.Seq

static asset serving from absolute path in play framework 2.3.x

偶尔善良 提交于 2019-12-03 21:31:25
I need to serve image files from an absolute path that is not on the classpath. When I use Assets.at(path, file) , it only searches inside /assets . I have mapped the url onto a controller function like the following: public static Action<AnyContent> getImage(String imageId) { String path = PICTURE_UPLOAD_DIR; // here this path is absolute String file = imageId + ".png"; return Assets.at(path, file); } How can I make this work? NOTE: The reason to make images served using Assets is because of the auto etagging feature that make easy to send http 304 not modified. It seems that there is no auto

Playframework with CSRF : “CSRF token not found in session”?

五迷三道 提交于 2019-12-03 14:14:16
I'm making a simple authentication system using Playframework with their built-in CSRF filter and Security.Authenticator system, but I'm facing a problem : When the user fill his login/password and submit enter, I have the following error : CSRF token not found in session I checked my form and the CSRF token is really present and correctly placed (inside the tag) Here is my routes : GET /login controllers.Authentication.login POST /login controllers.Authentication.authenticate And my Authentication.java class : @play.filters.csrf.AddCSRFToken public static Result login() { if (Session

How to integrate Sass and Play 2.3?

China☆狼群 提交于 2019-12-03 13:22:23
Is it possible to integrate Sass and Play Framework 2.3 , so that Sass gets compiled to CSS? If so, how should I go about it? I've tried the play-sass plugin, but it doesn't build with Play 2.3, only up to 2.2. As you probably know, Play has migrated to using sbt-web as the model for its asset pipeline, instead of the old system. It's much more flexible than the old system. Unfortunately, since it's so new, it also lacks whole lot of existing packages. You'll either have to write sbt-sass yourself or wait till someone else does. I'm in the same boat for migrating my project to Play 2.3. From

How to set up asset fingerprinting in Play 2.3.4?

萝らか妹 提交于 2019-12-03 11:16:28
Versions: play 2.3.4 sbt 0.13.1 scala 2.11.2 I've followed the documentation on playframework.com to enable fingerprinting on public assets, but calls to routes.Assets.versioned never produce a versioned filename with a digest hash. Relevant lines in build.sbt: scalaVersion := "2.11.2" pipelineStages := Seq(rjs, digest) Relevant lines in project/plugins.sbt: addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.4") addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.5") addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0") Relevant lines in conf/routes: GET /assets/*file controllers.Assets

Play Framework 2.X and blocking database call

拟墨画扇 提交于 2019-12-03 10:06:01
问题 I'm a little confused. From the documentation: Play default thread pool - This is the default thread pool in which all application code in Play Framework is executed, excluding some iteratees code. It is an Akka dispatcher, and can be configured by configuring Akka, described below. By default, it has one thread per processor. Does it bring benefit to wrap a blocking database call in a Future , the call to the Future being itself wrapped by an async controller (returning it), in order to let

Custom JSON validation constraints in Play Framework 2.3 (Scala)

旧城冷巷雨未停 提交于 2019-12-03 05:54:29
I managed to implement form validation with custom constraints, but now I want to do the same thing with JSON data. How can I apply custom validation rules to a JSON parser? Example: The client's POST request contains a user name ( username ) and not only do I want to make sure that this parameter is a non-empty text, but also that this user actually exists in the database. // In the controller... def postNew = Action { implicit request => request.body.asJson.map { json => json.validate[ExampleCaseClass] match { case success: JsSuccess[ExampleCaseClass] => val obj: ExampleCaseClass = success

Play JSON formatter for Map[Int,_]

ぃ、小莉子 提交于 2019-12-03 03:02:47
I am attempting to migrate a Rails/Mongodb application to Play 2.3 using play-reactivemongo and reactivemongo-extensions. In modeling my data I am running across a problem serializing and deserializing a Map[Int,Boolean]. When I try to define my formats via macro like so implicit val myCaseClass = Json.format[MyCaseClass] where MyCaseClass has a few string fields, a BSONObjectID field, and a Map[Int,Boolean] field the compiler complains with: No Json serializer found for type Map[Int,Boolean]. Try to implement an implicit Writes or Format for this type. No Json deserializer found for type Map

Play Framework 2.X and blocking database call

给你一囗甜甜゛ 提交于 2019-12-03 01:35:33
I'm a little confused. From the documentation : Play default thread pool - This is the default thread pool in which all application code in Play Framework is executed, excluding some iteratees code. It is an Akka dispatcher, and can be configured by configuring Akka, described below. By default, it has one thread per processor. Does it bring benefit to wrap a blocking database call in a Future , the call to the Future being itself wrapped by an async controller (returning it), in order to let the default thread pool handling other users requests? It would just move the blocking code inside

Why are integration tests in a Play/Scala project not executed when using “sbt it:test”?

北城余情 提交于 2019-12-02 23:29:50
I have a Play Framework 2.3 project in which I'd like to separate unit tests and functional tests as follows: running sbt test should run unit tests and exclude integration tests running sbt it:test should run integration tests only The Scala documentation suggests using project/Build.scala , but I'd like to use combination of build.sbt and project/Build.scala , so my configuration looks like this (I have also tried putting all of configuration into Build.scala ): build.sbt .... libraryDependencies ++= Seq( "com.typesafe.play" %% "play-json" % "2.2.3", "org.scalatest" %% "scalatest" % "2.1.5"