I'm trying to my first Spray + Akka project work.
Although this looks like straight forward, I still get a type error with the unmarshaller (which I don't need, I'm returning a String because I'll produce nothing but XML in the end.
package com.example.actors
import akka.actor.{Props, ActorContext, Actor}
import akka.util.Timeout
import spray.http.CacheDirectives.`max-age`
import spray.http.HttpHeaders.`Cache-Control`
import spray.routing._
import spray.http._
import MediaTypes._
import scala.concurrent.duration._
class SprayActor extends Actor with DefaultService {
def actorRefFactory = context
def receive = runRoute(defaultRoute)
}
trait DefaultService extends HttpService {
def actorRefFactory: ActorContext
lazy val feedActor = actorRefFactory.system.actorOf(Props[MainFeedActor])
import akka.pattern.ask
implicit val timeout = Timeout(5 seconds) // needed for `?` below
val defaultRoute = path("rss") {
get {
respondWithMediaType(`text/xml`) {
respondWithHeaders(`Cache-Control`(`max-age`(0))) {
complete {
(feedActor ? "rss").mapTo[String]
}
}
}
}
}
}
class MainFeedActor extends Actor {
val log = Logging(context.system, this)
override def receive: Receive = {
case "rss" => "<xml>test</xml>"
}
Here is the compiler error:
[error] src/main/scala/com/example/actors/SprayActor.scala:31: type mismatch;
[error] found : scala.concurrent.Future[String]
[error] required: spray.httpx.marshalling.ToResponseMarshallable
[error] (feedActor ? "rss").mapTo[String]
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed