2014-03-27 3 views
0

스프레이로 나머지 API를 개발하고 있습니다. 웹 클라이언트에서 보고서를 다운로드해야합니다.스프레이가 클라이언트에게 xls 파일을 보내십시오.

엑셀 발전기 방법은 준비가되어 있지만, 스프레이의 "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) 
} 

출력 :

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

코드의 주된 문제는 getFromFile(path)는 요청에 아무것도하지 않는다는 것입니다 대신 새로운 기능을 반환 RequestContext => Unit 결코 부르지 않는다. 한 가지 해결책은 해당 라인을 getFromFile(path)(ctx)으로 대체하는 것입니다.

그러나 내적 경로를 계속하기 전에 비동기 작업을 처리하는 방법이 더 좋습니다 : 선물 사용과 FutureDirectives 중 하나. 여기에 거의 사용 사례에 적용하는 예이다 : 당신이 당신의 시나리오에서 500 Internal Server Error을받을 이유를 말했다

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

, 나는 확실하지 않다. 콘솔에 문제가 무엇인지 암시하는 내용이 있습니까?

관련 문제