playframework-2.5

Play framework 2.5.0 Websockets example [closed]

半世苍凉 提交于 2019-12-04 20:57:12
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Play framework 2.5.0 Websockets example. in play 2.5.0 websockets code is changed to support akka streams but I'm not able find a sample code to use it. 回答1: This will be properly documented in 2.5.1 as you can see here: https://github.com/playframework/playframework/issues/5057 In the meantime you can take a

How to refactor this code by using akka streams.

时光毁灭记忆、已成空白 提交于 2019-12-04 20:17:16
问题 The idea is to keep the channel opened to use it later. In playframework 2.5.x the documentation says that you have to use akka streams but does not say anything how to achieve this example. Somebody can help me? import play.api.mvc._ import play.api.libs.iteratee._ import play.api.libs.concurrent.Execution.Implicits.defaultContext def socket = WebSocket.using[String] { request => // Concurrent.broadcast returns (Enumerator, Concurrent.Channel) val (out, channel) = Concurrent.broadcast[String

Play 2.5: get response body in custom http action

萝らか妹 提交于 2019-12-04 15:34:30
I'm trying to create a custom http action ( https://playframework.com/documentation/2.5.x/JavaActionsComposition ) to log request and response bodies with Play 2.5.0 Java. This is what I've got so far: public class Log extends play.mvc.Action.Simple { public CompletionStage<Result> call(Http.Context ctx) { CompletionStage<Result> response = delegate.call(ctx); //request body is fine System.out.println(ctx.request().body().asText()) //how to get response body string here while also not sabotaging http response flow of the framework? //my guess is it should be somehow possible to access it below

Slick: combine actions with a Seq of DBIOAction

☆樱花仙子☆ 提交于 2019-12-04 09:45:24
I have the (working) following code: val actions = (for { _ <- slickUsers.insertOrUpdate(dbUser) loginInfo <- loginInfoAction _ <- slickUserLoginInfos += DBUserLoginInfo(dbUser.userID, loginInfo.id.get) } yield ()).transactionally with loginInfoAction being a DBIOAction. I would like to change loginInfoActions to a Seq of DBIOAction and for each of them, execute the same DBUserLoginInfo action afterwards. I tried this stupidly: val actions = (for { _ <- slickUsers.insertOrUpdate(dbUser) loginInfoAction <- loginInfoActions loginInfo <- loginInfoAction _ <- slickUserLoginInfos += DBUserLoginInfo

Automatically inject WebJarAssets in Play 2.5 HTML template?

强颜欢笑 提交于 2019-12-04 06:59:04
In my Play HTML template inside my custom module, I have the following line of code: <script type="text/javascript" src="@controllers.core.routes.WebJarAssets.at(WebJarAssets.locate("jquery.min.js"))"></script> This references a WebJarAssets class in the core module that looks like this: package controllers.core import javax.inject._ import play.api.http.HttpErrorHandler import play.api.{Environment, Configuration} class WebJarAssets @Inject()(errorHandler: HttpErrorHandler, configuration: Configuration, environment: Environment) extends controllers.WebJarAssets(errorHandler, configuration,

How to refactor this code by using akka streams.

▼魔方 西西 提交于 2019-12-03 12:54:38
The idea is to keep the channel opened to use it later. In playframework 2.5.x the documentation says that you have to use akka streams but does not say anything how to achieve this example. Somebody can help me? import play.api.mvc._ import play.api.libs.iteratee._ import play.api.libs.concurrent.Execution.Implicits.defaultContext def socket = WebSocket.using[String] { request => // Concurrent.broadcast returns (Enumerator, Concurrent.Channel) val (out, channel) = Concurrent.broadcast[String] // log the message to stdout and send response back to client val in = Iteratee.foreach[String] { msg

Play 2.5.3: Using dependency injection to get configuration values

*爱你&永不变心* 提交于 2019-12-03 03:27:34
I'm trying to migrate a Playframework application from 2.4 to 2.5.3 and I have problems to get values from application.conf file: Before to get a value of from application.conf what I do was: Play.application().configuration().getString("label") Now as Play.application() is deprecated, I should use Dependency injection. Based on the framework documentation I use the following instructions: Define import : import javax.inject.*; import play.Configuration; Define class property : @Inject private Configuration configuration; Use the configuration class property on my class When I follow these

How to prevent circular dependencies when using WebJarAssets & Play 2.5?

你离开我真会死。 提交于 2019-12-02 04:22:30
After I implemented what has been suggested by an answer of my last question , I received the following error when accessing the application in the browser: ProvisionException: Unable to provision, see the following errors: 1) Tried proxying play.api.http.HttpErrorHandler to support a circular dependency, but circular proxies are disabled. while locating utils.ErrorHandler while locating play.api.http.HttpErrorHandler for parameter 0 at controllers.WebJarAssets.<init>(WebJarAssets.scala:19) at controllers.WebJarAssets.class(WebJarAssets.scala:19) while locating controllers.WebJarAssets for

Play tests with database: “Too many connections”

两盒软妹~` 提交于 2019-12-01 17:06:10
To have a database available in scalatest with evolutions I use this extension of the default PlaySpec inspired by this SO question : trait ResetDbSpec extends PlaySpec with BeforeAndAfterAll { lazy val appBuilder = new GuiceApplicationBuilder() lazy val injector = appBuilder.injector() lazy val databaseApi = injector.instanceOf[DBApi] override def beforeAll() = { Evolutions.applyEvolutions(databaseApi.database("default")) } override def afterAll() = { Evolutions.cleanupEvolutions(databaseApi.database("default")) databaseApi.database("default").shutdown() } } It applies database evolutions

Play tests with database: “Too many connections”

狂风中的少年 提交于 2019-12-01 16:58:13
问题 To have a database available in scalatest with evolutions I use this extension of the default PlaySpec inspired by this SO question: trait ResetDbSpec extends PlaySpec with BeforeAndAfterAll { lazy val appBuilder = new GuiceApplicationBuilder() lazy val injector = appBuilder.injector() lazy val databaseApi = injector.instanceOf[DBApi] override def beforeAll() = { Evolutions.applyEvolutions(databaseApi.database("default")) } override def afterAll() = { Evolutions.cleanupEvolutions(databaseApi