본문 바로가기

playFramework

[Play Framework2] WebSockets Play에서는 Actor 이용한 방법과 iteratees를 이용하는 방법이 있다. Actor은 Akka에서 제공해주는 방식이고 iteratees는 Play에서 제공해주는 것 같다. 참고 사이트 : https://www.playframework.com/documentation/2.3.x/ScalaWebSockets import akka.actor._ object MyWebSocketActor { def props(out: ActorRef) = Props(new MyWebSocketActor(out)) } class MyWebSocketActor(out: ActorRef) extends Actor { def receive = { case msg: String => out ! ("I received your .. 더보기
[Play Framework2] Streaming HTTP responses Streaming 기능에 대해서 실제로 구현해서 만들어 본 적이 없는데 이번에 PlayFramework에서 아주 간단하게 제공하는 방법이 있다. 참고 사이트 : https://www.playframework.com/documentation/2.3.x/ScalaStream def index = Action { val file = new java.io.File("/tmp/fileToServe.pdf") val fileContent: Enumerator[Array[Byte]] = Enumerator.fromFile(file) Result( header = ResponseHeader(200), body = fileContent ) }위의 코드로 간단한 스트리밍 기능? 이 구현이 완료가 되었고 혹시나 Enumer.. 더보기
[Play Framework2] Session and Flash scopes PlayFramework에서 Session은 내부적으로 Cookie 로 사용되어지고 그래서4kb라는 제약있다.자세한 사항은 https://www.playframework.com/documentation/2.3.x/ScalaSessionFlash Ok("Welcome!").withSession( "connected" -> "user@gmail.com")위와 같이 key값으로 저장을 하고Ok("Hello World!").withSession( request.session + ("saidHello" -> "yes"))+ 통해서 session에 값을 저장하는 것이 가능하다.Ok("Theme reset!").withSession( request.session - "theme")- 도 가능하다. def index .. 더보기
[Play Framework2] Setting and discarding cookies Cookie를 사용하는 방법이다. (https://www.playframework.com/documentation/2.3.x/ScalaResults) val result = Ok("Hello world").withCookies( Cookie("theme", "blue"))Setval result2 = result.discardingCookies(DiscardingCookie("theme"))Discardingval result3 = result.withCookies(Cookie("theme", "blue")).discardingCookies(DiscardingCookie("skin"))Set & Discarding def home(name:String) = Action {request=> val prev.. 더보기