playframework-2.6

Play framework - how to write to public assets

有些话、适合烂在心里 提交于 2019-12-24 07:39:47
问题 Trying to process uploaded images and then display the result. Was following: https://github.com/playframework/play-scala-fileupload-example Relevant snippet: private def handleFilePartAsFile: FilePartHandler[File] = { case FileInfo(partName, filename, contentType) => val path: Path = Files.createTempFile("multipartBody", "tempFile") val fileSink: Sink[ByteString, Future[IOResult]] = FileIO.toPath(path) val accumulator: Accumulator[ByteString, IOResult] = Accumulator(fileSink) accumulator.map

Unit testing a controller in Play 2.6

我的梦境 提交于 2019-12-23 12:34:42
问题 I'm getting a null pointer exception when trying to test a controller in Play 2.6 in Scala. This is a test for an OK response: class ApplicationControllerSpec extends PlaySpec with MockitoSugar with ScalaFutures { val mockOrchestrator = mock[ApplicationOrchestrator] val mockCC = mock[ControllerComponents] val controller = new ApplicationController(mockOrchestrator, mockCC) val method = controller.home()(FakeRequest()) assert(status(method) == 200) } This is the Controller I'm testing: class

Using JWT authentication with Play Framework 2.6

自古美人都是妖i 提交于 2019-12-22 05:14:33
问题 I'm having issues with using JWT Authentication using guides for older versions but I'd like to focus on the new Play 2.6 According to the official documentation, JWT is now used under the hood. It seems like there would be an easier way instead of creating an ActionBuilder and a bunch of other classes or importing third-party libraries but I can't figure out what I would need to do. Can anyone give me guidance on how to create JWT tokens/secrets with 2.6? Preferably Java but I could make my

How to mix Slick and JDBC in the same Play Framework project?

喜你入骨 提交于 2019-12-14 04:02:01
问题 I'd like to mix regular JDBC into my Play Framework project using Slick. I've ran into a few hurdles. Directly adding the jdbc dependency to my project yields this error from this question A binding to play.api.db.DBApi was already configured, evolutions and injector error with play-slick removing the jdbc dependency means I cannot use the play.api.db.Database class and yields this error Play error on startup: No implementation for play.api.db.Database was bound So how can I use regular jdbc

how to test an Action[T] without a message body in play framework

两盒软妹~` 提交于 2019-12-14 03:09:48
问题 An Action[T] means that it accepts a request with body of type T . Eg def getQuestion:Action[JsValue] = silhouette.UserAwareAction.async(parse.json){...} How do I test the above Action with a request which doesn't contain any body? In my unit test, I call the above action like the following val request = FakeRequest("POST","ws/questions/get-question") val responseFuture:Future[Result] = questionsTestEnv.questionsController.getQuestion(request) But I get error Error:(182, 92) type mismatch;

unable to understand why validateOpt will return `None` instead of `JsError`

北慕城南 提交于 2019-12-13 20:38:24
问题 In the following code, I am unable to understand why validateOpt might return value JsSuccess(None) instead of JsError def getQuestion = silhouette.UserAwareAction.async{ implicit request => { val body: AnyContent = request.body val jsonBodyOption: Option[JsValue] = body.asJson jsonBodyOption.map((jsonBody:JsValue) => { //body is json val personJsonJsResultOption = jsonBody.validateOpt[Person]//check that json structure is correct personJsonJsResultOption match { case personSuccessOption:

Class is not visible unless I declare it in a package

ぐ巨炮叔叔 提交于 2019-12-13 18:12:41
问题 I have a class AppComponents in AppLoader.scala in projectDir/app My tests are in projectDir/test/ControllerSpec/UserControllerSpec.scala In UserControllerSpec.scala , I tried to create an instance of AppComponents but the compiler couldn't find the AppComponents class override def components: BuiltInComponents = new AppComponents(context) //doesn't compile But if I include statement package app in Apploader.scala then the compiler is able to find AppComponents and the above code compiles. I

Request body is showing as AnyContentAsRaw with inMemory 0

五迷三道 提交于 2019-12-13 03:26:53
问题 My outgoing request looks like follows POST ws/questions/new-question headers List((Host,localhost), (X-Auth-Token...) body AnyContentAsJson({"practice-question":...}) The Action to process the request should first check that the size of the body does not exceed a maximum value. def newQuestion = silhouette.SecuredAction.async(parse.maxLength(maxAllowedBodySize, parse.anyContent)(materializer)) { implicit request => { println("got request with body:" + request.body) val anyBodyErrors: Either

unable to start a Process in Scala/Play application

我们两清 提交于 2019-12-13 02:48:50
问题 I have a ccm.py script which runs Cassandra cluster on local machine. I am able to run the command using windows command prompt. But I get error if I try to do so using Process class in Scala . I want to run it before starting my test cases. So I am calling Process in beforeAll . override def beforeAll():Unit = { println("starting cassandra cluster locally") val ccmCommand = Process("ccm.py start").! } The error I get is An exception or error caused a run to abort: Cannot run program "ccm.py"

How one should handle incremental database schema evolution

99封情书 提交于 2019-12-11 23:48:30
问题 I have a Play framework powered application with database as a persistance layer (and I use Slick for that). I have enabled evolutions, generated 1.sql file and successfully rolled it out to production. Client requests new features that require database schema modifications - ie. adding new tables, adding new columns and changes to existing columns' nullability. Once all Slick's Table definitions and related code are updated, I generate schema once again and place it as 2.sql . Evolutions are