4

无法弄清楚这一点,但我的路线得到了以下堆栈跟踪:

[错误] [09/06/2013 17:08:00.019] [example-akka.actor.default-dispatcher-5] [akka://example/user/$a] 处理请求 HttpRequest(GET,/ user/12345abcd?service=YT,List(Host: localhost:8080, Accept: /, User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5),EmptyEntity,HTTP/1.1) java.lang.NullPointerException at spray。 routing.directives.BasicDirectives$$anonfun$mapRequestContext$1$$anonfun$apply$1.apply(BasicDirectives.scala:30) at spray.routing.directives.BasicDirectives$$anonfun$mapRequestContext$1$$anonfun$apply$1.apply(BasicDirectives .scala:30) at spray.routing.directives.ExecutionDirectives$$anonfun$handleExceptions$1$$anonfun$apply$2.apply(ExecutionDirectives.scala:34) at spray.routing.directives.ExecutionDirectives$$anonfun$handleExceptions$1$$ anonfun$apply$2.apply(ExecutionDirectives.scala:32) at spray.routing.HttpServiceBase$class.runSealedRoute$1(HttpService.scala:36) at spray.routing.HttpServiceBase$$anonfun$runRoute$1。applyOrElse(HttpService.scala:46) at akka.actor.ActorCell.receiveMessage(ActorCell.scala:498) at akka.actor.ActorCell.invoke(ActorCell.scala:456) at akka.dispatch.Mailbox.processMailbox(Mailbox.scala :237) at akka.dispatch.Mailbox.run(Mailbox.scala:219) at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java: 260) 在 scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) 在 scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.run(ForkJoinWorkerThread) 的 scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) .java:107)在akka.dispatch.Mailbox.run(Mailbox.scala:219) 在akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237) 调用(ActorCell.scala:456) 在akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher .scala:386) 在 scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) 在 scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) 在 scala.concurrent.forkjoin.ForkJoinPool。 runWorker(ForkJoinPool.java:1979) 在 scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)在akka.dispatch.Mailbox.run(Mailbox.scala:219) 在akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237) 调用(ActorCell.scala:456) 在akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher .scala:386) 在 scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) 在 scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) 在 scala.concurrent.forkjoin.ForkJoinPool。 runWorker(ForkJoinPool.java:1979) 在 scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)386) 在 scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) 在 scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool) 的 scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) .java:1979) 在 scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)386) 在 scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) 在 scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool) 的 scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) .java:1979) 在 scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

我的路线如下所示:

class UserServiceActor extends Actor with UserService {
  def actorRefFactory = context
  def receive = runRoute(userServiceRoute)

}

trait UserService extends HttpService {

  val userServiceRoute = linkRoute

  val linkRoute =
    pathPrefix("user" / Segment) {
      userId =>
        path("link") {
          parameters('service ! "YT") {
            complete {
              "Done"
            }
          }
        }
    }
}

我提出的要求是:

卷曲http://server.com/user/12345abcd/link?service=YT

有什么看起来很明显的问题吗?

4

1 回答 1

6

这可能是一个初始化问题。尝试将路由定义设为 def 或惰性 val。

还有一个 scalac 标志-Xcheckinit,它将添加运行时检查,并提供更好的错误消息以提高性能。

于 2013-09-08T07:55:15.023 回答