playframework-2.2

Composing with Play's EssentialAction

喜夏-厌秋 提交于 2019-12-04 15:34:37
I'm using Play 2.2.1 and I'm trying to write my own Action to deal with CORS requests. I found this but unfortunately it doesn't compile. Just for reference here's the (slightly modified) code: import play.api.mvc._ import scala.concurrent.ExecutionContext case class CorsAction(action: EssentialAction) extends EssentialAction { def apply(request: RequestHeader) = { implicit val executionContext: ExecutionContext = play.api.libs.concurrent.Execution.defaultContext val origin = request.headers.get("Origin").getOrElse("*") if (request.method == "OPTIONS") { val cors = Action { request => Ok("")

Play Framework 2.2.x multiple route files

血红的双手。 提交于 2019-12-04 13:36:43
I've read through the Play! For Scala book's section on modules and I can't seem to figure out how to import the routes from a referenced module. I've set up my module as a library dependency in my build.sbt file and I've tried to import the route in my routes file like so build.sbt: libraryDependencies ++= Seq( "org.webjars" %% "webjars-play" % "2.2.0", "default" % "mymodule" % "1.0-SNAPSHOT" routes ... -> /api/mymodule mymodule.routes mymodule contains a routing file called mymodule.routes. I don't really see how this could work however I don't fully understand what's going on so I'm not

Play Framework send message via rabbit mq

我的梦境 提交于 2019-12-04 11:49:47
Does anybody out there using rabbitmq with Play Framework? I have an AI written in Scala using Play Framework. And I have a mean stack, which handles a nosql database. I'd like to send json messages via rabbitmq to that AI. I already got things going with nodejs and rabbitmq, but now that i want to connect to play I might need your help. Has someone any experience with rabbitmq and play or some practical Advices? Thanks! You can use the standard Java library to send messages to RabbitMQ like this: val factory = new ConnectionFactory() factory.setUri(serverUri) val channel = connection

Need advice on project layout for Play 2.2 submodule with other modules as dependencies

故事扮演 提交于 2019-12-04 11:35:20
问题 I have an existing SBT project with modules. I want to add Play 2.2 into my project as a submodule. This new Play module will depend on other modules. What I found so far was mostly about Play being the main project with supporting modules. If Play does support this setup, please point me in the right direction how to do it. Thanks. My intended setup (simplified): my_project \--- desktop_ui \--- src/main \--- src/test \--- common \--- src/main \--- src/test \--- web_ui (Play framework) \---

Unable to convert generic case class to json using “writes”

萝らか妹 提交于 2019-12-04 08:38:05
问题 I have a class which I want to be able to convert to json: case class Page[T](items: Seq[T], pageIndex: Int, pageSize: Int, totalCount: Long) object Page { implicit val jsonWriter: Writes[Page[_]] = Json.writes[Page[_]] } The error is No apply function found matching unapply parameters 回答1: You can define Format[Page[T]] for generic case class Page[T] like this: import play.api.libs.json._ import play.api.libs.functional.syntax._ implicit def pageFormat[T: Format]: Format[Page[T]] = ((__ \

Error reading annotations play framework 2.2

女生的网名这么多〃 提交于 2019-12-04 07:53:04
I have started to learn the Play Framework, following the Java guide (tutorial “ZenTasks”). Everything was going well until I found this error: Error reading annotations for models.Task Class package models; import java.util.*; import javax.persistence.*; import play.db.ebean.*; @Entity public class Task extends Model { @Id public Long id; public String title; public boolean done = false; public Date dueDate; @ManyToOne public User assignedTo; public String folder; @ManyToOne public Project project; public static Model.Finder<Long,Task> find = new Model.Finder(Long.class, Task.class); public

Using POST routes parameters in Play Framework

一曲冷凌霜 提交于 2019-12-04 02:30:56
I have a login route that should transmit its input parameters as POST variables. I have defined my route like this: POST /v1/accounts/login controllers.v1.Accounts.login(username: String, password: String) and my Controller is like this: object Accounts extends Controller { def login(username: String, password: String) = Action { Ok("Foo " + username) } } When I test this route using Chromes Advance REST Client it only works for GET parameters and not if I send it as application/x-www-form-urlencoded POST form data. The Play Framework documentation never actually mentions POST parameters but

Play Framework Multi-Tenant Filter

走远了吗. 提交于 2019-12-03 20:12:30
I'm attempting to build a multi-tenant application using Play Framework 2.2 and have run into a problem. I want to set a session key in the global onRouteRequest (or onRequest in Java) that identifies the site ID for the domain the user is requesting. In literally dozens of other frameworks this type of thing is painless (e.g. Django), but I'm learning that the session object in Play is apparently immutable, however. So, right now, I have something like this: override def onRouteRequest(request: RequestHeader): Option[Handler] = { if (request.session.get("site").isEmpty){ val id = models.Site

Play framework 2.2.1: Create Http.Context for tests

為{幸葍}努か 提交于 2019-12-03 19:09:28
问题 I've been trying to create an Http.Context for tests using its constructor unsuccessfully. Does anybody see what I'm doing wrong? I've looked at the following but it only applies to Play 2.0: Play framework 2.0: Store values in Http.Context It looks like the class changed for 2.2.1 and it has more parameters for the constructor as shown here: https://github.com/playframework/playframework/blob/2.1.x/framework/src/play/src/main/java/play/mvc/Http.java This my code: import java.util.Map; import

Play framework routes, and scala predef values

强颜欢笑 提交于 2019-12-03 14:02:13
问题 I develop application on play framework 2.2 I have a routes file like this: GET /posting/ controllers.posting.BlogController.allPosts() GET /posting/:number controllers.posting.BlogController.allPosts(number: Int) And BlogContriller: object BlogController extends Controller { def allPosts(pageNumber:Int = 1, postsPerPage:Int = 10) = Action{ val posts = Post.getLastNPosts(postsPerPage, postsPerPage*(pageNumber-1)) val htmlPosts = new Html(new StringBuilder()); for (post <- posts){ val htmlPost