UnfilteredはServletコンテナ上だけでなく、Netty上で動作させることもできます。Netty上でUnfilteredを動作させる場合、build.sbtに以下の依存関係を追加します。
libraryDependencies ++= Seq( "net.databinder" %% "unfiltered-netty" % "0.5.3", "net.databinder" %% "unfiltered-netty-server" % "0.5.3" )
プランはunfiltered.netty.cycle.Planを継承して作成します。
package jp.sf.amateras.scala.unfiltered import unfiltered.request._ import unfiltered.response._ import unfiltered.netty._ object NettyPlan extends cycle.Plan with cycle.ThreadPool with ServerErrorResponse { def intent = { case _ => ResponseString("Hello Netty!") } }
作成したプランを使用して unfiltered.netty.Httpを実行する起動用クラスを作成します。
package jp.sf.amateras.scala.unfiltered object NettyServer { def main(args: Array[String]) { unfiltered.netty.Http(8080).plan(NettyPlan).run() } }
「sbt run」でNettyServerクラスを実行し、Webブラウザでhttp://localhost:8080/にアクセスすると「Hello Netty!」と表示されるはずです。