2016-02-15 4 views
9
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 zu desginPdfLesen Variablenwert im Spiel WS Antwort Umfang

Sein leer wird so thats gehen async, warum seine nicht den Wert von contentByte hat, kann auch jede andere Art und Weise, so kann ich synchron verwenden oder jede andere Weg, um mein Problem zu lösen.

WSResponse resp = out.get(10000); 

immer versagt

+0

Woher kam contentByte? es ist eine globale Variable? oder es ist im Block der Antwort verfügbar? – Tomer

Antwort

1

Ich habe keine Erfahrung mit Java verspricht, aber auf Grund meiner Erfahrung in der Scala, würde ich habe versucht, so etwas wie dieses:

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 
0

Sie erklären sollten contentByte Variable als final

void makePdfPage(String url, final PdfContentByte contentByte){ 

Zusätzlich sollten Sie einen Wiederherstellungscode für den Fehlerfall hinzufügen