playframework-2.1

Is it possible to cast a SqlQuery results from Ebean to a Model (Bean)?

陌路散爱 提交于 2019-12-23 06:14:50
问题 Using Ebean (via Play Framework 2.1.1), I have to build a home made SQL query, but I'd like it to return directly a List<MyModel> , instead of a List<SqlRow> that I would have to query the database for each id from the result to have a List<MyModel> . Is it possible to cast directly a SqlQuery/SqlRow to a Model ? Actually, I do that : SqlQuery query = Ebean.createSqlQuery("SELECT id FROM MyModel WHERE ..."); List<SqlRow> rows = query.findList(); // not directly possible. List<MyModel> results

How to send request parameters with same parameter-name

∥☆過路亽.° 提交于 2019-12-23 02:58:09
问题 This question is an extension to How do I set params for WS.post() in play 2.1 Java My web service request handler is as follows @POST @Path("/requestPath") public String addChallengersToLeague( @FormParam("name") String name, @FormParam("values") List values); since WSRequestHolder accepts a Map<String, String> in setQueryParameter method, I am not able to send parameter list with same name. I can send request from POSTMAN with multiple parameters having name 'values'and it works fine. Can

How do I ignore ssl validation in play framework scala ws calls

核能气质少年 提交于 2019-12-22 09:17:58
问题 I want to consume a web service that is using an invalid certificate (self signed) I want to make the web service call without performing any sort of certificate validation. How do I do it? 回答1: In your application.conf add the below line ws.acceptAnyCertificate=true 回答2: By the way, if you going to user play2 as a lib, to allow self-signed ssl certificates you should do the following(2.1.3 as actual version): create conf/application.conf with at least one string ws.acceptAnyCertificate=true

How to change future timeout with play framework 2.1.0

房东的猫 提交于 2019-12-22 08:55:14
问题 i'm calling a webservice using play framework 2.1 which takes longer than 10s. because of that i always receive the following error: play.api.Application$$anon$1: Execution exception[[TimeoutException: Futures timed out after [10000 milliseconds]]] at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.0] at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.0] at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun

How to generate a big data stream on the fly

南楼画角 提交于 2019-12-22 07:41:12
问题 I have to generate a big file on the fly. Reading to the database and send it to the client. I read some documentation and i did this val streamContent: Enumerator[Array[Byte]] = Enumerator.outputStream { os => // new PrintWriter() read from database and for each record // do some logic and write // to outputstream } Ok.stream(streamContent.andThen(Enumerator.eof)).withHeaders( CONTENT_DISPOSITION -> s"attachment; filename=someName.csv" ) Im rather new to scala in general only a week so don't

How to generate a big data stream on the fly

£可爱£侵袭症+ 提交于 2019-12-22 07:40:52
问题 I have to generate a big file on the fly. Reading to the database and send it to the client. I read some documentation and i did this val streamContent: Enumerator[Array[Byte]] = Enumerator.outputStream { os => // new PrintWriter() read from database and for each record // do some logic and write // to outputstream } Ok.stream(streamContent.andThen(Enumerator.eof)).withHeaders( CONTENT_DISPOSITION -> s"attachment; filename=someName.csv" ) Im rather new to scala in general only a week so don't

No Json deserializer found for type Option[reactivemongo.bson.BSONObjectID]

孤者浪人 提交于 2019-12-22 04:03:12
问题 I'm getting a: No Json deserializer found for type Option[reactivemongo.bson.BSONObjectID]. Try to implement an implicit Reads or Format for this type. When trying to deserialise my review object. Review: case class Review(override var id: Option[BSONObjectID] = None, override var createdAt: Option[DateTime] = None, override var updatedAt: Option[DateTime] = None, grade: Int, text: String, originIPAddress: Option[String], status: ReviewStatus, origin: ReviewOrigin, rId: Option[Long], userId:

Play Framework 2.1: Scala: how to get the whole base url (including protocol)?

无人久伴 提交于 2019-12-22 02:03:54
问题 Currently I am able to get the host from the request, which includes domain and optional port. Unfortunately, it does not include the protocol (http vs https), so I cannot create absolute urls to the site itself. object Application extends Controller { def index = Action { request => Ok(request.host + "/some/path") // Returns "localhost:9000/some/path" } } Is there any way to get the protocol from the request object? 回答1: Actually your portnumber will give you if it's http or https. Start

How should I structure my nested reactivemongo calls in my play2 application?

蓝咒 提交于 2019-12-22 01:04:04
问题 I'm in the process of trying to combine some nested calls with reactivemongo in my play2 application. I get a list of objects returned from createObjects . I then loop over them, check if the object exist in the collection and if not insert them: def dostuff() = Action { implicit request => form.bindFromRequest.fold( errors => BadRequest(views.html.invite(errors)), form => { val objectsReadyForSave = createObjects(form.companyId, form.companyName, sms_pattern.findAllIn(form.phoneNumbers)

Play Framework JSON Reader and custom JSErrors

假装没事ソ 提交于 2019-12-21 22:36:04
问题 I'm trying to read a JSON that could have the following parameters coming from the client { "email" : "foobar@gmail.com", "password" : "XXXX", "facebookToken": "XXXXXXXXXXX" } The facebookToken could be Null or Not present, in which case the Email/Password should be filled, and vice versa. I'm having trouble constructing this Reader, here's what I have so far: val loginEmail = ( ( __ \ "email").read[String] and ( __ \ "password").read[String] )((email: String, password: String) => new User