본문 바로가기

Development/Web & Server

[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] Action composition PlayFramework에서는 Action이 뭔가 Restful 통신을 할때 반응하는 객체로 쓰여진다... 이번에는 이 Action을 활용하는 방법을 알아보자 자세한 사항은 : https://www.playframework.com/documentation/2.3.x/ScalaActionsComposition object LoggingAction extends ActionBuilder[Request] { def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = { Logger.info("Calling action") block(request) } }위와 같이LoggingAction을 만들고def index = Loggi.. 더보기
[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.. 더보기
[Play Framework2] Http Routing 프로젝트 파일에서 Conf 폴더에 routes 라는 파일이 있다. 이 파일에서 모든 url을 관리하는 듯하다. (#은 주석이다.)GET /clients/all controllers.Clients.list()GET /clients/:id controllers.Clients.show(id: Long)GET /files/*name controllers.Application.download(name)(*id 표현은 GET /files/images/logo.png 와 같이 파일형식의 파라미터를 받을수있다.) GET /items/$id controllers.Items.show(id: Long)($id 로 정규화 표현을 받을 수 있다.) # Extract the page parameter from the path, .. 더보기
IOException: Cannot run program "javac": java.io.IOException: error=2, No such file or directory EC2에서 PlayFramework 2.3.8버전을 시험삼아 실행해보려고 시도를 하니 IOException: Cannot run program "javac": java.io.IOException: error=2, No such file or directory와 같은 오류가 발생하였다. 원인은 AWS에서 openJDK를 설치하였는데 javac를 지원하지 않는게 문제였다. 본인은 openjdk 1.8.0을 사용해서 yum을 통해 1.8.0-openjdk-devel 추가적으로 설치하니 정상적으로 작동이 되었다. 더보기
[Play Framework] 2.3버전 설치 및 프로젝트 생성 오랜만에 Play Framework를 한번 해보려고 공식 홈페이지에 들어갔다. https://www.playframework.com 확인해보니 2.3.8 버전까지 업데이트를 하였다.이제 설치할 준비를 하고..... 파일은 다운받으니.. 아래와 같이 3개의 파일만 있다. activactor를 실행시키니 알아서 뭔가를 많이 다운받는다.... 그리고 아래와 같이 Play Server가 실행이 되고........ 웹 페이지를 통해 activactor라는 사이트?? 에 접속하고 프로젝트 생성부터 다 해준다.!!! 간단하게 프로젝트를 생성하고 빨간색 부분을 클릭하면 아래와 같은 버튼을 볼 수 있게 되는데 IDE변환까지 알아서 다해준다..!!! 정말 개발하기 편해졌다. 더보기
[Spring Framework] Injection of autowired dependencies failed 아래의 에러에서 주목해야되는 부분은 circular reference 이다. 즉... @Inject 애노테이션을 쓰면서 서로 서로 가지도록 설정을 해서 발생한 문제이다. 해결 방법은구조적으로 @Inject 하는 상황을 회피하도록 만들거나... http://java.dzone.com/articles/resolve-circular-dependency 여기를 참고해서 보자~! org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'userService': Bean with name 'userService' has been injected into other beans [matchingSer.. 더보기
[Javascript] 동적으로 생성하는 텍스트 Component에서 높이 가져오기 동적으로 생성하면서 높이 값이 필요할 때 유용하다. 약간 꼼수인 것 같지만..... function textComponentHeight (component) { document.body.appendChild(component); var textHeight = component.offsetHeight; document.body.removeChild(component); return textHeight; } 더보기
Tomcat7 에서 Memory Setting 하기 1. /etc/tomcat7 이동한다. (또는 /usr/share/tomcat7 여기로 이동하여 목록을 확인하여)drwxr-xr-x 2 root root 4096 Sep 12 03:53 binlrwxrwxrwx 1 root tomcat 12 Sep 12 03:53 conf -> /etc/tomcat7lrwxrwxrwx 1 root tomcat 23 Sep 12 03:53 lib -> /usr/share/java/tomcat7lrwxrwxrwx 1 root tomcat 16 Sep 12 03:53 logs -> /var/log/tomcat7lrwxrwxrwx 1 root tomcat 23 Sep 12 03:53 temp -> /var/cache/tomcat7/templrwxrwxrwx 1 root tomc.. 더보기