Почему аэрозольный баллончик не отвечает на запрос http?

Я пытаюсь установить очень простой HTTP-сервер, используя аэрозольный баллончик. Если я вызываю конечную точку, для которой я установил сопоставление, я получаю тайм-аут (хотя с помощью отладчика я вижу, что субъект получает сообщение).

Мой источник выглядит так:

import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.io.IO
import spray.can.Http
import spray.http.{HttpMethods, HttpRequest, HttpResponse, Uri}

class App extends Actor {

  implicit val system = context.system

  override def receive = {
    case "start" =>
      val listener: ActorRef = system.actorOf(Props[HttpListener])
      IO(Http) ! Http.Bind(listener, interface = "localhost", port = 8080)
  }

}

class HttpListener extends Actor {

  def receive = {
    case _: Http.Connected =>
      sender() ! Http.Register(self)
    case HttpRequest(HttpMethods.GET, Uri.Path("/ping"), _, _, _) =>
      HttpResponse(entity = "PONG")
  }

}

object Main {

  def main(args: Array[String]) {
    val system = ActorSystem("my-actor-system")
    val app: ActorRef = system.actorOf(Props[App], "app")
    app ! "start"
  }

}

проведение run показывает:

> run
[info] Running Main
[INFO] [09/10/2014 21:33:38.839] [my-actor-system-akka.actor.default-dispatcher-3] [akka://my-actor-system/user/IO-HTTP/listener-0] Bound to localhost/127.0.0.1:8080

Следующие HTTP/1.1 500 Internal Server Error появляется, когда я ударил http://localhost:8080/ping:

➜  ~  curl --include http://localhost:8080/ping
HTTP/1.1 500 Internal Server Error
Server: spray-can/1.3.1
Date: Wed, 10 Sep 2014 19:34:08 GMT
Content-Type: text/plain; charset=UTF-8
Connection: close
Content-Length: 111

Ooops! The server was not able to produce a timely response to your request.
Please try again in a short while!

мой build.sbt похоже:

scalaVersion := "2.11.2"

resolvers += "spray repo" at "http://repo.spray.io"

libraryDependencies ++= Seq(
  "io.spray" %% "spray-can" % "1.3.1",
  "io.spray" %% "spray-routing" % "1.3.1",
  "com.typesafe.akka" %% "akka-actor" % "2.3.5"
)

Есть идеи, что я делаю не так?

1 ответ

Решение
case HttpRequest(HttpMethods.GET, Uri.Path("/ping"), _, _, _) =>
  HttpResponse(entity = "PONG")

должно быть

case HttpRequest(HttpMethods.GET, Uri.Path("/ping"), _, _, _) =>
  sender ! HttpResponse(entity = "PONG")

Вы возвращаете HttpResponse вместо отправки сообщения отправителю.

Другие вопросы по тегам