I'm developing a rest api with spray I need to download from my web-client an excel file with a report.
The excel-generator method is ready but spray's "getFromFile(fileFullPath)" is getting "Internal server error"
Any ideas?
Here is my spray code:
(ctx: RequestContext) => {
val actor = actorRefFactory.actorOf(Props(new Actor {
def receive = {
case GetAnualReport(year, generateExcel) =>
val flujoActor = context.actorOf(Props[FlujoActor])
flujoActor ! GetAnualReport(year, generateExcel)
case ReporteResponse(path) =>
println("FILE: "+path)
getFromFile(path)
}
}))
actor ! GetAnualReport(year, true)
}
OUTPUT:
FILE: /tmp/flujocaja-reports-5627299217173924055/reporte-anual.xls
HTTP/1.1 500 Internal Server Error
The main problem with your code is that
getFromFile(path)
doesn't do anything with the request but instead returns a new functionRequestContext => Unit
which is never called. One solution could be to replace that line withgetFromFile(path)(ctx)
.However, there's a better way how to deal asynchronous work before continuing with an inner route: use futures and one of the FutureDirectives. Here's an example roughly adapted to your use case:
That said, I'm not sure why you get
500 Internal Server Error
in your scenario. Is there nothing on the console hinting at what the problem is?