2014-03-27 50 views
0

我正在開發一個帶噴霧的休息API,我需要從我的網絡客戶端下載帶有報告的excel文件。噴發送xls文件到客戶端

Excel的發電機的方法是準備好,但噴霧的「getFromFile(fileFullPath)」越來越「內部服務器錯誤」

任何想法?

這裏是我的噴碼:

(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 
+0

這是一個相當複雜的設置。你這樣建立你的路線的原因是什麼?你有沒有看過關於如何做「每個請求演員」的帖子?例如。在https://skillsmatter.com/skillscasts/4714-scala-does-the-catwalk#video或https://github.com/NET-A-PORTER/spray-actor-per-request – jrudolph

回答

2

與您的代碼的主要問題是,​​不要求做任何事情,而是返回一個新的功能RequestContext => Unit這是從未被稱爲。一種解決方案可能是用getFromFile(path)(ctx)替換該行。

但是,在繼續使用內部路由之前,如何處理異步工作還有更好的方法:使用期貨和FutureDirectives之一。以下是大致適合您的使用情況的一個例子:

onSuccess((flujoActor ? GetAnualReport(year, generateExcel)).mapTo[ReporteResponse]) { response => 
    getFromResource(response.path) 
} 

這麼說,我不知道爲什麼你在你的情況下獲得500 Internal Server Error。控制檯上沒有提示問題是什麼?

相關問題