Reputation: 15490
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
Upvotes: 9
Views: 438
Reputation: 1745
You should declare contentByte variable as final
void makePdfPage(String url, final PdfContentByte contentByte){
Additionally you should add a recover code for fail case
map(...)
.recover(new Function<Throwable,JsonNode>() {
public JsonNode apply(Throwable ex) {
if(Logger.isErrorEnabled()){
Logger.error("retrieving api info",ex);
}
return null; //TODO
}
});
Upvotes: 0
Reputation: 51
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
Upvotes: 1