playframework-2.1

Multiple Databases with Play Framework 2.1.x

人盡茶涼 提交于 2019-11-30 02:00:59
I have 2 databases that I need to connect to. I can easily connect to them in the application.conf file like so: db.default.driver=org.postgresql.Driver db.default.url="jdbc:postgresql://localhost/db1" db.default.user=postgres db.default.password="password" db.secondary.driver=org.postgresql.Driver db.secondary.url="jdbc:postgresql://localhost/db2" db.secondary.user=postgres db.secondary.password="password" ebean.default="models.db1.*" ebean.secondary="models.db2.*" I have my model classes in those packages, and it DDL generates the tables properly. The problem lies in actually working with

Custom JodaTime serializer using Play Framework's JSON library?

ぐ巨炮叔叔 提交于 2019-11-30 01:55:00
How do I implement a custom JodaTime's DateTime serializer/deserializer for JSON? I'm inclined to use the Play Framework's JSON library (2.1.1). There is a default DateTime serializer, but it uses dt.getMillis instead of .toString which would return an ISO compliant String. Writing Reads[T] amd Writes[T] for case classes seems fairly straightforward, but I can't figure out how to do the same for DateTime. I use Play 2.3.7 and define in companion object implicit reads/writes with string pattern: case class User(username:String, birthday:org.joda.time.DateTime) object User { implicit val

Changing layout template in runtime

不问归期 提交于 2019-11-29 21:12:40
问题 In Kohana (PHP framework) the layout is implemented through Template_Controller which continas a member variable called $template, which serves as layout view. Then in the action method you can populate the $template with further sub-views, usually the content view. (http://forum.kohanaframework.org/discussion/3612/kohana-layout-system/p1) This allows me to change the layout "theme" in the runtime. It is useful for multitenant system, where a tenant can select their own theme (two col, three

Call Solr asynchronous from Play Framework

China☆狼群 提交于 2019-11-29 12:08:46
I have created a Play 2.1 Scala application. I am uncertain what's the best way to call Solr from a Play application: There is no Solr module for Play 2. AFAIK all Solr-APIs like SolrJ are blocking. I could wrap a SolrJ call into a Future , but this will also block a thread, correct? Should I use the play.api.libs.ws.WS library to call Solr and use Plays JSON support to extract the result (like in the example below) or is there any easier/faster way? val solrQuery: Future[play.api.libs.ws.Response] = WS.url("http://localhost:8983/solr/collection1/select?q=id%3A123&wt=json").get() Here's how I

play framework 2.1 junit test not working from eclipse

我与影子孤独终老i 提交于 2019-11-29 09:18:15
im following the zentask tutorial and wrote a junit test, the test wont run from the eclipse IDE its giving the following exception javax.persistence.PersistenceException: java.lang.IllegalStateException: Class [class play.db.ebean.Model] is enhanced and [class models.User] is not - (you can not mix!!) at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.setEntityBeanClass(BeanDescriptorManager.java:1475) at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.createByteCode(BeanDescriptorManager.java:1138) at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager

How to serialize/deserialize case classes to/from Json in Play 2.1

五迷三道 提交于 2019-11-29 06:57:41
问题 I'm trying to serialize/deserialize some case classes to/from Json... and I've troubles when dealing with case classes with just one field (I'm using Play 2.1): import play.api.libs.json._ import play.api.libs.functional.syntax._ case class MyType(type: String) object MyType { implicit val myTypeJsonWrite = new Writes[MyType] { def writes(type: MyType): JsValue = { Json.obj( "type" -> MyType.type ) } } implicit val myTypeJsonRead = ( (__ \ 'type).read[String] )(MyType.apply _) } The code

How to use prepared statement in JPA

五迷三道 提交于 2019-11-29 06:56:16
I am a play framework application Developer.I am using createNativeQuery method in JPA. In this example i want to use prepared statement. Please anyone help me? Here is the code without JPA. I need help to convert it to Prepared statement. Query query = JPA.em().createNativeQuery("select count(*) from truck t inner join" + "box b where t.truck_id=b.truck_id and t.shipment_upc='" + code + "'"); BigInteger val = (BigInteger)query.getSingleResult(); System.out.println(val); Query query = JPA.em().createNativeQuery("select count(*) from truck t inner join box b where t.truck_id=b.truck_id and t

Play framework handling session state

◇◆丶佛笑我妖孽 提交于 2019-11-29 06:34:43
I have a Webapp that is built on top of the Play framework and Scala. It is about presenting the user with a set of questions with each question having a set of answers. Some of the questions have radio button types an answers and some have check boxes as answers. When the user clicks start test, I call the controller, fetch the list of questions with its answers and return the result as a case class to the view template. I now need to maintain the state of the test as the user answers each question. He can go previous, next and I need to keep track of all the questions that he answered.

Testing a Play2 application with SecureSocial using dependency injection

一世执手 提交于 2019-11-29 05:14:26
Thanks a lot for any guidance! The SecureSocial plugin works fine when I run it from the browser, but I would like to be able to test the rest of my Play app now. Quick Intro SecureSocial's syntax looks like this: def page = SecuredAction(WithProvider("google")) { ... } or this: def page = UserAwareAction { ... } I've been looking here , which seems to be the only question on Stack Overflow even remotely related to my problem with SecureSocial, but I don't quite fancy rewiring bytecode. There should be a simpler solution to this. When I'm running tests that access SecureSocial-protected

Scala play http filters: how to find the request body

自闭症网瘾萝莉.ら 提交于 2019-11-29 04:10:12
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. I spent some time on this. I am no means a Scala expert but this works pretty well! :) object AccessLog extends EssentialFilter