playframework

Explicit return from play action

主宰稳场 提交于 2020-01-09 11:25:23
问题 I have following action def login: Result = Action(parse.json) { request => if (/* Let's we say here is some validation */) { return BadRequest("bad") } Ok("all ok") } This is giving me an Error. Intellij is suggesting Action[JsValue] type. When I say return will be of that type, I am getting again error on BadRequest line, because types doesn't match. I tried searching about this problem, and I found some answers which are suggesting to set Action[AnyContent] as return type. But I am STILL

Use Argonaut in Play framework with Reads and Writes

我只是一个虾纸丫 提交于 2020-01-07 09:02:07
问题 I know how to do json parsing using play json library for play application. For example I have following code: class PersonController extends Controller { case class Person(age: Int, name: String) implicit val personReads = Json.reads[Person] implicit val personWrites = Json.writes[Person] def create = Action(parse.json) { implicit request => rs.body.validate[Person] match { case s: JsSuccess => ... case e: JsError => ... } } } How should I write the code like Reads and Writes using Argonaut

What's the point of dependency injection if you still have to pass in an argument?

痞子三分冷 提交于 2020-01-07 06:26:21
问题 I'm having a bit of trouble understanding the basic idea of dependency injection. (I'm using Play 2.5 with the play-slick module) Say I have a class Users that needs a database connection. package models @Singleton class Users @Inject() (dbConfigProvider: DatabaseConfigProvider) { private val db = dbConfigProvider.get[JdbcProfile].db private val users = TableQuery[UserTable] private val setupAction = DBIO.seq(users.schema.create) private val setupFuture: Future[Unit] = db.run(setupAction) def

Can I (DNS) map one subdomain to multiple Play Framework entry points

為{幸葍}努か 提交于 2020-01-07 05:08:20
问题 Is the scenario below possible? A warning that I understand DNS only in its basic form. We have an API (built using Play) that we would like to make available via a an address say http://api.publicname.com However, we would like to split this API in 2 Play projects (e.g. myapione and myapitwo). Then access them using only 1 domain but two separate "subfolders" So I have been looking for the possibility of mapping say... http://myinternal.domain:9000 to http://api.publicname.com/myapione ...

Play Framework WS losing unicode chars from external api

♀尐吖头ヾ 提交于 2020-01-07 05:01:27
问题 I'm working on a play application that uses WS to make an asynchronous call to an external api and I can't figure out why I'm losing unicode chars when consuming for instance if they api is producing something like: { "title": "Plück, Franke" } and make a call to the api with: ws.url("http://example.org/stuff/").get().map { response => println(response.body) Ok.... The following will print: { "title":"Plück, Franke" } I'm trying to find if there is a header argument that I need to be passing

how to mock external WS API calls in Scala Play framework

做~自己de王妃 提交于 2020-01-07 04:43:24
问题 I have an existing Scala play application which has a REST API that calls another external REST API. I want to mock the external Web service returning fake JSON data for internal tests. Based on example from: https://www.playframework.com/documentation/2.6.x/ScalaTestingWebServiceClients I followed example exactly as in Documentation and I'm getting compiler errors due to deprecated class Action. import play.core.server.Server import play.api.routing.sird._ import play.api.mvc._ import play

how to add alphanumeric field in play framework

ε祈祈猫儿з 提交于 2020-01-07 04:38:08
问题 i need to add alphanumeric field in play for that i am trying this code object TestValidation { implicit val readTestUser: Reads[TestValidation] = ( (JsPath \ "firstName").read(minLength[String](1)) and (JsPath \ "lastName").read(minLength[String](1)) and (JsPath \ "email").read(email) and (JsPath \ "password").read(minLength[String](1)))(TestValidation.apply _) i want the "password" field to be alphanumeric i have added this custom validation constraint now i want to intregate this during

ProvisionException: Unable to provision. Play Framework

谁说胖子不能爱 提交于 2020-01-07 04:14:22
问题 when I put this line into my application I'm no longer able to start my application and I don't know why. I'm using Play 2.5. public class HomeController extends Controller { Form<User> userForm = Form.form(User.class); // get error if I put this line in public Hashtable<Integer, String> hmap = new Hashtable<>(); If I generate the form in the controller I get the error. Error I get: ProvisionException: Unable to provision, see the following errors: 1) Error injecting constructor, java.lang

Java play application running despite of having errors- how to resolve this errors?

删除回忆录丶 提交于 2020-01-07 03:26:09
问题 I just started with play using activator, I created new play app using activator new firstApp play-java Then I opened play console using activator and run the application, app was running fine. Then I opened the project in my intellij as SBT, the project opened and started showing errors. in routes file there were lines GET / controllers.HomeController.index GET /count controllers.CountController.count GET /message controllers.AsyncController.message This errors are because method index,

Scala/Play/Squeryl Retrieve multiple params

喜欢而已 提交于 2020-01-07 02:35:12
问题 I have the following url : http://localhost/api/books/?bookId=21&bookId=62?authorId=2 I want to retrieve all the bookId values with Scala and then use Squeryl to do a fetch in a the database. I'm using the PlayFrameWork as the WebServer, so here's my code : val params = request.queryString.map { case (k, v) => k -> v(0) } // Retrieve only one the first occurence of a param So params.get("bookId") will only get the last value in the bookId params. e-g : 62 . To retrieve all my bookId params i