Qiita Conference 2025

Qiita史上最多!豪華12名のゲストが登壇

特別講演ゲスト(敬称略)

ymrl、成瀬允宣、鹿野壮、伊藤淳一、uhyo、徳丸浩、ミノ駆動、みのるん、桜庭洋之、tenntenn、けんちょん、こにふぁー

7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

finatra はじめの一歩

Last updated at Posted at 2016-06-21

finatra はじめの一歩

by FScoward
1 / 9

playframework以外も触りたいなと思ったので、手を付けてみます。

構成としては finatra + quill あたりで考えています。

新しくスライドモード付いたみたいなんでお試し


Finatra

Fast, testable, Scala services built on TwitterServer and Finagle.

だそうです。


とりあえず

finatra の公式のexampleをパクります
https://github.com/twitter/finatra/tree/master/examples/hello-world


普通に sbt run しようとしたら以下のようなエラーが出たので
↓のブログを参考に sbt run -admin.port=:9001 とかやってみましたが、なぜか認識してくれず。。。
http://befool.co.jp/blog/chainzhang/tasting-twitter-finatra/
→コメント頂きました。(2016/07/14) sbt 'run -admin.port=:9001'で良いそうです。

org.jboss.netty.channel.ChannelException: Failed to bind to: 0.0.0.0/0.0.0.0:9990
        at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:272)
        at com.twitter.finagle.netty3.Netty3Listener$$anon$1.<init>(Netty3Listener.scala:338)
        at com.twitter.finagle.netty3.Netty3Listener.listen(Netty3Listener.scala:318)
        at com.twitter.finagle.server.StdStackServer$$anon$1.<init>(StackServer.scala:260)
        at com.twitter.finagle.server.StdStackServer$class.serve(StackServer.scala:212)
        at com.twitter.finagle.Http$Server.serve(Http.scala:306)
        at com.twitter.finagle.Server$class.serve(Server.scala:113)
        at com.twitter.finagle.Http$Server.serve(Http.scala:306)
        at com.twitter.server.AdminHttpServer$class.com$twitter$server$AdminHttpServer$$startServer(AdminHttpServer.scal
a:210)

しょうがないのでoverrideします

HelloWorldServer.scala

package helloworld

import com.twitter.finagle.http.{Request, Response}
import com.twitter.finatra.http.HttpServer
import com.twitter.finatra.http.filters.{CommonFilters, LoggingMDCFilter, TraceIdMDCFilter}
import com.twitter.finatra.http.routing.HttpRouter

object HelloWorldServerMain extends HelloWorldServer

class HelloWorldServer extends HttpServer {

  /*
   * Since Heroku only supports a single port per service,
   * we disable the Admin HTTP Server
   */
  override val disableAdminHttpServer = true

  override val defaultFinatraHttpPort = ":9000"
  override val defaultHttpPort = 9001

  override def configureHttp(router: HttpRouter) {
    router
      .filter[LoggingMDCFilter[Request, Response]]
      .filter[TraceIdMDCFilter[Request, Response]]
      .filter[CommonFilters]
      .add[HelloWorldController]
  }
}

GET

これで sbt run で起動できるようになったので

"http://localhost:9000/hi?name=World"
Hello World が返って来ます。

2016-06-22_00h15_28.png


post

2016-06-22_00h31_06.png

なんと!case classを定義しただけなのに動作します。
playframeworkだったら Json.reads とか定義しないとダメなのに!



https://github.com/FScoward/handshake-api/tree/0.1

7
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?