Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading variable value in play WS response scope

void makePdfPage(String url, PdfContentByte contentByte){
    com.itextpdf.text.Font sans = UtilityMethods.getSansSerifFont(14);
    sans.setColor(80,147,225);
    ColumnText ct = new ColumnText(contentByte);
    ct.setSimpleColumn("Hello", 0, 780, 595, 830, 10, Element.ALIGN_CENTER);
    try {
        ct.go();
    } catch (DocumentException e) {
        System.out.println(e);
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



  Promise<WSResponse> out = notification.call(url);
    out.map(resp->{
        Map<String,Object> mapp= Json.fromJson(resp.asJson().get("list"), Map.class);
        PdfService.designPdf(mapp, contentByte);
        return resp;
    });
}

contentByte is going empty to desginPdf

Its going async so thats why its not having the value of contentByte, can any other way so i can synchronously use or any other way to solve my problem.

WSResponse resp = out.get(10000);

getting fails

like image 684
Govind Singh Avatar asked Feb 15 '16 14:02

Govind Singh


1 Answers

I don't have experience with Java promises, but based on my experience in Scala, I would've tried something like this:

Promise<WSResponse> out = notification.call(url);
WSResponse res = out.map(resp->{
  Map<String,Object> mapp= Json.fromJson(resp.asJson().get("list"), Map.class);
  PdfService.designPdf(mapp, contentByte);
  return resp;
});
//Do something with res
like image 140
gooby_j Avatar answered Oct 17 '22 03:10

gooby_j