playframework-2.2

How to parse json list or array in scala for play framework 2.2

落爺英雄遲暮 提交于 2020-01-12 08:45:51
问题 I am writing some RESTful API test cases and have little experience working with the scala playframwork. Here is an example of my JSON. [ { "size" : "5082", "date-created" : "Wed Nov 19 17:10:39 CST 2014", "id" : "546d236fb84e894eefd8f769", "content-type" : "image/png", "filename" : "chrome-on-windows.PNG" }, { "size" : "15684", "date-created" : "Mon Jan 12 17:28:02 CST 2015", "id" : "54b4588266b3d11b1c1e9db6", "content-type" : "image/png", "filename" : "logos_ncsa.png" }, { "size" : "1267871

Batch HTTP requests in Play!Framework

こ雲淡風輕ζ 提交于 2020-01-11 07:30:20
问题 I have the current set of of routes implemented (for example): GET /api/:version/:entity my.controllers.~~~~~ GET /api/:version/:entity/:id my.controllers.~~~~~ POST /api/:version/:entity my.controllers.~~~~~ POST /api/:version/:entity/:id my.controllers.~~~~~ DELETE /api/:version/:entity my.controllers.~~~~~ POST /api/:version/search/:entity my.controllers.~~~~~ And they work beautifully. Now let's say I want to implement a "batch endpoint" for the same API. It should look something like

Add global error in validate function

浪尽此生 提交于 2020-01-06 00:55:05
问题 I have a login form: public static class LoginForm { @Constraints.Required public String email; @Constraints.Required public String password; } And I need to validate if user exist or is validated. So my validate function is: public List<ValidationError> validate() { List<ValidationError> errors = new ArrayList<ValidationError>(); User user = User.findByEmail(email); if (user == null || !Hash.checkPassword(password, user.passwordHash)) { errors.add(new ValidationError("email", "Invalid email"

My Play! Application doesn't have an application.log

江枫思渺然 提交于 2020-01-04 05:58:32
问题 I got an error message saying: This exception has been logged with id 1mhqg4onc But I don't see this exception in the logs. I only have myapp.DEBUG , myapp.ERROR , myapp.FATAL , myapp.INFO , myapp.TRACE and myapp.WARN in my myapp/logs directory. I thought application.log was just supposed to be there by default. It's in my local machine but not when I deploy to production and that's where this exception is happening. I tried adding a file at conf/application-logger.xml with the default

My Play! Application doesn't have an application.log

大城市里の小女人 提交于 2020-01-04 05:58:30
问题 I got an error message saying: This exception has been logged with id 1mhqg4onc But I don't see this exception in the logs. I only have myapp.DEBUG , myapp.ERROR , myapp.FATAL , myapp.INFO , myapp.TRACE and myapp.WARN in my myapp/logs directory. I thought application.log was just supposed to be there by default. It's in my local machine but not when I deploy to production and that's where this exception is happening. I tried adding a file at conf/application-logger.xml with the default

How to read a file in Play Framework 2.2.1?

两盒软妹~` 提交于 2020-01-03 11:02:53
问题 I have a static file that I want to read in one of my Play Framework models. The file contains some simple text in it. I can't find any examples or API that shows where the appropriate location is to store such a resource and second, how to access that resource. For whatever it is worth I'm using Play for Scala, but I don't think that's relevant here. 回答1: You can place any resource file in the folder /conf and load it (Programatically) as explained here: Custom configuration files - Play!

Scala Play Action.async cant resolve Ok as mvc.AnyContent

自闭症网瘾萝莉.ら 提交于 2020-01-03 02:46:10
问题 The following controller action cause the error: (block: => scala.concurrent.Future[play.api.mvc.SimpleResult])play.api.mvc.Action[play.api.mvc.AnyContent] cannot be applied to (scala.concurrent.Future[Object])". Every Future inside the action should be Ok() so I don't understand why scala can't resolve the futures correctly. def form = Action.async { val checkSetup: Future[Response] = EsClient.execute(new IndexExistsQuery("fbl_indices")) checkSetup map { case result if result.status == 200 =

Play framework 2.2: How to get current controller and action in java

心不动则不痛 提交于 2020-01-02 22:34:19
问题 In my application authentication scheme is based on user and role. users with particular role have access to particular action method. To implement this I have done following 1.Write custom action public class Authorization extends play.mvc.Action.Simple { public Promise<Result> call(Context ctx) throws Throwable { //check access return delegate.call(ctx); } } 2.Annotate controller with action @With(actions.Authorization.class) public class Upload extends Controller { .... } In my action I

build.sbt defining project dependency between modules

浪子不回头ぞ 提交于 2020-01-02 10:22:54
问题 I have project in PlayFramework. It has one main project without any code/logic. And it have few submodules: main: admin common shop Modules: admin and shop will base on common module (classes like: user, role, permission), so I have to configure it that way: lazy val shop = project.in(file("modules/shop")) .dependsOn(cirs) .dependsOn(common) .dependsOn(admin) lazy val admin = project.in(file("modules/admin")) .dependsOn(cirs) .dependsOn(common) .dependsOn(shop) But in module common I have

How do I wait for an actor to stop during Play Framework shutdown?

天涯浪子 提交于 2020-01-01 06:18:12
问题 The below code throws a java.lang.IllegalMonitorStateException exception when I shutdown the play server; it is caused by the a.wait(1000) call in the onStop method. Could anyone tell me why this is the case and how to gracefully wait for an actor to complete within Play framework shutdown? import play.api.GlobalSettings import play.api.libs.concurrent.Akka import akka.actor.{ Actor, Props } import play.api.libs.concurrent.Execution.Implicits.defaultContext import play.api.Play.current import