Help us understand the problem. What is going on with this article?

finatra はじめの一歩

More than 3 years have passed since last update.

finatra はじめの一歩

by FScoward
1 / 9

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

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

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


Finatra

http://twitter.github.io/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

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away