I tried to seek help on the Spray-ser list but it doesnt get much traffic so I was hoping perhaps someone here could help.
I am trying to create my first simple spray actor that all it does is send back the headers the user sent as JSON.
The project can be found here:
https://bitbucket.org/kraythensoft/ecplatAnd the problematic source file here:
https://bitbucket.org/kraythensoft/ecplat/src/ff09200fa791/src/main/scala/com/kraythensoft/ecplat/Actors.scala?at=masterThe actor is quite simple and pasted below:
class HTTPRoutingActor extends Actor with SprayActorLogging {
val jsonContentType = new ContentType(MediaTypes.`application/json`, Option(HttpCharsets.`UTF-8`))
def receive = {
case HttpRequest(HttpMethods.GET, "/ecplat", headers, _, _) =>
val headerValues = Map[String, String](headers map { h => (h.name, h.value) }: _*)
val hdrJSON = headerValues.toJson.prettyPrint.stripMargin
//val hdrJSON = headers.toJson.prettyPrint.stripMargin
val response = HttpResponse(
entity = HttpBody(jsonContentType, hdrJSON)
)
sender ! response
case _: HttpRequest => sender ! HttpResponse(status = StatusCodes.NotFound, entity = "Unknown resource!")
}
}
I have tried to serialize the map of headers itself as well as loading it into a map[string, string] to no avail. Compiling this code yields:
- gradle clean build run
Starting Ecplat on Akka Microkernel, Exit with CTRL-C.
:clean
:compileJava UP-TO-DATE
:compileScala
..../KraythenSoft/ecplat/src/main/scala/com/kraythensoft/ecplat/Actors.scala:44: value toJson is not a member of scala.collection.immutable.Map[String,String]
val hdrJSON = headerValues.toJson.prettyPrint.stripMargin
^
one error found
:compileScala FAILEDAs you can see there is something wrong with the toJson method even though it should be found on the map it isnt. I have googled this til google bled and to no avail. Any help would be appreciated.
-- Robert